Professional Documents
Culture Documents
CBSE Class XII Computer Project Report (Body)
CBSE Class XII Computer Project Report (Body)
Normal User Mode: Anyone can use this mode, which allows a user to
attempt questions in the included database. Questions are presented in a
multiple-choice format, with automatic scoring. After the user chooses to
exit the session, he / she is presented with extended statistics about his
/ her quizzing session.
Administrator Mode: An authenticated mode, it allows the user to
carry out advanced functions like managing question and / or user
database, accessing overall statistics about all users, searching users by
different criteria, and changing current administration password. It also
offers a Quizmaster Mode, intended to be stage-round specific mode for
a quiz, which allows the authenticated user to view the correct answer
along with the questions and their options.
page1
.: Source Code :.
/*
#include
#include
#include
#include
#include
#include
#include
<fstream.h>
<conio.h>
<stdio.h>
<string.h>
<process.h>
<graphics.h>
<dir.h>
page2
if (flag == 0)
cout<<endl<<"Username you searched for does not
exist!"<<endl;
else cout<<endl<<"User with username "<<check<<" has been
deleted."<<endl;
cout<<endl<<"Press any key to continue...";
getch();
file.close();
temp.close();
remove("user.dat");
rename("temp.dat", "user.dat");
}
void edituser() // Edit records of a particular user
{
clearviewport();
border();
cout<<endl<<"Enter username of user whose record needs to be
edited: ";
gets(check);
file.open("user.dat", ios::in|ios::binary);
temp.open("temp.dat", ios::out|ios::binary);
flag = 0;
while (file.read((char*)&u1, sizeof(u1)))
{
strcpy(name, u1.retname());
if(strcmpi (check, name) == 0)
{
flag = 1;
cout<<endl<<"Enter new details for user "<<name<<endl;
u2.getuser();
u2.score = u1.score; // To prevent reset of score
u2.pass = u1.pass;
u2.perc = u1.perc;
temp.write((char*)&u2, sizeof(u2));
}
else temp.write((char*)&u1, sizeof(u1));
}
if (flag == 0)
cout<<endl<<"Username you searched for does not
exist!"<<endl;
else cout<<endl<<"User with username "<<check<<" has been
edited."<<endl;
cout<<endl<<"Press any key to continue...";
getch();
file.close();
temp.close();
remove("user.dat");
rename("temp.dat", "user.dat");
}
page5
void searchuser()
{
clearviewport();
border();
cout<<endl<<"User Details Search"
<<endl<<"Search by"
<<endl<<"\t1. Name"
<<endl<<"\t2. Age"
<<endl<<"Enter your choice (1-2): ";
cin>>ich;
file.open("user.dat", ios::in|ios::binary);
switch(ich)
{
case 1 : // For searching by name
cout<<endl<<"Enter username to be searched: ";
gets(check);
flag = 0;
while(file.read((char*)&u1, sizeof(u1)))
{
strcpy(name, u1.retname());
if(strcmpi (name, check) == 0)
{
flag = 1;
u1.showuser();
cout<<endl<<"Press any key to
continue...";
getch();
}
}
if (flag == 0)
{
cout<<"Username you searched for does not
exist!"<<endl;
cout<<endl<<"Press any key to continue...";
getch();
}
break;
case 2 : // For searching by age
cout<<endl<<"Enter the age to be searched in
records: ";
cin>>r1;
flag = 0;
while (file.read((char*)&u1, sizeof(u1)))
{
r2 = u1.retage();
if (r1 == r2)
{
flag = 1;
u1.showuser();
cout<<endl<<"Press any key to
continue...";
getch();
}
page6
}
if (flag == 0)
{
cout<<endl<<"Age you searched for does not
exist in any record!"<<endl;
cout<<endl<<"Press any key to continue...";
getch();
}
break;
default : cout<<endl<<"You entered an invalid choice! Press
any key to continue...";
getch();
}
file.close();
file.close();
break;
case 2 : float p1, p2;
p1 = u1.perc;
while (file.read((char*)&u1, sizeof(u1)))
{
p2 = u1.perc;
if (p2 > p1)
p1 = p2;
}
cout<<endl<<"Highest Accuracy Percentage is: "
<<p1<<endl<<"Details of user(s) with high
score: ";
file.close();
file.open("user.dat", ios::in|ios::binary);
while (file.read((char*)&u1, sizeof(u1)))
{
if (u1.perc == p1)
{
u1.showuser();
cout<<endl<<"Press any key to
continue...";
getch();
clearviewport();
border();
}
}
file.close();
break;
default : cout<<endl<<"You entered an incorrect choice!
Press any key to continue...";
getch();
}
void playquiz() // Normal mode playquiz
{
clearviewport();
border();
cout<<endl<<"Jabberwocky Normal User Mode"
<<endl<<endl<<"Rules"
<<endl<<"\t1. Each correct answer gets you +42 points"
<<endl<<"\t2. Each incorrect answer gets you -21 points"
<<endl<<"\t3. No points / penalties for a pass";
cout<<endl<<endl<<"Get ready to play the quiz! Press any key to
continue...";
getch();
r3 = 0;
ich = 0;
file.open("ques.dat", ios::in|ios::binary);
while(file.read((char*)&q1, sizeof(q1)))
{
page8
r3++;
clearviewport();
border();
cout<<endl<<"Question Number "<<r3;
q1.showq();
cout<<endl<<"Enter your answer (1-4; 5 for a 'pass'): ";
cin>>r1;
r2 = q1.retans();
if (r1 == r2)
{
cout<<endl<<"Correct answer! You get 42 points!";
u1.score += 42;
ich++;
}
else if (r1 == 5)
u1.pass++;
else
{
u1.score -= 21;
cout<<endl<<"Wrong answer! Correct option is
"<<r2<<".";
}
cout<<endl<<"Press any key to continue (or '0' to finish
quiz)...";
cch = getch();
if (cch == '0')
break;
}
u1.perc = ((float)ich / r3) * 100;
cout<<endl<<endl<<"You scored "<<u1.score<<" points with "
<<u1.pass<<" passes out of a total of "<<r3<<" questions"
<<" resulting in an accuracy of "<<u1.perc<<" percentage.";
file.close();
file.open("user.dat", ios::app|ios::binary);
file.write((char*)&u1, sizeof(u1));
file.close();
cout<<endl<<endl<<"Press any key to continue...";
getch();
clearviewport();
border();
file.open("ques.dat", ios::app|ios::binary);
cout<<endl<<"Enter new questions in the question database";
cout<<endl<<endl<<"Press any key to continue...";
getch();
do
{
q1.getq();
file.write((char*)&q1, sizeof(q1));
cout<<endl<<"Question added to database"<<endl
<<"Do you want to enter another question? (Y/N) : ";
cin>>cch;
} while (cch == 'y' || cch == 'Y');
file.close();
}
void editq() // Edit existing questions in database
{
adminedit:
clearviewport();
border();
cout<<endl<<"Enter question number to be edited (0 to exit): ";
cin>>r2;
countq();
if ((r2 < 0) || (r2 > r3))
{
cout<<endl<<"Sorry, record number you requested does not
exist!";
cout<<endl<<endl<<"Press any key to continue...";
getch();
goto adminedit;
}
r1 = 0;
file.open("ques.dat", ios::in|ios::binary);
temp.open("temp.dat", ios::out|ios::binary);
while (file.read((char*)&q1, sizeof(q1)))
{
r1++;
if (r1 == r2)
{
q1.showq();
cout<<endl<<"Is this the question you want to edit?
(Y/N): ";
cin>>cch;
if (cch == 'y' || cch == 'Y')
{
cout<<endl<<"Enter new details for question";
cout<<endl<<endl<<"Press any key to continue...";
getch();
q2.getq();
temp.write((char*)&q2, sizeof(q2));
page10
}
else
{
cout<<endl<<"Question has not been edited.";
cout<<endl<<endl<<"Press any key to continue...";
getch();
file.close();
temp.close();
goto adminedit;
}
}
else temp.write((char*)&q1, sizeof(q1));
}
file.close();
temp.close();
remove("ques.dat");
rename("temp.dat", "ques.dat");
}
}
else
{
}
}
file.close();
temp.close();
remove("ques.dat");
rename("temp.dat", "ques.dat");
}
void qmmode() // Quizmaster Mode - For viewing all questions with
answers
{
cout<<endl<<"Entering Quizmaster Mode"<<endl
<<"This displays all questions in the database along with
the answer";
r3 = 0;
file.open("ques.dat",ios::in|ios::binary);
while(file.read((char*)&q1, sizeof(q1)))
{
r3++;
clearviewport();
border();
cout<<endl<<"Question Number "<<r3;
q1.showq();
r1 = q1.retans();
cout<<"Option number "<<r1<<" is correct"<<endl
<<"Press any key to continue (or '0' to exit QM
mode)...";
cch = getch();
if (cch == '0')
break;
}
file.close();
}
void viewusers() // To view details of all users till now
{
clearviewport();
border();
page12
r1++;
cch = file.get();
cout<<cch;
if ( (r1%720) == 0)
{
cout<<endl<<endl<<"Press any key to continue (or '0'
to exit this mode)..."<<endl<<endl;
cch = getch();
if (cch == '0')
break;
}
}
file.close();
cout<<endl<<endl<<"Press any key to continue...";
getch();
}
void zaphod() // Easter egg
{
clearviewport();
border();
r1 = 0;
file.open("zaphod.txt", ios::in);
while (!file.eof())
{
r1++;
cch = file.get();
cout<<cch;
if ( (r1%1000) == 0)
{
cout<<endl<<endl<<"Press any key to continue (or '0'
to exit this mode)..."<<endl<<endl;
cch = getch();
if (cch == '0')
break;
}
}
file.close();
cout<<endl<<endl<<"Press any key to continue...";
getch();
}
void pwdchk()
{
clearviewport();
border();
cout<<endl<<"Jabberwocky Password Authentication"
<<endl<<endl<<"Enter current password: ";
for (int i = 0; ;i++)
{
check[i] = getch();
page14
if(check[i] == '\r')
break;
cout<<"*";
}
check[i] = '\0';
file.open("pwd.dat", ios::in|ios::binary);
file.read((char*)&name, 42);
file.close();
flag = 0;
if (strcmp (check, name) == 0)
{
flag = 1;
cout<<endl<<"Authentication confirmed"<<endl;
}
else cout<<endl<<"Sorry! Invalid password!";
cout<<endl<<endl<<"Press any key to continue...";
getch();
}
void pswd() // Password manipulation
{
pwdchk();
if (flag == 1)
{
pwdchange:
cout<<endl<<"Enter new password (alphanumeric): ";
for (int i = 0; ;i++)
{
check[i]=getch();
if(check[i]=='\r')
break;
cout<<"*";
}
check[i]='\0';
cout<<endl<<"Confirm new password: ";
for( i = 0; ;i++)
{
name[i]=getch();
if(name[i]=='\r')
break;
cout<<"*";
}
name[i]='\0';
if (strcmp(check,name) == 0)
{
file.open("pwd.dat", ios::out|ios::binary);
file.write((char*)&name, 42);
file.close();
cout<<endl<<"Password has been changed successfully!";
cout<<endl<<endl<<"Press any key to continue...";
getch();
}
page15
else
{
again!";
}
void admin() // Options for administrator mode
{
clearviewport();
border();
pwdchk();
if (flag == 1)
{
admenu:
// To maintain uniformity
clearviewport();
border();
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,4);
outtextxy(64,1,"Jabberwocky Administrator Menu");
gotoxy(1,4);
cout<<endl<<"\t1. Quizmaster Mode"<<endl;
cout<<endl<<"\tQuestion Database Options"
<<endl<<"\t\t2. Add Questions To Database";
cout<<endl<<"\t\t3. Edit Question Currently In
Database"<<endl
<<"\t\t4. Delete Question Currently In Database"
<<endl<<"\t\t5. Count Number of Questions In
Database"<<endl;
cout<<endl<<"\tUser Database Options"
<<endl<<"\t\t6. View Users"
<<endl<<"\t\t7. Search User Records";
cout<<endl<<"\t\t8. Edit User Record"
<<endl<<"\t\t9. Delete User Record"<<endl
<<endl<<"\t10. View High Score";
cout<<endl<<"\t11. Change Administrator Password"
<<endl<<endl<<"12. Help"
<<endl<<"0. Exit Administrator Mode"<<endl
<<endl<<"Enter your choice (0-12): ";
cin>>ich;
switch(ich)
{
case 0 : goto end;
case 1 : qmmode();
break;
case 2 : addq();
break;
case 3 : editq();
break;
page16
case 4 :
case 5 :
case 6 :
case 7 :
case 8 :
case 9 :
case 10 :
case 11 :
case 12 :
case 42 :
default :
}
goto admenu;
delq();
break;
countq();
cout<<endl<<"The database has "<<r3<<"
questions";
cout<<endl<<endl<<"Press any key to
continue...";
getch();
break;
viewusers();
break;
searchuser();
break;
edituser();
break;
deluser();
break;
highscore();
break;
pswd();
break;
proghelp();
break;
zaphod();
break;
cout<<endl<<"You entered an invalid
choice!";
cout<<endl<<endl<<"Press any key to
continue...";
getch();
end:
cout<<endl<<"You are about to exit Jabberwocky Administrator
Menu"<<endl<<"Press any key to continue...";
getch();
}
void main()
{
char *p = searchpath( "Graphics" );
initgraph(&gd, &gm,p); // Initiating graphics mode
setlinestyle(DASHED_LINE,0,NORM_WIDTH);
menu:
clearviewport();
border();
outtext(" Welcome to Jabberwocky!");
gotoxy(12,9);
cout<<"1. Normal User Mode";
gotoxy(50,9);
cout<<"2. Administrator Mode";
page17
gotoxy(35,15);
cout<<"0. Exit";
gotoxy(12,21);
cout<<"3. Help";
gotoxy(50,21);
cout<<"4. About";
gotoxy(1,24);
cout<<"Enter your choice (0-4): ";
cin>>ich;
switch(ich)
{
case 1 : u1.getuser(); // Get user details
playquiz(); // Allow user to start playing
break;
case 2 : admin();
break;
case 3 : proghelp(); // Program help
break;
case 4 : aboutus();
break;
case 0 : exit(0);
case 42 : zaphod(); // An easter egg
break;
default : cout<<endl<<"You entered an invalid
choice!";
cout<<endl<<endl<<"Press any key to
continue...";
getch();
}
goto menu;
page18
Main Menu
Administrator Menu
page19
Quizmaster Mode
page20
page21
page23