Você está na página 1de 16

CERTIFICATE

This to certify that Argha Nandan of class XII of


Kendriya Vidyalaya No.2, Salt Lake, Kolkata
school, under the guidance and supervision of Mrs.
Sabiha Shahin (PGT Computer) has carried out the
project entitled Scholastic Quiz.
The students in accordance with the requirements of
All India Senior School Certificate Examination
2014, have performed this project.

Teachers Signature Principals Signature

External Examiners Signature


Date:
Roll No:

1
ACKNOWLEDGEMENT

I express my sincere acknowledgement and thanks to


my respected teacher Mrs. Sabiha Shahin (PGT
Computer) for the guidance extended to me and my
group members during the course of the project.

Last but not the least, I would like to sincerely thank


Mrs. Snigdha Deb, our Principal I/C for providing
us such a well equipped laboratory.

2
TOPIC:

SCHOLASTIC
QUIZ
USING DATA FILE HANDLING

3
ABOUT
This project is dedicated to the conversion of real-world
quizzing into a computer program. It is done using data
file handling.
The program has features like Play Game, Add
Questions, Delete or Modify Questions. The users can
play the game, add their own questions and edit existing
options.
Each of the questions in the quiz has four options out of
which only one will be correct and while adding
questions, the user will be prompted to indicate the
correct option. The players will also have scoring
facilities.
We can find these types of programs at many places,
especially on the internet. Online tests are organized these
days on a big scale now-a-days and all those are based on
data files.
We have mirrored them as far as possible and tried to
make it extensively interactive towards the user.
4
REQUIREMENTS

HARDWARE:
A computer having a monitor, a keyboard, a
mouse
A printer to print the documents

SOFTWARE:
An operating system (this project has been
done in Windows 7)
Turbo C++ installed
Snipping tool software, which is already
available on a computer having Windows 7 or
higher operating system. The software is used to
save the Output screens during the programs
run-time

5
DETAILS
PROBLEM:
The question will be declared as an object of a class,
having the question name, four options, and the correct
option as the data members declared privately. The
objects will have member functions to add, show and
update questions, declared publicly. There has to
individual functions to play game, add, modify and delete
questions and delete directory which are not part of the
class. File has to be opened in append mode to avoid
deletion of previously written data.
ALGORITHM:
main() function
1. Display welcome screen and main menu.
2. Accept option from user and call function.
3. Repeat step 2 till option is not Exit
present_quiz() function
1. Read object from data file. Display the question.
6
Take the option from user and check whether the
option is correct. Increment points if correct.
2. Repeat step 1 till there are no questions left in
the data file. Return to main().
write_ques() function
1. Open file in append mode and call add()
function to create an object. Write it to the file.
2. Repeat step 1 till user wants. Return to main().
update_record() function
1. Display all the questions and then accept the
question number which is to be deleted.
2. Repeat step 1 as required. Return to main().
delete_directory() function
1. Delete the data file after accepting the password.
anim() function
1. Use a delay loop inside a for loop.
2. Display each of the characters of the string one
at a time in each cycle of the outer loop.
7
CODING
SOURCE CODE:
#include<fstream.h> #include<conio.h>
#include<stdio.h> #include<process.h>
#include<string.h>
class Question
{
public: char ques[100], op1[20],op2[20],op3[20],op4[20];
int crt, Add();
void Display(int), Update(int);
};
int Question::Add()
{
cout<<"\nEnter the question: ";gets(ques);
cout<<"\nOption 1: ";gets(op1); cout<<"\nOption 2: ";gets(op2);
cout<<"\nOption 3: ";gets(op3); cout<<"\nOption 4: ";gets(op4);
cout<<"\nCorrect option(1/2/3/4): ";cin>>crt;
return crt;
}
void Question::Display(int i)
{
cout<<"\n"<<i<<". "<<ques;cout<<"\n\n1."<<op1;cout<<"\n\n2."<<op2;
cout<<"\n\n3."<<op3;cout<<"\n\n4."<<op4;cout<<"\n\nEnter your choice: ";
}
void Question::Update(int i)
{
cout<<"\n"<<i<<". "<<ques;
}
int check_pass()
{
char password[20]; cout<<"\nEnter the password: ";gets(password);
if(strcmp(password,"password")==0)

8
return 0;
return 1;
}
void present_quiz()
{
ifstream ifile; ifile.open("Directory.txt",ios::binary|ios::in);
int n,i=1, points=0; Question obj;
while(!ifile.eof())
{
clrscr();
ifile.read((char*)&obj,sizeof(obj));
if(ifile.eof())
break;
obj.Display(i); cin>>n;
if(obj.crt==n)
{
cout<<"\nIt's the correct answer!! \nYou get 1 point.";
points++;
}
else
cout<<"Oops!! Wrong answer";
getch(); i++;
}
ifile.close(); cout<<"\n\tGAME OVER ! ! !";
cout<<"\n\nTotal points earned = "<<points;
cout<<"\n\nPress ENTER"; getch();
}
void write_ques()
{
ofstream ofile; char ch; int chk;
ofile.open("Directory.txt",ios::binary|ios::app);
Question obj; chk=check_pass();
if(chk==0)
{
clrscr();
do

9
{
obj.Add(); ofile.write((char*)&obj,sizeof(obj));
cout<<"\nDo you want to add more questions?(Y/N): ";
cin>>ch;
}while(ch=='y' || ch=='Y');
}
else
cout<<"\nWrong Password !";
ofile.close();
}
void update_record(int k)
{
ifstream ifile; ofstream ofile;
ofile.open("temp.txt",ios::app|ios::binary);
int n,i=1,chk;
ifile.open("Directory.txt",ios::binary|ios::in);
Question obj; chk=check_pass();
if(chk==0)
{
clrscr();
while(!ifile.eof())
{
ifile.read((char*)&obj,sizeof(obj));
if(ifile.eof())
break;
obj.Update(i); i++;
}
if(k==3)
cout<<"\n\nWhich question do you want to edit?: ";
else
cout<<"\n\nWhich question do you want to delete?: ";
cin>>n;
for(i=1;i<=n;i++)
{
ifile.read((char*)&obj,sizeof(obj));
if(i!=n)

10
ofile.write((char*)&obj,sizeof(obj));
}
remove("Directory.txt");rename("temp.txt","Directory.txt");
if(k==3)
write_ques();
}
else
cout<<"\nWrong Password !";
ifile.close();ofile.close();
}
void delete_directory()
{
int chk;chk=check_pass();
if(chk==0)
{
ifstream ifile;
ifile.open("Directory.txt",ios::binary|ios::in);
remove("Directory.txt");
cout<<"\nDirectory Deleted ! Please press ENTER";
getch();
ifile.close();ofstream ofile;
ofile.open("Directory,txt",ios::binary|ios::app);ofile.close();
}
else
cout<<"\nWrong password !";
}
void anim(char str[100])
{
int i;long j;
for(i=0;i<strlen(str);i++)
{
for(j=0;j<=20000000;j++);cout<<str[i];
}
}
void main()
{

11
int n;char ch;
char welcome[]="Welcome to Scholastic Quiz!!!";
char present[]="Presented by:";
char argha[]="Argha Nandan and Nabanil Chatterjee";
char press[]="Press Enter...";
do
{
clrscr();
char play[]="1. Play Game";char add[]="2. Add Question";
char edit[]="3. Edit Question";char delques[]="4. Delete Question";
char deldirec[]="5. Delete Directory";char quit[]="6. Quit";
char enter[]="Enter your choice: ";
char doyou[]="Do you want to go to the main menu?(Y/N):";
cout<<"\n\n\n\t\t";anim(welcome);cout<<"\n\n\n\t\t\t";anim(present);
cout<<"\n\n\t\t";anim(argha);cout<<"\n\n\n\n\t\t\t";anim(press);
getch();clrscr();cout<<"\n\n\n\t\t"; anim(play);cout<<"\n\n\t\t";
anim(add);cout<<"\n\n\t\t"; anim(edit);cout<<"\n\n\t\t"; anim(delques);
cout<<"\n\n\t\t";anim(deldirec);cout<<"\n\n\t\t"; anim(quit);
cout<<"\n\n\t\t";anim(enter);cin>>n;
switch(n)
{
case 1: present_quiz();break;
case 2: write_ques(); break;
case 3: update_record(3);break;
case 4: update_record(4);break;
case 5: delete_directory();break;
case 6: exit(0);break;
}
cout<<"\n\n\t";anim(doyou);cin>>ch;
if(ch=='n' || ch=='N')
exit(0);
}while(ch=='y' || ch=='Y');
}

12
OUTPUT SCREENS:

Welcome Screen

Main Menu

13
Adding Question

Playing Game

14
Deleting Question

Deleting Directory

15
BIBLIOGRAPHY

During the course of the project, we took help


from our teachers and the following book:

Computer Science C++ - A textbook for


class XII by Sumita Arora

-*-^-*-

16

Você também pode gostar