Professional Documents
Culture Documents
Multiple Choice Quiz Program Using C++ File Handling
Multiple Choice Quiz Program Using C++ File Handling
INTRODUCTION TO C++
INTRODUCTION TO PROJECT
SOURCE CODE
FUTURE VALIDATIONS
OUTPUT
INTRODUCTION TO C++
C++ is a programming Language Developed by Bjarne Stroustrup. It was
originally named as C with classes, was renamed as C++ in 1983.It is regarded
as an intermediate-level language, as it comprises both high-level and low-
level language features. Its application domains include systems software,
application software, device drivers, embedded software, high performance
server and client applications, and entertainment software such as video games.
C++ continues to be used and is one of the preferred programming languages to
develop professional applications.
• C++ is portable.
As one of the most frequently used languages in the world and as an open
language, C++ has a wide range of compilers that run on many different
platforms that support it. Code that exclusively uses C++'s standard library will
run on many platforms with few to no changes.
INTRODUCTION TO PROJECT
Quiz game is a very popular General Knowledge Game. Quiz game increases
the knowledge of the player. It is used to check the knowledge within us.
The provided source code is a simple Quiz game programmed in C++ language.
This program is based on the exploitation of the ordered arrangement of
question number, question, options and the answer in a file. In this program
several question are provided to the player. The players are provided with 4
options in it. Player is all need to choose the suitable option from the 4 option
available in the screen. The player needs to type either A, B, C, or D according to
the suitable answer provided in it.
The player will score the points with each correct answer provided marks will be
deducted for wrong answer. This program displays questions in a random order
from the question bank. The highlight of this program is that question bank can
be updated (users can add questions to the question bank).
SYSTEM REQUIREMENTS
}
}
}
void contest::func(int p,int array[])
{ ifstream in,fin;
in.open("ques.txt");
fin.open("ques.txt");
char A,answer;
int i=0,j=1,r=0,sh;
while(!fin.eof())
{
i++;
if(i%5==1)
in>>sh;
{if(sh==array[p])
{
{
do
{
fin.getline(s,100);r++;} while(r<(sh-1)*5+2);
cout<<endl<<s<<endl;
{
if(j%5==3)
{
fin.get(A);
lb:
cout<<"\nans: ";
gets(ans);
i=-1;
j=-1;
answer=tolower(ans[0]);
if(answer<'a'||answer>'d')
{cout<<"wrong choice";
goto lb; }
else
if(answer==A)
{
x=x+5;
cout<<"your answer is correct\n";
}
else
{
if(x>0)
x=x-2.5;
cout<<"wrong answer\n";
cout<<"the correct answer is "<<A<<endl;
}
cout<<"press any key to continue";
getch();
clrscr();
cout<<endl<<endl;
return;
}
j++;
}
}
}
}
if(i%5==1)sh++;
}
in.close();
}
void contest::rndm(int p[])
{randomize();
//shuffle p
for (int i=12; i>0; --i)
{
//get swap index
int j=random(i);
//swap p[i] with p[j]
int temp = p[i];
p[i] = p[j];
p[j] = temp;
}
int ar[10];
//copy first n elements from p to arr
for ( i=0; i<10; ++i)
ar[i] = p[i];
}
void contest::questions()
{ofstream file;
file.open("ques.txt");
file<<"1\n When computer was first invented?\n";
file<<" a.1820 \t b.1823\n";
file<<" c.1834 \t d.1922\n";
file<<'a'<<"\n";
file<<"2\n Which day is celebrated as 'World Computer Literacy day'?\n";
file<<" a.October 6 \t b.December 2\n";
file<<" c.October 4 \t d.May 15\n";
file<<'b'<<"\n";
file<<"3\n Who is known as human computer of India?\n";
file<<" a. Sundar Pichai \t b.Sathya Nathella\n";
file<<" c. Shakunthala Devi\t c.Derek o brein\n";
file<<'c'<<"\n";
file<<"4\n 'Do no evil' is the tag line of\n";
file<<" a. Adobe \t b. Microsoft\n";
file<<" c. Linux \t d. Google\n";
file<<'d'<<"\n";
file<<"5\n Extension of PDF\n";
file<<" a. Portable Document Format \t b. Personal Document Format\n";
file<<" c. Portable Digital format \t d. Presentation Document Format\n";
file<<'a'<<"\n";
file<<"6\n Which company invented floppy disk?\n";
file<<" a. Microsoft \t b. Apple\n";
file<<" c. Intel \t d.IBM\n";
file<<'a'<<endl;
file<<"7\n IC chips are usually made of\n";
file<<" a. Lead \t b. Silicon\n";
file<<" c. Chromium \t d. Gold\n";
file<<'b'<<endl;
file<<"8\n Technology no longer protected by copyrights and available to all is
\n";
file<<" a. Proprietary \t b. Open\n";
file<<" c. Experimental \t d. Free\n";
file<<'a'<<endl;
file<<"9\n In binary language each alphabet is made up of unique combination
of \n";
file<<" a. 8 bytes \t b.8 kbytes\n";
file<<" c. 8 character \t d. 8 bits\n";
file<<'d'<<endl;
file<<"10\n The term bit is short for\n";
file<<" a. Byte \t b. Binary language\n";
file<<" c. Binary digit \t d.Binary number\n";
file<<'c'<<endl;
file<<"11\n Who invented graphical use interface(GUI)?\n";
file<<" a.Microsoft \t b.Apple\n";
file<<" c.Xerox \t d. IBM\n";
file<<'c'<<endl ;
file<<"12\n What is the transfer rate of a satandard USB2.0?\n";
file<<" a.100Mbit/s \t b.480 Mbit/s\n";
file<<" c.1 Gbit/s \t c. 250 Mbit/c\n";
file<<'b'<<endl;
file<<"13\n Who invented USB?\n";
file<<" a. HP \t b.Samsung\n";
file<<" c. Intel \t d. AMD\n";
file<<'c'<<endl;
file.close();
}
void contest::edit()
{ char password[25],q[100],a[100],b[100],c[100],d[100],answer;
int no;
cout<<"enter password \t";
gets(password);
if(strcmp(password,"admin")==0)
{
ofstream out;
out.open("ques.txt",ios::app);
cout<<"Enter question no\n";
cin>>no;
out<<no+13<<endl;
cout<<"Enter question name\n";
gets(q);
out<<q<<"\n";
cout<<"enter options\n";
cout<<"Enter option a\n";
gets(a);
out<<"a. "<<a<<"\t";
cout<<"Enter option b\n";
gets(b);
out<<"b. "<<b<<"\n";
cout<<"Enter option c\n";
gets(c);
out<<"c. "<<c<<"\t";
cout<<"Enter option d\n";
gets(d);
out<<"d. "<<d<<"\n";
cout<<"enter correct option\n";
cin>>answer;
out<<answer<<"\n";
out.close();
}
}
void contest::init()
{
cout<<"contestant name - ";
gets(name);
cout<<"contestant roll no - ";
cin>>roll;
}
void contest::display()
{
cout<<"\nresult:: \n"<<name<<" got total "<<x<<" marks \n";
}
void main()
{
clrscr();
contest r;
cout<<" \n\n\n\t\t\t Quiz Contest\n";
cout<<"GENERAL INSTRUCTIONS\n";
cout<<"This is a multiple choice quiz contest.\n";
cout<<"5 points will be awarded for each correct answer and\n";
cout<<"\t2.5 marks will be DEDUCTED for each wrong answer.\n";
cout<<"If more than one options are entered,";
cout<<"\n\t FIRST OPTION to be entered will be considered\n";
cout<<"Press any key to continue";
getch();
clrscr();
cout<<endl<<endl;
r.init();
L:
cout<<"\nSelect your choice \n\t1 start\n\t2 display\n\t3 add
questions\n";
cout<<"\t0 quit\n";
int c;
cin>>c;
char reply;
clrscr();
switch(c)
{case 1: r.define();
break;
case 2: r.display();
break;
case 3: r.edit();
break;
case 0: goto Last;
default: cout<<"wrong choice \n";
}
cout<<"\nenter your reply : Press y for continuing \t";
cin>>reply;
if(reply=='y'||reply=='Y')
goto L;
else
Last:
cout<<"\n\n\nTHANKS FOR SPENDING YOUR VALUABLE TIME";
cout<<"\nDone by Pugazhendhi and Shivakumar";
getch();
}
FUTURE VALIDATIONS
1) Inclusion of timer
2) Inclusion of graphics
3) Producing sound