You are on page 1of 19

#include<iostream>

#include<fstream>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<stdio_ext.h>
using namespace std;
char x;
class mem
{
//
char name[20];
public:
virtual int authend(int)=0;
};
class teacher:public mem
{
protected:
char name[20];
char pass[20];
public:
int add_ques();
int remove_ques();
int publish_result();
int authend(int);
int database();
}t;
class student:public mem
{
public:
char name[20];
int reg_no;
int marks;
public:
int get_details();
int mark_assign(int);
//int markmin();
int write_exam();
void view_result();
int authend(int);
}st[10],s1,s2;
class quest
{
public:

char ques[100];
char opt1[20];
char opt2[20];
char opt3[20];
char opt4[20];
char key[20];
public:
int add_qns();
int details();
int ask(int);
int write();
}q[20],ques;

class auth
{
public:
int login(int);
int signup();
}a1,a2;
class menu
{
public:
int online();
};
class file
{
public:
void write_details(char *,char *,int);
int write_details(int);
int read_details(int);
int read_details();
int read_details(char *);
int read_details(char *,char *);
}file1,file2;
int teacher::authend(int l)
{
if(l==0)
{
int c2=a1.login(1);
return c2;
}
else
exit(0);
}
int teacher::add_ques()
{
int c4=file2.read_details(4);
return c4;
}
int teacher::remove_ques()
{
file file2;
int c4=file2.write_details(1);
return c4;
}
int teacher::publish_result()
{
file file2;
int c4=file2.read_details(2);
return c4;
}
int teacher::database()
{
file file2;
int c4=file2.read_details(1);
return c4;
}
int student::authend(int k)

if(k==0)
{
int c2=a1.signup();
return c2;
}
else if(k==1)
{
int c2=a1.login(0);
return c2;
}
else
exit(0);

}
int student::write_exam()
{
file file3;
int cnt=file3.write_details(2);
if(cnt)
return 1;
else
return 0;
}
int student::get_details()
{
file f;
int m=f.read_details();
return m;
}
void student::view_result()
{
file file4;
file4.read_details(3);
}
int file::read_details()
{
int i,reg;student s;char name[20];
system("clear");
cout<<"\t\t\t****************************************************************
*"<<endl;
cout<<"\n\t\t\t\t\t
ONLINE EXAMINATION PORTAL\n\n";
cout<<"\t\t\t****************************************************************
*"<<endl;
cout<<"\t\t\t\t\t
CANDIDATE REGISTRATION\n\n";
cout<<"\t\t\tENTER CANDIDATE'S NAME\t\t:";
cin>>name;
cout<<"\t\t\tENTER THE REGISTRTION NUMBER\t:";
cin>>reg;
fstream file;

file.open("result.dat",ios::in);
while(file.read((char*) &s1,sizeof(s)))
{
if(s1.reg_no==reg)
{
cout<<"\t\t\tCandidate with this reg.no is already
registered...please check...!!!";
x=getchar();
x=getchar();
return 0;
}
}
file.close();
strcpy(s1.name,name);
s1.reg_no=reg;
system("clear");
cout<<"\t\t\t****************************************************************
*"<<endl;
cout<<"\n\t\t\t\t\t
ONLINE EXAMINATION PORTAL\n\n";
cout<<"\t\t\t****************************************************************
*"<<endl;
cout<<"\t\t\t\t\tCANDIDATE REGISTRATION\n\n";
cout<<"\t\t\tDear "<<name<<", You are successfully
registered....!!!\n\t\t\tPRESS ANY KEY...!!! ";
x=getchar();
x=getchar();
return 1;
}
int quest::add_qns()
{
cout<<"\t\t*****************************************************************"
<<endl;
cout<<"\n\t\tENTER THE QUESTION: ";
__fpurge(stdin);
//char q[100],op1[20],op2[20],op3[20],op4[20],ke[20];char ans[20];
fgets(ques,100,stdin);
loop:
cout<<"\n\t\t\tENTER THE OPTION 1: ";
fgets(opt1,20,stdin);
//strcpy(opt1,op1);
cout<<"\n\t\t\tENTER THE OPTION 2: ";
fgets(opt2,20,stdin);
//strcpy(opt2,op2);
cout<<"\n\t\t\tENTER THE OPTION 3: ";
fgets(opt3,20,stdin);
//strcpy(opt3,op3);
cout<<"\n\t\t\tENTER THE OPTION 4: ";
fgets(opt4,20,stdin);
//strcpy(opt4,op4);
cout<<"\n\t\t\tENTER THE ANSWER : ";
fgets(key,20,stdin);
//strcpy(key,ke);

int d=(!
((strcmp(opt1,key))&&(strcmp(opt2,key))&&(strcmp(opt3,key))&&(strcmp(opt4,key
))));
if(d==1)
{
return 1;
}
else
{
cout<<"\t\t\tANSWER IS NOT MATCHING WITH THE OPTIONS..CHECK
OPTIONS AGAIN...!!";
x=getchar();
goto loop;
}
}
/*int quest::details()
{
//cout<<":"<<ques<<endl;
cout<<"1: "<<opt1<<"\t2: "<<opt2<<"\n3: "<<opt3<<"\t4:
"<<opt4<<"\nanswer: "<<key<<endl;
}*/
int quest::ask(int a)
{
int k;
cout<<"\t\t\t";
cout<<a;
cout<<":"<<ques<<endl;
cout<<"\n\t\t\t 1:"<<opt1<<"\n\t\t\t 2:"<<opt2<<"\n\t\t\t
3:"<<opt3<<"\n\t\t\t 4:"<<opt4<<endl;
cout<<"\t\t\t";
cin>>k;
if(k==1)
{
if(strcmp(key,opt1)==0)
return 1;
else
return 0;
}
else if(k==2)
{
if(strcmp(key,opt2)==0)
return 1;
else
return 0;
}
else if(k==3)
{
if(strcmp(key,opt3)==0)
return 1;
else

return 0;
}
else if(k==4)
{
if(strcmp(key,opt4)==0)
return 1;
else
return 0;
}
else
{
cout<<"\n\t\t\tWRONG CHOICE...!!! PRESS ANY KEY";
x=getchar();
x=getchar();
return 0;
}
}
/*int file::read_details(char *m)
{
int i;
fstream fobj1;
char *s_name;
fobj1.open("student.dat",ios::in);
char string[20];
s_name=new char[strlen(m)+1];
strcpy(s_name,m);
for(;;)
{
if(fobj1.getline(string,20)!=NULL)
{
for(i=0;i<strlen(string);i++)
{
if(string[i]=='\n')
string[i]='\0';
}
int s=strcmp(s_name,string);
if(s==0)
return 0;
else
{
continue;
}
}
else
}

return 1;

}*/
int file::read_details(int i)
{
int count=0;
if(i==0)
{

fstream fobj1;
fobj1.open("ques_data.dat",ios::in);
quest q1;
while((fobj1.read((char*)&q1,sizeof(q1))))
{
count++;
}
fobj1.close();
return count;

else if(i==1)
{
//system("clear");
cout<<"\t\t\t****************************************************************
*"<<endl;
cout<<"\n\t\t\t\t\t
ONLINE EXAMINATION PORTAL\n\t\t\t\t\t
QUESTION
DATABASE 2011\n";
cout<<"\t\t\t****************************************************************
*"<<endl;
int count=0;
fstream file6;
file6.open("ques_data.dat",ios::in);
file6.seekg(0,ios::beg);
while(file6.read((char*) &q[count],sizeof(ques)))
{
cout<<"\t\t\tQN NO."<<count+1<<endl;
cout<<" "<<q[count].ques<<endl;
cout<<"\t1: "<<q[count].opt1<<"\t2: "<<q[count].opt2<<"\n\t3:
"<<q[count].opt3<<"\t4: "<<q[count].opt4<<"\n\tanswer:
"<<q[count].key<<endl<<endl;
count++;
}
file6.close();
}

return 1;

else if(i==2)
{
system("clear");

cout<<"\t\t\t****************************************************************
*"<<endl;
cout<<"\n\t\t\t\t\t
ONLINE EXAMINATION PORTAL\n\t\t\t\t\t\t
RESULTS\n";
cout<<"\t\t\t****************************************************************
*"<<endl;

cout<<"------------------------------------------------------------------"<<e
ndl;
cout<<"REG.NO\tNAME\t\t\tMARK\tPERCENTAGE\t\tSTATUS\n";
cout<<"------------------------------------------------------------------"<<e
ndl;
int count=0;
float percent;
//cout<<"results"<<endl;
fstream file;
file.open("result.dat",ios::in);
while(file.read((char*)&(st[count]),sizeof(s1)))
{
percent=st[count].marks*5;
cout<<st[count].reg_no<<"\t"<<st[count].name<<"\t\t\t"<<st[count].marks<<"\t";
if(st[count].marks>=6)
{
cout<<percent<<"%
\t\tPASSED\n";
}
else
{
cout<<percent<<"%
\t\tFAILED\n";
}
count++;
}
cout<<"\t\t\t";
if(count==0)
{
cout<<"\t\tNo one completed the test...!!!";
}
file.clear();
file.close();
x=getchar();
x=getchar();
}
else if(i==3)
{
int j,count=0;
student s[20];

fstream fobj7;
int r;
cout<<"\t\tREGISTER NUMBER:";
cin>>r;
fobj7.open("result.dat",ios::in);
while(fobj7.read((char *)(&s[count]),sizeof(s1)))
count++;
fobj7.close();
//fobj7.open("result.dat",ios::in);
//fobj7.read((char *)(&s[count]),sizeof(s1));
for(j=0;j<count;j++)
{
if((r==s[j].reg_no))
{

}
else

cout<<"NAME:";
cout<<s[j].name<<endl;
cout<<"SCORE:";
cout<<s[j].marks<<endl;
if(s[j].marks>=9)
cout<<"YOU ARE QUALIFIED";
else
cout<<"YOU ARE NOT QUALIFIED";

continue;
}
fobj7.close();
}
else if(i==4)
{
int count=0;
int s1;
fstream fobj2;
quest q1;
file file5;
fobj2.open("ques_data.dat",ios::in|ios::app);
while(fobj2.read((char*) (&q1),sizeof(q1)))
count++;
fobj2.close();
for(int k=0;k<15;k++)
{
int c5=file5.write_details(0);
cout<<"QUESTION SUCCESSFULLY ADDED"<<endl;
cout<<"Do you want to add another question press 1:if
yes\n2:no"<<endl;
cin>>s1;
if(s1==1)
continue;
else
return 0;
}
return 1;
}
else
exit(0);
}

int file::read_details(char *m,char *p)


{
int i;
fstream fobj1;
char *s_name,*s_pas;
fobj1.open("student.dat",ios::in);
char string[20];
s_name=new char[strlen(m)+1];
s_pas=new char[strlen(p)+1];
strcpy(s_name,m);
strcpy(s_pas,p);
for(;;)
{
if(fobj1.getline(string,20)!=NULL)
{
for(i=0;i<strlen(string);i++)
{
if(string[i]=='\n')
string[i]='\0';
}
int s=strcmp(s_name,string);
if(s==0)
{
if(fobj1.getline(string,20)!=NULL)
{
for(int i=0;i<strlen(string);i++)
{
if(string[i]=='\n')
string[i]='\0';
}
int s3=strcmp(s_pas,string);
if(s3==0)
return 1;
//return 0;
else
{
return 0;
}

else
{
continue;
}}
}}
fobj1.close();

}
void file::write_details(char *m,char *p,int n)
{
if(n==0)
{
char *s1_name;char *s1_pass;
fstream fobj2;
fobj2.open("student.dat",ios::out|ios::app);
s1_name=new char[strlen(m)+1];
s1_pass=new char[strlen(p)+1];
strcpy(s1_name,m);
strcpy(s1_pass,p);
fobj2<<s1_name<<endl;
fobj2<<s1_pass<<endl;
fobj2.close();
}
}
int file::write_details(int m)
{
if(m==0)
{
fstream fobj2;
fobj2.open("ques_data.dat",ios::app | ios::out);
quest q2;
int d=q2.add_qns();
if(d==1)
{
fobj2.write((char*) &(q2),sizeof(q2));
return 1;
}
}
else if(m==1)
{
fstream fobj2,file;int j;
int count=0,q_num;
quest q2;
fobj2.open("ques_data.dat",ios::in);
while(fobj2.read((char*)(&q[count]),sizeof(q2)))
{
count++;
}
fobj2.close();
fobj2.open("temp.dat",ios::out);
cout<<"\t\tENTER THE QUESTION NUMBER TO DELETE :";
cin>>q_num;
fobj2.seekg(0,ios::beg);
for(int i=0;i<count;i++)
{
if((i+1)!=q_num)
{
fobj2.write((char*) &q[i],sizeof(q2));

}
else
continue;
}
fobj2.close();
rename("temp.dat","ques_data.dat");
//return 1;
t.database();

}
else if(m==2)
{
int j,n,i=0,count=0,res,mark=0,l=0;char qn_num[10];
student std2;
fstream fobj3;

cout<<"\t\t Objective type questions...\n\t\tEach questions


carries 4 marks\n\t\tEach wrong answer carries a negative mark of 1"<<endl;
quest q3,q[20];
fobj3.open("ques_data.dat",ios::in);
//cout<<"hai"<<endl;
while(fobj3.read((char*) &q[count],sizeof(q3)))
{
count++;
}
cout<<"count"<<count<<endl;
fobj3.close();int k;
while(i<5)
{
j=rand()%(count);
//cout<<j<<endl;
for(k=0;k<l;k++)
{
//cout<<"test "<<endl;
//cout<<qn_num[k]<<endl<<j<<endl;
if(qn_num[k]==j)
{
j=rand()%(count);
k=0;
continue;
}
}
//cout<<"j="<<j<<endl;
qn_num[l++]=j;
res=q[j].ask(i+1);
if(res==1)
{
mark+=4;
}
else
{
mark-=1;
}

i++;
system("clear");
}
s1.marks=mark;
//cout<<s1.marks;
fobj3.open("result.dat",ios::out|ios::app);
fobj3.write((char*)&(s1),sizeof(s1));
fobj3.close();
return 1;

//}//}

}}
int auth::signup()
{
char nam[20],pas1[20],pas2[20];
label:
cout<<"\t\tNAME
:";
cin>>nam;
label1:
cout<<"\t\tPASSWORD
:";
cin>>pas1;
cout<<"\t\tCONFIRM PASSWORD:";
cin>>pas2;
//pas1=getpass("\t\tPASSWORD:")<<endl;
//pas2=getpass("\t\tCONFIRM PASSWORD:")<<endl;
//file file2;
int s1=file2.read_details(nam);
if(s1==0)
{
cout<<"\t\tUsername not available.............\n\t\tplease select
another one"<<endl;
goto label;
}
else
{
int s2=strcmp(pas1,pas2);
if(s2==0)
{
file2.write_details(nam,pas1,0);
return 1;
}
else
{
cout<<"\t\tPassword is not matching......\n\t\ttry
again........"<<endl;
goto label1;
}
}
}
int auth::login(int l)
{
if(l==0)
{
char nam1[20],pas[20];
int c1,count1=0;
cout<<"\t\tUSER NAME:";
cin>>nam1;

//pas=getpass("\t\t password:")<<endl;
cout<<"\t\tPASSWORD :";
//pas=getpass("\t\t password:")<<endl;
cin>>pas;
//file file2;
int s2=file2.read_details(nam1,pas);
if(s2==1)
{
return 1;
}
else

return 0;

}
else if(l==1)
{
char nam1[20],pas[20],name2[]="sudharsan",pass1[]="rtos338";
cout<<"\t\tUSER NAME:";
cin>>nam1;
cout<<"\t\tPASSWORD :";
cin>>pas;
// pas=getpass("\t\t password:")<<endl;
if(((strcmp(nam1,name2)==0)&&(strcmp(pas,pass1)==0)))
return 0;
else
}
else
exit(0);

return 1;

}
int menu::online()
{
int count1=0,count2=0,ch,c,y;student s,std1;teacher tchr;fstream file;
//file file1;
file.open("result.dat",ios::out|ios::app|ios::in);
int c1,c2,cnt1,count=0,cnt2,c4,c5,c6;
count1=file1.read_details(0);
cout<<count1<<endl;
while(1)
{
if(count1>=5)
{
cout<<"\t\t******************************************************************
**"<<endl;
cout<<"\t\t\t\tWELCOME TO ONLINE EXAMINATION"<<endl;
loop3:cout<<"\t\t\t1:START EXAMINATION\t 2:TEACHER\n \t\t
3:VIEW RESULT\t 4:EXIT "<<endl;

cout<<"\t\t******************************************************************
**"<<endl;
cin>>ch;
switch(ch)
{
case 1: for(;;)
{
cout<<"\t\t 1.sign up\t\t\t 2.login"<<endl;
cin>>c;
if(c==1)
{
mem *mptr;
mptr=&std1;
label1:c1=mptr->authend(0);
if(c1==1)
{
cout<<"\t\tyou are successfully

registerd"<<endl;

}
else
{

continue;

count++;
while(count<3)
goto label1;
cout<<"sorry....\nyou can't
able to write the exam\n"<<endl;

exit(0);
}

else if(c==2)
{
mem *mptr;
//student std1;
mptr=&std1;
label2:c2=mptr->authend(1);
if(c2==1)
{
cout<<"YOU ARE SUCCESSFULLY LOGGED
IN"<<endl;

successfully\n\t\tpress any key"<<endl;

y=s1.get_details();
if(y==0)
{
goto loop3;
}
cnt2=s1.write_exam();
if(cnt2)
{
cout<<"\t\tExam completed
x=getchar();
goto loop3;
}

//cout<<"hai";
goto loop3;
}
else
{

count2++;
if(count2<3)
{
cout<<"\t\tusername or
password is incorrect..\n\t\ttry again...."<<endl;
goto label2;
}
else
{
cout<<"\t\tsorry....your
account is blocked\n\t\tyou want to create an account\n"<<endl;
continue;
}
}
}

else
exit(0);

}
break;

case 2: count1=0,c4,c5;
mem *mptr;
mptr=&tchr;
label:c1=mptr->authend(0);
if(c1==0)
{
loop:cout<<"\t\t*********************************************"<<endl;
cout<<"\t\t1:ADD QUESTIONS \t2:REMOVE
QUESTIONS\n\t\t3:DATABASE\t4:PUBLISH RESULT\n\t\t5:LOGOUT "<<endl;
cout<<"\t\t*********************************************"<<endl;
cin>>c2;
if(c2==1)
{
c4=tchr.add_ques();
if(c4==0)
{
//cout<<"\t\tquestion
succesfully added"<<endl;
goto loop;
}
else
goto loop;
}
else if(c2==2)
{
if(c4=tchr.remove_ques())
goto loop;

else

exit(0);
}
else if(c2==3)
{
if(c5=tchr.database())
goto loop;
}
else if(c2==4)
{
c6=tchr.publish_result();
goto loop;
}
else if(c2==5)
{
goto loop3;
}
else
exit(0);
}
else
{

count1++;
while(count1<3)
{
cout<<"\t\tusername or password is
incorrect..\n\t\ttry again...."<<endl;
goto label;
}
exit(0);
}
break;
case 3:
s1.view_result();
goto loop3;
break;
case 4:exit(0);
}
}
else
{
cout<<"\t\t******************************************************"<<endl;
cout<<"\t\tNOTE:"<<endl;
cout<<"\t\tThere is no enough questions on the
database"<<endl;
cout<<"\t\tPress any key............"<<endl;
x=getchar();
//system ("clear");
cout<<"\t\t******************************************************"<<endl;

cout<<"\t\twelcome to online examination"<<endl;


cout<<"\t\t1:TEACHER\t\t2:EXIT "<<endl;
cout<<"\t\t*******************************************************"<<endl;
int ch;
cin>>ch;
switch(ch)
{
case 1:int count1=0,c4,c5;
teacher tchr;
mem *mptr;
mptr=&tchr;
label3:c1=mptr->authend(0);
if(c1==0)
{
for(;;)
{
int c2;
system("clear");
cout<<"\t\t*********************************************"<<endl;
cout<<"\t\t1:ADD QUESTIONS
\t2:REMOVE QUESTIONS\n\t\t3:DATABASE\t\t4:LOGOUT "<<endl;
cout<<"\t\t*********************************************"<<endl;
//system("clear");
cin>>c2;
if(c2==1)
{
c4=tchr.add_ques();
if(c4)
{
cout<<"\t\tquestion
succesfully added"<<endl;
continue;
}
}
else if(c2==2)
{
if(c4=tchr.remove_ques())
continue;
else
exit(0);
}
else if(c2==3)
{
if(c5=tchr.database())
continue;
}
else if(c2==4)
{
goto loop3;
}
else
exit(0);
}

}
else
{

count1++;
if(count1<3)
{
cout<<"\t\tusername or password is
incorrect..\n\t\ttry again...."<<endl;
goto label3;
}
else
{
return 0;
}

}
}

}}
int main()
{
menu obj;
obj.online();
}

}
break;