#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<strstrea.h>
struct kbcqbank
{
int qno;
char quest[60];
char opt01[30];
char opt02[30];
char opt03[30];
int key;
} kbq;
int main()
{
clrscr();
char fname[20], kline[150];
char qresp[1]="N", mesg[]="This is a test", ch;
kbcqbank p1[3];
int ctr, kcap, qctr, quizr, qpoints, qscore, handle;
char *errorcodes;
ifstream rfptr;
ofstream wfptr;
cout<<"Enter the question bank file name firstname.lastname ? ";
cin>>fname;
cout<<"Filename you want to read is "<<fname<<endl;
getch();
kcap=4;
handle=open("a.txt");
rfptr.open(fname);
cout<<handle<<mesg;
getch();
if(!rfptr)
{
cout<<"Error opening the file "<<fname;
getch();
errorcodes=strerror(errno);
cout << strerror(errno);
cout << errorcodes<<endl;
wfptr.open(fname);
for(ctr=1;ctr<=kcap;ctr++)
{
cout<<"\n\nQuestion details "<<endl;
cout<<"Enter Qno "<<endl;
cin>>p1[ctr].qno;
cout<<endl<<"Enter Question:"<<endl;
cin>>p1[ctr].quest;
cout<<"Option 01: "<<endl;
cin>>p1[ctr].opt01;
cout<<"Option 02: "<<endl;
cin>>p1[ctr].opt02;
cout<<"Option 03: "<<endl;
cin>>p1[ctr].opt03;
cout<<"Key: "<<endl;
cin>>p1[ctr].key;
printf("Qno %d Question %s Opt01 %s Opt02 %s Opt03 %s Key %d",p1[ctr].qno,p1[ctr].quest,p1[ctr].opt01,p1[ctr].opt02,p1[ctr].opt03,p1[ctr].key);
getch();
wfptr<<p1[ctr].qno<<p1[ctr].quest<<p1[ctr].opt01<<p1[ctr].opt02<<p1[ctr].opt03<<p1[ctr].key<<endl;
}
wfptr.close();
getch();
}
else
{
rfptr.open(fname);
printf("File Status ");
errorcodes=strerror(errno);
cout << strerror(errno)<<" ->";
cout << errorcodes<<endl;
cout<<"File found, Now showing records"<<strerror(errno);
getch();
for(ctr=1;!rfptr.eof();ctr++)
{
printf("Question # %d ",ctr);
rfptr>>kline;
cout<<kline;
};
cout<<"Close\n";
getch();
rfptr.close();
}
clrscr();
printf("Do you wish to start the Quiz (Y/N) ? ");
cin>>qresp;
if(qresp=="Y"|| qresp=="y")
{
printf("Loading questions...\n");
printf("Start Quiz...\n");
getch();
rfptr.open(fname);
rfptr.close();
qpoints=0;
for(ctr=1;ctr<qctr && (qresp=="Y"|| qresp=="y"); ctr++)
{
clrscr();
printf("\nQuestion # %d",p1[ctr].qno);
printf("\nQuestion -> %s",p1[ctr].quest);
printf("\mOption 02 -> %s",p1[ctr].opt01);
printf("\nOption 03 -> %s",p1[ctr].opt02);
printf("\nOption 03 -> %s",p1[ctr].opt03);
printf("\nEnter the correct option 1, 2 or 3 ");
cin>>quizr;
if(quizr==p1[ctr].key)
{
qpoints=(10*qpoints)+(ctr*1000);
printf("\n\nCorrect !!! Your score is %d ",qpoints);
printf("\n\n\nDo wish to continue quiz (Y/N) ? ");
cin>>qresp;
}
quizr=0;
}
printf("\n\n\nYour final score is %d ", qpoints);
}
getch();
return 0;
}