Quiz using C++

45
1 | Page

description

Quiz using C++

Transcript of Quiz using C++

Page 1: Quiz using C++

1 | P a g e

Made By -

Sushil Kumar Mishra (05311502809)

Of ECE-I

INTRODUCTIONThe Online Quiz is basically for the school and college goers where a user can give an online test for asubject(s) According to the number of marks hisher evaluation has to be done Where the students at largethis Online Quiz scrutinize the universitiesInstitutions problems at once and produce a quick response in alimited timeIt can be further extended to any organization or company who want to conduct the examination usingonlineThe project keeps four different data files such as 1048712 Computerdat1048712 Mathsdat1048712 Sciencedata1048712 GeneraldatAll the above files have the common fields but the records are appended according to the examinationoptionques_no Question numberques Name of the questionans1 First answer of the questionans2 Second answer of the questionans3 Third answer of the questionsol Correct answer of the questionThe Online Quiz system displays the result immediately after a quiz is completed The Online Quiz systemkeeps track of the following options for maintaining its database and quizQUIZOPTIONSPLAYADD QUESTIONSEDITQUITPLAY This option opens a sub-menu as SUB ndash MENUCOMPUTERMATHEMATICSSCIENCEGENERAL(Uparrow DownArrow)=Move ltENTERgt = Select ltESCgtExitFrom the above menus when you select any one option you will be used to enter your name Afterentering your name it will display the question one-by-one and you have to give the answer in a specified timelimit If the time limit is over it will display the next question and zero will be added to your score otherwiseyour score will be incremented by one In the end you will see a score board as shown in Fig 19 Similarly youcan attend all the sub-menu options as required by youADD QUESTIONS In this option you can add different questions to your previous sub-menu options Forexample you select COMPUTER you will see a screen for adding a question with its question number andquestion detailsHere the question number generates automatically After entering three answers and its right solutionyou will be asked for updating the database for next quizEDIT In this option you can delete modify your previously entered questions as required Here all theprocess will transact through the question numberClass Description- lines It controls function related to draw horizontal and vertical line and boxes- menu It control the overall functioning of Online Quiz project It displays all menus and submenus- quiz It controls overall function related to quiz like adding deleting or modifying questionsin the database

2 | P a g e

SOURCE CODE PROJECT COMPUTER QUIZ INCLUDED HEADER FILESinclude ltiostreamhgtinclude ltconiohgtinclude ltdoshgtinclude ltstringhgtinclude ltfstreamhgtinclude ltprocesshgtinclude ltstdlibhgtinclude ltstdiohgtinclude ltctypehgt CLASS NAME lines DETAILS IT CONTROLS FUNCTIONS RELATED TO DRAW LINES BOXES ETCclass linespublic

void line_hor (int int int char) void line_ver (int int int char) void box (intintintintchar)

CLASS NAME menu DETAILS IT CONTROLS OVER ALL FUNCTIONING OF PROJECTclass menupublic

void main_menu(void) char sub_menu(void) void start(void)

private void edit_menu(void)

3 | P a g e

CLASS NAME quiz DETAILS IT CONTROLS OVER ALL THE FUNCTIONS RELATED TO QUIZclass quizpublic

void play(char filename[13]) void add(char filename[13]) void deletion(char filename[13]) void modify(char filename[13])

private void delete_record(char filename[13] int) void modify_record(char filename[13] int) void display_score(char name[20] int int) int recordno(char filename[13] int) int record_count(char filename[13]) int found_record(char filename[13] int) void display_record(char filename[13] int) int ques_no char ques[60] char ans1[50] char ans2[50] char ans3[50] char sol

CLASS NAME lines FUNCTION NAME line_hor DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE HORIZONTAL LINEvoid lines line_hor(int column1 int column2 int row char c) for ( column1 column1lt=column2 column1++ ) gotoxy(column1row) cout ltltc CLASS NAME lines FUNCTION NAME line_ver

4 | P a g e

DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE VERTICAL LINEvoid lines line_ver(int row1 int row2 int column char c) for ( row1 row1lt=row2 row1++ ) gotoxy(columnrow1) cout ltltc CLASS NAME lines FUNCTION NAME box DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE BOXvoid lines box(int column1 int row1 int column2 int row2 char c) char ch=218 char c1 c2 c3 c4 char l1=196 l2=179 if (c == ch) c1 = 218

c2 = 191 c3 = 192 c4 = 217 l1 = 196 l2 = 179

else c1 = c

c2 = c c3 = c c4 = c l1 = c l2 = c

gotoxy(column1row1) cout ltltc1 gotoxy(column2row1) cout ltltc2 gotoxy(column1row2) cout ltltc3 gotoxy(column2row2) cout ltltc4 column1++

5 | P a g e

column2-- line_hor(column1column2row1l1) line_hor(column1column2row2l1) column1-- column2++ row1++ row2-- line_ver(row1row2column1l2) line_ver(row1row2column2l2) CLASS NAME menu FUNCTION NAME start DETAILS IT CREATES THE OPENING SCREENvoid menu start(void) lines line textmode(C80) clrscr() textbackground(LIGHTCYAN) textcolor(BLACK) clrscr() gotoxy(812) cout ltltC O M P U T E R gotoxy(2512) cout ltltQ U I Z linebox(410361421) gotoxy(521) coutltltMADE BY gotoxy(522) coutltltSUSHIL MISHRASACHIN MISHRA(ECE-1) linebox(2194024219) gotoxy(410) getch() textbackground(BLACK) textcolor(LIGHTGRAY) clrscr() CLASS NAME menu FUNCTION NAME main_menu DETAILS IT CREATES THE MAIN MENU TO CONTROL ALL THE FUNCTIONS

6 | P a g e

void menu main_menu(void) lines line textmode(C80) clrscr int valid int n = 4 int x = 14 char ch1 ch2 char chr1=219 chr=175 do linebox (113925219)

lineline_hor(9316196) linebox (833220218) char c1=24 c2=25 gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(135) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(145) cprintf(Q U I Z ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(148) cout ltltOPTIONS gotoxy(149) cout ltlt------- gotoxy(1411) cout ltltPLAY gotoxy(1412) cout ltltADD QUESTIONS gotoxy(1413) cout ltltEDIT gotoxy(1414) cout ltltQUIT gotoxy(10x) cout ltltchr gotoxy(135) do

7 | P a g e

do do

ch1 = getch() if ( ch1 == 27 )

textmode(C80) clrscr() exit(0) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do ch2 = getch() if ( ch2 == 27 )

textmode(C80) clrscr() exit(0)

while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(10x)

cout ltlt if (n == 4) n = 1

x = x - 3 else n = n + 1

x = x + 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(10x)

cout ltlt if ( n == 1 ) n = 4

x = x + 3 else n = n - 1

8 | P a g e

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 2: Quiz using C++

INTRODUCTIONThe Online Quiz is basically for the school and college goers where a user can give an online test for asubject(s) According to the number of marks hisher evaluation has to be done Where the students at largethis Online Quiz scrutinize the universitiesInstitutions problems at once and produce a quick response in alimited timeIt can be further extended to any organization or company who want to conduct the examination usingonlineThe project keeps four different data files such as 1048712 Computerdat1048712 Mathsdat1048712 Sciencedata1048712 GeneraldatAll the above files have the common fields but the records are appended according to the examinationoptionques_no Question numberques Name of the questionans1 First answer of the questionans2 Second answer of the questionans3 Third answer of the questionsol Correct answer of the questionThe Online Quiz system displays the result immediately after a quiz is completed The Online Quiz systemkeeps track of the following options for maintaining its database and quizQUIZOPTIONSPLAYADD QUESTIONSEDITQUITPLAY This option opens a sub-menu as SUB ndash MENUCOMPUTERMATHEMATICSSCIENCEGENERAL(Uparrow DownArrow)=Move ltENTERgt = Select ltESCgtExitFrom the above menus when you select any one option you will be used to enter your name Afterentering your name it will display the question one-by-one and you have to give the answer in a specified timelimit If the time limit is over it will display the next question and zero will be added to your score otherwiseyour score will be incremented by one In the end you will see a score board as shown in Fig 19 Similarly youcan attend all the sub-menu options as required by youADD QUESTIONS In this option you can add different questions to your previous sub-menu options Forexample you select COMPUTER you will see a screen for adding a question with its question number andquestion detailsHere the question number generates automatically After entering three answers and its right solutionyou will be asked for updating the database for next quizEDIT In this option you can delete modify your previously entered questions as required Here all theprocess will transact through the question numberClass Description- lines It controls function related to draw horizontal and vertical line and boxes- menu It control the overall functioning of Online Quiz project It displays all menus and submenus- quiz It controls overall function related to quiz like adding deleting or modifying questionsin the database

2 | P a g e

SOURCE CODE PROJECT COMPUTER QUIZ INCLUDED HEADER FILESinclude ltiostreamhgtinclude ltconiohgtinclude ltdoshgtinclude ltstringhgtinclude ltfstreamhgtinclude ltprocesshgtinclude ltstdlibhgtinclude ltstdiohgtinclude ltctypehgt CLASS NAME lines DETAILS IT CONTROLS FUNCTIONS RELATED TO DRAW LINES BOXES ETCclass linespublic

void line_hor (int int int char) void line_ver (int int int char) void box (intintintintchar)

CLASS NAME menu DETAILS IT CONTROLS OVER ALL FUNCTIONING OF PROJECTclass menupublic

void main_menu(void) char sub_menu(void) void start(void)

private void edit_menu(void)

3 | P a g e

CLASS NAME quiz DETAILS IT CONTROLS OVER ALL THE FUNCTIONS RELATED TO QUIZclass quizpublic

void play(char filename[13]) void add(char filename[13]) void deletion(char filename[13]) void modify(char filename[13])

private void delete_record(char filename[13] int) void modify_record(char filename[13] int) void display_score(char name[20] int int) int recordno(char filename[13] int) int record_count(char filename[13]) int found_record(char filename[13] int) void display_record(char filename[13] int) int ques_no char ques[60] char ans1[50] char ans2[50] char ans3[50] char sol

CLASS NAME lines FUNCTION NAME line_hor DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE HORIZONTAL LINEvoid lines line_hor(int column1 int column2 int row char c) for ( column1 column1lt=column2 column1++ ) gotoxy(column1row) cout ltltc CLASS NAME lines FUNCTION NAME line_ver

4 | P a g e

DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE VERTICAL LINEvoid lines line_ver(int row1 int row2 int column char c) for ( row1 row1lt=row2 row1++ ) gotoxy(columnrow1) cout ltltc CLASS NAME lines FUNCTION NAME box DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE BOXvoid lines box(int column1 int row1 int column2 int row2 char c) char ch=218 char c1 c2 c3 c4 char l1=196 l2=179 if (c == ch) c1 = 218

c2 = 191 c3 = 192 c4 = 217 l1 = 196 l2 = 179

else c1 = c

c2 = c c3 = c c4 = c l1 = c l2 = c

gotoxy(column1row1) cout ltltc1 gotoxy(column2row1) cout ltltc2 gotoxy(column1row2) cout ltltc3 gotoxy(column2row2) cout ltltc4 column1++

5 | P a g e

column2-- line_hor(column1column2row1l1) line_hor(column1column2row2l1) column1-- column2++ row1++ row2-- line_ver(row1row2column1l2) line_ver(row1row2column2l2) CLASS NAME menu FUNCTION NAME start DETAILS IT CREATES THE OPENING SCREENvoid menu start(void) lines line textmode(C80) clrscr() textbackground(LIGHTCYAN) textcolor(BLACK) clrscr() gotoxy(812) cout ltltC O M P U T E R gotoxy(2512) cout ltltQ U I Z linebox(410361421) gotoxy(521) coutltltMADE BY gotoxy(522) coutltltSUSHIL MISHRASACHIN MISHRA(ECE-1) linebox(2194024219) gotoxy(410) getch() textbackground(BLACK) textcolor(LIGHTGRAY) clrscr() CLASS NAME menu FUNCTION NAME main_menu DETAILS IT CREATES THE MAIN MENU TO CONTROL ALL THE FUNCTIONS

6 | P a g e

void menu main_menu(void) lines line textmode(C80) clrscr int valid int n = 4 int x = 14 char ch1 ch2 char chr1=219 chr=175 do linebox (113925219)

lineline_hor(9316196) linebox (833220218) char c1=24 c2=25 gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(135) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(145) cprintf(Q U I Z ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(148) cout ltltOPTIONS gotoxy(149) cout ltlt------- gotoxy(1411) cout ltltPLAY gotoxy(1412) cout ltltADD QUESTIONS gotoxy(1413) cout ltltEDIT gotoxy(1414) cout ltltQUIT gotoxy(10x) cout ltltchr gotoxy(135) do

7 | P a g e

do do

ch1 = getch() if ( ch1 == 27 )

textmode(C80) clrscr() exit(0) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do ch2 = getch() if ( ch2 == 27 )

textmode(C80) clrscr() exit(0)

while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(10x)

cout ltlt if (n == 4) n = 1

x = x - 3 else n = n + 1

x = x + 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(10x)

cout ltlt if ( n == 1 ) n = 4

x = x + 3 else n = n - 1

8 | P a g e

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 3: Quiz using C++

SOURCE CODE PROJECT COMPUTER QUIZ INCLUDED HEADER FILESinclude ltiostreamhgtinclude ltconiohgtinclude ltdoshgtinclude ltstringhgtinclude ltfstreamhgtinclude ltprocesshgtinclude ltstdlibhgtinclude ltstdiohgtinclude ltctypehgt CLASS NAME lines DETAILS IT CONTROLS FUNCTIONS RELATED TO DRAW LINES BOXES ETCclass linespublic

void line_hor (int int int char) void line_ver (int int int char) void box (intintintintchar)

CLASS NAME menu DETAILS IT CONTROLS OVER ALL FUNCTIONING OF PROJECTclass menupublic

void main_menu(void) char sub_menu(void) void start(void)

private void edit_menu(void)

3 | P a g e

CLASS NAME quiz DETAILS IT CONTROLS OVER ALL THE FUNCTIONS RELATED TO QUIZclass quizpublic

void play(char filename[13]) void add(char filename[13]) void deletion(char filename[13]) void modify(char filename[13])

private void delete_record(char filename[13] int) void modify_record(char filename[13] int) void display_score(char name[20] int int) int recordno(char filename[13] int) int record_count(char filename[13]) int found_record(char filename[13] int) void display_record(char filename[13] int) int ques_no char ques[60] char ans1[50] char ans2[50] char ans3[50] char sol

CLASS NAME lines FUNCTION NAME line_hor DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE HORIZONTAL LINEvoid lines line_hor(int column1 int column2 int row char c) for ( column1 column1lt=column2 column1++ ) gotoxy(column1row) cout ltltc CLASS NAME lines FUNCTION NAME line_ver

4 | P a g e

DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE VERTICAL LINEvoid lines line_ver(int row1 int row2 int column char c) for ( row1 row1lt=row2 row1++ ) gotoxy(columnrow1) cout ltltc CLASS NAME lines FUNCTION NAME box DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE BOXvoid lines box(int column1 int row1 int column2 int row2 char c) char ch=218 char c1 c2 c3 c4 char l1=196 l2=179 if (c == ch) c1 = 218

c2 = 191 c3 = 192 c4 = 217 l1 = 196 l2 = 179

else c1 = c

c2 = c c3 = c c4 = c l1 = c l2 = c

gotoxy(column1row1) cout ltltc1 gotoxy(column2row1) cout ltltc2 gotoxy(column1row2) cout ltltc3 gotoxy(column2row2) cout ltltc4 column1++

5 | P a g e

column2-- line_hor(column1column2row1l1) line_hor(column1column2row2l1) column1-- column2++ row1++ row2-- line_ver(row1row2column1l2) line_ver(row1row2column2l2) CLASS NAME menu FUNCTION NAME start DETAILS IT CREATES THE OPENING SCREENvoid menu start(void) lines line textmode(C80) clrscr() textbackground(LIGHTCYAN) textcolor(BLACK) clrscr() gotoxy(812) cout ltltC O M P U T E R gotoxy(2512) cout ltltQ U I Z linebox(410361421) gotoxy(521) coutltltMADE BY gotoxy(522) coutltltSUSHIL MISHRASACHIN MISHRA(ECE-1) linebox(2194024219) gotoxy(410) getch() textbackground(BLACK) textcolor(LIGHTGRAY) clrscr() CLASS NAME menu FUNCTION NAME main_menu DETAILS IT CREATES THE MAIN MENU TO CONTROL ALL THE FUNCTIONS

6 | P a g e

void menu main_menu(void) lines line textmode(C80) clrscr int valid int n = 4 int x = 14 char ch1 ch2 char chr1=219 chr=175 do linebox (113925219)

lineline_hor(9316196) linebox (833220218) char c1=24 c2=25 gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(135) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(145) cprintf(Q U I Z ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(148) cout ltltOPTIONS gotoxy(149) cout ltlt------- gotoxy(1411) cout ltltPLAY gotoxy(1412) cout ltltADD QUESTIONS gotoxy(1413) cout ltltEDIT gotoxy(1414) cout ltltQUIT gotoxy(10x) cout ltltchr gotoxy(135) do

7 | P a g e

do do

ch1 = getch() if ( ch1 == 27 )

textmode(C80) clrscr() exit(0) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do ch2 = getch() if ( ch2 == 27 )

textmode(C80) clrscr() exit(0)

while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(10x)

cout ltlt if (n == 4) n = 1

x = x - 3 else n = n + 1

x = x + 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(10x)

cout ltlt if ( n == 1 ) n = 4

x = x + 3 else n = n - 1

8 | P a g e

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 4: Quiz using C++

CLASS NAME quiz DETAILS IT CONTROLS OVER ALL THE FUNCTIONS RELATED TO QUIZclass quizpublic

void play(char filename[13]) void add(char filename[13]) void deletion(char filename[13]) void modify(char filename[13])

private void delete_record(char filename[13] int) void modify_record(char filename[13] int) void display_score(char name[20] int int) int recordno(char filename[13] int) int record_count(char filename[13]) int found_record(char filename[13] int) void display_record(char filename[13] int) int ques_no char ques[60] char ans1[50] char ans2[50] char ans3[50] char sol

CLASS NAME lines FUNCTION NAME line_hor DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE HORIZONTAL LINEvoid lines line_hor(int column1 int column2 int row char c) for ( column1 column1lt=column2 column1++ ) gotoxy(column1row) cout ltltc CLASS NAME lines FUNCTION NAME line_ver

4 | P a g e

DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE VERTICAL LINEvoid lines line_ver(int row1 int row2 int column char c) for ( row1 row1lt=row2 row1++ ) gotoxy(columnrow1) cout ltltc CLASS NAME lines FUNCTION NAME box DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE BOXvoid lines box(int column1 int row1 int column2 int row2 char c) char ch=218 char c1 c2 c3 c4 char l1=196 l2=179 if (c == ch) c1 = 218

c2 = 191 c3 = 192 c4 = 217 l1 = 196 l2 = 179

else c1 = c

c2 = c c3 = c c4 = c l1 = c l2 = c

gotoxy(column1row1) cout ltltc1 gotoxy(column2row1) cout ltltc2 gotoxy(column1row2) cout ltltc3 gotoxy(column2row2) cout ltltc4 column1++

5 | P a g e

column2-- line_hor(column1column2row1l1) line_hor(column1column2row2l1) column1-- column2++ row1++ row2-- line_ver(row1row2column1l2) line_ver(row1row2column2l2) CLASS NAME menu FUNCTION NAME start DETAILS IT CREATES THE OPENING SCREENvoid menu start(void) lines line textmode(C80) clrscr() textbackground(LIGHTCYAN) textcolor(BLACK) clrscr() gotoxy(812) cout ltltC O M P U T E R gotoxy(2512) cout ltltQ U I Z linebox(410361421) gotoxy(521) coutltltMADE BY gotoxy(522) coutltltSUSHIL MISHRASACHIN MISHRA(ECE-1) linebox(2194024219) gotoxy(410) getch() textbackground(BLACK) textcolor(LIGHTGRAY) clrscr() CLASS NAME menu FUNCTION NAME main_menu DETAILS IT CREATES THE MAIN MENU TO CONTROL ALL THE FUNCTIONS

6 | P a g e

void menu main_menu(void) lines line textmode(C80) clrscr int valid int n = 4 int x = 14 char ch1 ch2 char chr1=219 chr=175 do linebox (113925219)

lineline_hor(9316196) linebox (833220218) char c1=24 c2=25 gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(135) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(145) cprintf(Q U I Z ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(148) cout ltltOPTIONS gotoxy(149) cout ltlt------- gotoxy(1411) cout ltltPLAY gotoxy(1412) cout ltltADD QUESTIONS gotoxy(1413) cout ltltEDIT gotoxy(1414) cout ltltQUIT gotoxy(10x) cout ltltchr gotoxy(135) do

7 | P a g e

do do

ch1 = getch() if ( ch1 == 27 )

textmode(C80) clrscr() exit(0) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do ch2 = getch() if ( ch2 == 27 )

textmode(C80) clrscr() exit(0)

while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(10x)

cout ltlt if (n == 4) n = 1

x = x - 3 else n = n + 1

x = x + 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(10x)

cout ltlt if ( n == 1 ) n = 4

x = x + 3 else n = n - 1

8 | P a g e

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 5: Quiz using C++

DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE VERTICAL LINEvoid lines line_ver(int row1 int row2 int column char c) for ( row1 row1lt=row2 row1++ ) gotoxy(columnrow1) cout ltltc CLASS NAME lines FUNCTION NAME box DETAILS IT ACCEPTS THE ROWS AND COLUMNS AND DRAW THE BOXvoid lines box(int column1 int row1 int column2 int row2 char c) char ch=218 char c1 c2 c3 c4 char l1=196 l2=179 if (c == ch) c1 = 218

c2 = 191 c3 = 192 c4 = 217 l1 = 196 l2 = 179

else c1 = c

c2 = c c3 = c c4 = c l1 = c l2 = c

gotoxy(column1row1) cout ltltc1 gotoxy(column2row1) cout ltltc2 gotoxy(column1row2) cout ltltc3 gotoxy(column2row2) cout ltltc4 column1++

5 | P a g e

column2-- line_hor(column1column2row1l1) line_hor(column1column2row2l1) column1-- column2++ row1++ row2-- line_ver(row1row2column1l2) line_ver(row1row2column2l2) CLASS NAME menu FUNCTION NAME start DETAILS IT CREATES THE OPENING SCREENvoid menu start(void) lines line textmode(C80) clrscr() textbackground(LIGHTCYAN) textcolor(BLACK) clrscr() gotoxy(812) cout ltltC O M P U T E R gotoxy(2512) cout ltltQ U I Z linebox(410361421) gotoxy(521) coutltltMADE BY gotoxy(522) coutltltSUSHIL MISHRASACHIN MISHRA(ECE-1) linebox(2194024219) gotoxy(410) getch() textbackground(BLACK) textcolor(LIGHTGRAY) clrscr() CLASS NAME menu FUNCTION NAME main_menu DETAILS IT CREATES THE MAIN MENU TO CONTROL ALL THE FUNCTIONS

6 | P a g e

void menu main_menu(void) lines line textmode(C80) clrscr int valid int n = 4 int x = 14 char ch1 ch2 char chr1=219 chr=175 do linebox (113925219)

lineline_hor(9316196) linebox (833220218) char c1=24 c2=25 gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(135) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(145) cprintf(Q U I Z ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(148) cout ltltOPTIONS gotoxy(149) cout ltlt------- gotoxy(1411) cout ltltPLAY gotoxy(1412) cout ltltADD QUESTIONS gotoxy(1413) cout ltltEDIT gotoxy(1414) cout ltltQUIT gotoxy(10x) cout ltltchr gotoxy(135) do

7 | P a g e

do do

ch1 = getch() if ( ch1 == 27 )

textmode(C80) clrscr() exit(0) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do ch2 = getch() if ( ch2 == 27 )

textmode(C80) clrscr() exit(0)

while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(10x)

cout ltlt if (n == 4) n = 1

x = x - 3 else n = n + 1

x = x + 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(10x)

cout ltlt if ( n == 1 ) n = 4

x = x + 3 else n = n - 1

8 | P a g e

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 6: Quiz using C++

column2-- line_hor(column1column2row1l1) line_hor(column1column2row2l1) column1-- column2++ row1++ row2-- line_ver(row1row2column1l2) line_ver(row1row2column2l2) CLASS NAME menu FUNCTION NAME start DETAILS IT CREATES THE OPENING SCREENvoid menu start(void) lines line textmode(C80) clrscr() textbackground(LIGHTCYAN) textcolor(BLACK) clrscr() gotoxy(812) cout ltltC O M P U T E R gotoxy(2512) cout ltltQ U I Z linebox(410361421) gotoxy(521) coutltltMADE BY gotoxy(522) coutltltSUSHIL MISHRASACHIN MISHRA(ECE-1) linebox(2194024219) gotoxy(410) getch() textbackground(BLACK) textcolor(LIGHTGRAY) clrscr() CLASS NAME menu FUNCTION NAME main_menu DETAILS IT CREATES THE MAIN MENU TO CONTROL ALL THE FUNCTIONS

6 | P a g e

void menu main_menu(void) lines line textmode(C80) clrscr int valid int n = 4 int x = 14 char ch1 ch2 char chr1=219 chr=175 do linebox (113925219)

lineline_hor(9316196) linebox (833220218) char c1=24 c2=25 gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(135) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(145) cprintf(Q U I Z ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(148) cout ltltOPTIONS gotoxy(149) cout ltlt------- gotoxy(1411) cout ltltPLAY gotoxy(1412) cout ltltADD QUESTIONS gotoxy(1413) cout ltltEDIT gotoxy(1414) cout ltltQUIT gotoxy(10x) cout ltltchr gotoxy(135) do

7 | P a g e

do do

ch1 = getch() if ( ch1 == 27 )

textmode(C80) clrscr() exit(0) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do ch2 = getch() if ( ch2 == 27 )

textmode(C80) clrscr() exit(0)

while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(10x)

cout ltlt if (n == 4) n = 1

x = x - 3 else n = n + 1

x = x + 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(10x)

cout ltlt if ( n == 1 ) n = 4

x = x + 3 else n = n - 1

8 | P a g e

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 7: Quiz using C++

void menu main_menu(void) lines line textmode(C80) clrscr int valid int n = 4 int x = 14 char ch1 ch2 char chr1=219 chr=175 do linebox (113925219)

lineline_hor(9316196) linebox (833220218) char c1=24 c2=25 gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(135) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(145) cprintf(Q U I Z ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(148) cout ltltOPTIONS gotoxy(149) cout ltlt------- gotoxy(1411) cout ltltPLAY gotoxy(1412) cout ltltADD QUESTIONS gotoxy(1413) cout ltltEDIT gotoxy(1414) cout ltltQUIT gotoxy(10x) cout ltltchr gotoxy(135) do

7 | P a g e

do do

ch1 = getch() if ( ch1 == 27 )

textmode(C80) clrscr() exit(0) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do ch2 = getch() if ( ch2 == 27 )

textmode(C80) clrscr() exit(0)

while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(10x)

cout ltlt if (n == 4) n = 1

x = x - 3 else n = n + 1

x = x + 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(10x)

cout ltlt if ( n == 1 ) n = 4

x = x + 3 else n = n - 1

8 | P a g e

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 8: Quiz using C++

do do

ch1 = getch() if ( ch1 == 27 )

textmode(C80) clrscr() exit(0) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do ch2 = getch() if ( ch2 == 27 )

textmode(C80) clrscr() exit(0)

while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(10x)

cout ltlt if (n == 4) n = 1

x = x - 3 else n = n + 1

x = x + 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(10x)

cout ltlt if ( n == 1 ) n = 4

x = x + 3 else n = n - 1

8 | P a g e

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 9: Quiz using C++

x = x - 1 gotoxy(10x) cout ltltchr gotoxy(135) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) quiz q

qplay(filename) clrscr()

if (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qadd(filename) textmode(C40) clrscr()

if (n == 3)edit_menu()

while ( n = 4 ) textmode(C80) clrscr() CLASS NAME menu FUNCTION NAME edit_menu DETAILS IT CREATES THE EDIT MAIN MENUvoid menu edit_menu(void) lines line int valid static int n = 3 static int x = 19 char ch1 ch2 char chr1=219 chr=175

9 | P a g e

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 10: Quiz using C++

do linebox(19143120218)

gotoxy(2115) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(2215) cprintf(E D I T ) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(2317) cout ltltDELETE gotoxy(2318) cout ltltMODIFY gotoxy(2319) cout ltltRETURN gotoxy(20x) cout ltltchr gotoxy(2115) do do

do ch1 = getch()

if ( ch1 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() return

while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) gotoxy(115) clreol()

gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol()

10 | P a g e

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 11: Quiz using C++

return while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(20x)

cout ltlt if (n == 3) n = 1

x = x - 2 else n = n + 1

x = x + 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(20x)

cout ltlt if ( n == 1 ) n = 3

x = x + 2 else n = n - 1

x = x - 1 gotoxy(20x) cout ltltchr gotoxy(2115) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) if (n == 1) char filename[13] strcpy(filenamesub_menu())

if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qdeletion(filename)

11 | P a g e

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 12: Quiz using C++

textmode(C40) clrscr()

return clrscr() return

elseif (n == 2) char filename[13]

strcpy(filenamesub_menu()) if (strcmp(filenamenull)) textmode(C80)

clrscr() quiz q qmodify(filename) textmode(C40) clrscr() return

clrscr() return while ( n = 3 )

gotoxy(115) clreol() gotoxy(117) clreol() gotoxy(118) clreol() gotoxy(119) clreol() gotoxy(120) clreol() gotoxy(1914) clreol() CLASS NAME menu FUNCTION NAME sub_menu DETAILS IT CREATES THE SUB MAIN MENU AND RETURN FILE NAMEchar menu sub_menu(void) lines line clrscr() int valid static int n = 1 static int x = 10 char ch1 ch2 char chr1=219 chr=175 linebox(113925219) lineline_hor(23823196) char c1=24 c2=25

12 | P a g e

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 13: Quiz using C++

gotoxy(324) cout ltltc1 cout ltltc2 cout ltlt=Move ltENTERgt=Select ltESCgt=Exit gotoxy(136) cout ltltchr1 textbackground(WHITE) textcolor(BLACK) gotoxy(146) cprintf(S U B - M E N U ) textbackground(BLACK) textcolor(LIGHTGRAY) linebox(115317218) gotoxy(1410) cout ltltCOMPUTERS gotoxy(1412) cout ltltMATHEMATICS gotoxy(1414) cout ltltSCIENCE gotoxy(1416) cout ltltGENERAL gotoxy(1418) cout ltltRETURN gotoxy(12x) cout ltltchr gotoxy(136) do do

do ch1 = getch()

if ( ch1 == 27 ) clrscr()

return(null) while (( ch1 = 0 ) ampamp ( ch1 = 13 )) if ( ch1 = 13 ) do

ch2 = getch() if ( ch2 == 27 ) clrscr()

return(null) while (( ch2 = 72 ) ampamp ( ch2 = 80 ) ampamp ( ch2 = 13 ))

13 | P a g e

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 14: Quiz using C++

while ((( ch1 = 0 ) || (( ch2 = 72 ) ampamp ( ch2 = 80 ))) ampamp (( ch1 = 13 ) ampamp ( ch2 = 13 ))) if (( ch1 == 0 ) ampamp ( ch2 == 80 )) gotoxy(12x)

cout ltlt if (n == 5) n = 1

x = x - 8 else n = n + 1

x = x + 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

if (( ch1 == 0 ) ampamp ( ch2 == 72 )) gotoxy(12x)

cout ltlt if ( n == 1 ) n = 5

x = x + 8 else n = n - 1

x = x - 2 gotoxy(12x) cout ltltchr gotoxy(136) sound(200) delay(30) nosound()

while (( ch1 = 13 ) ampamp ( ch2 = 13 )) clrscr() if (n == 1)

return(computerdat) else if (n == 2)

return(mathsdat) else if (n == 3)

return(sciencedat) else

14 | P a g e

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 15: Quiz using C++

if (n == 4)return(generaldat)

return(null) CLASS NAME quiz FUNCTION NAME record_count DETAILS IT RETURNS THE NO OF RECORD IN THE GIVEN FILEint quiz record_count(char filename[13]) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int t=0 while (fileread((char ) this sizeof(quiz)))

t++ fileclose() return t CLASS NAME quiz FUNCTION NAME add DETAILS IT ADDS THE RECORDS IN THE GIVEN FILEvoid quiz add(char filename[13]) lines line int valid int t_ques_no t_ques_no = record_count(filename) t_ques_no++ if (t_ques_no == 1) ques_no = t_ques_no

strcpy(quesabc) strcpy(ans1-) strcpy(ans2-) strcpy(ans3-) sol = 0 fstream file fileopen(filename iosout | iosapp ) filewrite((char ) this sizeof(quiz)) fileclose() delete_record(filenamet_ques_no)

15 | P a g e

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 16: Quiz using C++

char ch do clrscr()

linebox(117923218) gotoxy(35) cout ltltquestion ltltt_ques_no gotoxy(38) cout ltltquestion gotoxy(310) cout ltltanswer 1 gotoxy(312) cout ltltanswer 2 gotoxy(314) cout ltltanswer 3 gotoxy(316) cout ltltsolution do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER QUESTION gotoxy(148) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt 159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BE BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(148) clreol()

16 | P a g e

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 17: Quiz using C++

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1410) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1410) clreol()

while ( valid ) do

linebox(117923218) valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1412) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49)

17 | P a g e

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 18: Quiz using C++

valid = 0 sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1412) clreol()

while ( valid ) do linebox(117923218)

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1414) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1414) clreol()

while ( valid ) do linebox(117923218)

18 | P a g e

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 19: Quiz using C++

valid = 1 gotoxy(125) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1416) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(1416) clreol()

while ( valid ) gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(319) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4219) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4219) clreol()

while ( valid ) if (ch == Y) ques_no = t_ques_no

fstream file fileopen(filename iosapp ) filewrite((char ) this sizeof(quiz))

19 | P a g e

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 20: Quiz using C++

fileclose() t_ques_no++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(321) cout ltltDo you want to add more questions (yn) do linebox(117923218)

valid = 1 gotoxy(4521) ch = getche() ch = toupper(ch) if (ch == 0)

return if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4521) clreol() while ( valid ) while (ch == Y)

CLASS NAME quiz FUNCTION NAME found_record DETAILS IT SEARCH THE GIVEN RECORDS IN THE GIVEN FILE AND RETURN 0 IF NOT FOUNDint quiz found_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) int found=0 while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

found++ break

fileclose() return found CLASS NAME quiz FUNCTION NAME display_record DETAILS IT DISPLAY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILE

20 | P a g e

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 21: Quiz using C++

void quiz display_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) if (t_ques_no == ques_no)

gotoxy(33) cout ltltquestion ltltt_ques_no gotoxy(37) cout ltltquestion ltltques gotoxy(38) cout ltltanswer 1 ltltans1 gotoxy(39) cout ltltanswer 2 ltltans2 gotoxy(310) cout ltltanswer 3 ltltans3 break

fileclose() CLASS NAME quiz FUNCTION NAME delete_record DETAILS IT DELETE THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz delete_record(char filename[13] int t_ques_no) fstream file fileopen(filename iosin) fstream temp tempopen(tempdat iosout) fileseekg(0iosbeg) while (fileeof()) fileread((char ) this sizeof(quiz))

if ( fileeof() )break

if (ques_no = t_ques_no)tempwrite((char ) this sizeof(quiz))

fileclose() tempclose() fileopen(filename iosout) tempopen(tempdat iosin) tempseekg(0iosbeg)

21 | P a g e

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 22: Quiz using C++

t_ques_no = 1 while (tempeof()) tempread((char ) this sizeof(quiz))

ques_no = t_ques_no if (tempeof())

break filewrite((char ) this sizeof(quiz)) t_ques_no++

fileclose() tempclose() CLASS NAME quiz FUNCTION NAME deletion DETAILS IT GIVE THE QUESTION NO TO DELETE RECORD FROM THE GIVEN FILEvoid quiz deletion(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be deleted do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found

22 | P a g e

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 23: Quiz using C++

lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() linebox(117923218) display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to delete this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N)valid = 0

sound(500) delay(100) nosound() gotoxy(4510) clreol() while (valid )

if (ch == N)return

gotoxy(125) cout ltltWait delete_record(filenamet_ques_no) clrscr() sound(500) delay(100) nosound() gotoxy(314) cout ltltRecord Deleted lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify_record DETAILS IT MODIFY THE RECORD FOR THE GIVEN QUESTION NO FROM THE GIVEN FILEvoid quiz modify_record(char filename[13] int t_ques_no)

23 | P a g e

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 24: Quiz using C++

lines line int valid modified=0 char ch lineline_hor(27812196) linebox(117923218) gotoxy(314) cout ltltQUESTION ltltt_ques_no gotoxy(316) cout ltltQUESTION gotoxy(317) cout ltltANSWER 1 gotoxy(318) cout ltltANSWER 2 gotoxy(319) cout ltltANSWER 3 gotoxy(320) cout ltltSOLUTION gotoxy(125) clreol() lineline_hor(17923196) gotoxy(1416) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2816) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2816) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1416) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325)

24 | P a g e

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 25: Quiz using C++

cout ltltENTER QUESTION gotoxy(1416) gets(ques) strupr(ques) if (ques[0] == 0)

return if (strlen(ques) gt159 || strlen(ques) == 0) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT BLANK OR GREATER THAN 159 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1416) clreol()

gotoxy(125) clreol() gotoxy(1417) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2817) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2817) clreol()

while (valid) valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1317) clreol() gotoxy(7225)

25 | P a g e

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 26: Quiz using C++

cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1417) gets(ans1) strupr(ans1) if (ans1[0] == 0)

return if (strlen(ans1) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1417) clreol()

gotoxy(125) clreol() gotoxy(1418) cout ltltChange (yn) dolinebox(117923218)

valid = 1 gotoxy(2818) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2818) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1 valid = 1 gotoxy(1418) clreol()

26 | P a g e

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 27: Quiz using C++

gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1418) gets(ans2) strupr(ans2) if (ans2[0] == 0)

return if (strlen(ans2) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1418) clreol()

gotoxy(125) clreol() gotoxy(1419) cout ltltChange (yn) do linebox(117923218)

valid = 1 gotoxy(2819) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(2819) clreol() while (valid)

valid = 0 while (valid ampamp ch == Y) linebox(117923218)

modified = 1

27 | P a g e

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 28: Quiz using C++

valid = 1 gotoxy(1419) clreol() gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER ANSWER FOR THE QUESTION gotoxy(1419) gets(ans3) strupr(ans3) if (ans3[0] == 0)

return if (strlen(ans3) gt 49) valid = 0

sound(500) delay(100) nosound() gotoxy(125) clreol() gotoxy(124) cout ltltLENGTH SHOULD NOT GREATER THAN 49 gotoxy(125) cout ltltPress any key to continue getch() gotoxy(124) clreol() gotoxy(125) clreol() gotoxy(1419) clreol()

if (modified)return

do linebox(117923218) gotoxy(125) clreol() valid = 1 gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(325) cout ltltENTER CORRECT SOLUTION FOR THE QUESTION (123) gotoxy(1420) sol = getche() if (sol == 0)

return if (sol = 1 ampamp sol = 2 ampamp sol = 3) valid = 0

sound(500) delay(100)

28 | P a g e

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 29: Quiz using C++

nosound() gotoxy(1420) clreol() while (valid)

gotoxy(125) clreol() gotoxy(124) clreol() gotoxy(122) cout ltltDo you want to save the record (yn) do linebox(117923218)

valid = 1 gotoxy(4122) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500) delay(100) nosound() gotoxy(4122) clreol() while ( valid )

if (ch == N) return

fstream file fileopen(filename iosout | iosate) int recno recno = t_ques_no int location location = (recno-1) sizeof(quiz) fileseekp(location) filewrite((char ) this sizeof(quiz)) fileclose() clrscr() sound(500) delay(100) nosound() gotoxy(114) cout ltltRecord Modified lineline_hor(17924196) gotoxy(125) cout ltltPress any key to continue getch() CLASS NAME quiz FUNCTION NAME modify DETAILS IT GIVE THE QUESTION NO TO MODIFY

29 | P a g e

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 30: Quiz using C++

RECORD FROM THE GIVEN FILEvoid quiz modify(char filename[13]) lines line clrscr() int valid int t_ques_no=0 t char t1_ques_no[5] char ch linebox(117923218) gotoxy(7225) cout ltltlt0gt=EXIT gotoxy(33) cout ltltEnter question no to be modify do gotoxy(383)

gets(t1_ques_no) while (strlen(t1_ques_no) == 0) t = atoi(t1_ques_no) t_ques_no = t if (t1_ques_no[0] == 0)

return if (found_record(filenamet_ques_no)) sound(500)

delay(100) nosound() gotoxy(315) cout ltltquestion not found lineline_hor(27824196) gotoxy(125) cout ltltPress any key to continue getch() return

clrscr() display_record(filenamet_ques_no) gotoxy(312) cout ltltDo you want to modify this Record (yn) do valid = 1

gotoxy(4512) ch = getche() ch = toupper(ch) if (ch = Y ampamp ch = N) valid = 0

sound(500)

30 | P a g e

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 31: Quiz using C++

delay(100) nosound() gotoxy(4510) clreol()

while (valid ) if (ch == N)

return modify_record(filenamet_ques_no) CLASS NAME quiz FUNCTION NAME display_score DETAILS IT DISPLAY THE SCORE FOR THE GIVEN PLAYERS NAMEvoid quiz display_score(char name[20] int played int correct) clrscr() lines line linebox(113925218) linebox(223824219) textbackground(WHITE) textcolor(BLACK+BLINK) gotoxy(54) cprintf( ) gotoxy(94) cprintf(S C O R E B O A R D) textbackground(BLACK) textcolor(LIGHTGRAY) gotoxy(57) cout ltltPlayers Name ltltname gotoxy(59) cout ltltquestions Attempted ltltplayed gotoxy(511) cout ltltCorrect answer ltltcorrect gotoxy(513) cout ltltWrong answer ltltplayed-correct int score score = correct 10 gotoxy(516) cout ltltScore ltltscore int tplayed tplayed = played 10 float percentage percentage = ((score100)tplayed)

31 | P a g e

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 32: Quiz using C++

gotoxy(518) cout ltltPercentage ltltpercentage getch() CLASS NAME quiz FUNCTION NAME play DETAILS IT CREATES SCREEN FOR PLAYING QUIZ TO THE PLAYER FOR THE GIVEN FILE NAME AND KEEP SCOREvoid quiz play(char filename[13]) clrscr() int valid lines line char name[20] gotoxy(33) cout ltltEnter your name do linebox(113925219)

valid = 1 gotoxy(3024) cout ltltlt0gt=EXIT gotoxy(213) gets(name) strupr(name) if (name[0] == 0)

return if (strlen(name) gt 18) valid = 0

sound(500) delay(100) nosound() gotoxy(3024) cout ltlt gotoxy(323) cout ltltLENGTH SHOULD NOT GREATER THAN 18 gotoxy(324) cout ltltPress any key to continue getch() gotoxy(323) cout ltlt gotoxy(324)

32 | P a g e

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 33: Quiz using C++

cout ltlt gotoxy(213)

cout ltlt while ( valid ) char t_sol ch int correct=0 played=0 fstream file fileopen(filenameiosin) fileseekg(0iosbeg) while (fileread((char ) this sizeof(quiz))) clrscr()

linebox(113925219) gotoxy(253) cout ltltSCORE ltltcorrect10 valid = 1 gotoxy(2824) cout ltltltESCgt=Exit gotoxy(34) cout ltltquestion ltltques_no gotoxy(36) cout ltltquestion ltltques gotoxy(310) cout ltltanswer 1 ltltans1 gotoxy(311) cout ltltanswer 2 ltltans2 gotoxy(312) cout ltltanswer 3 ltltans3 gotoxy(314) cout ltltEnter correct solution int i=0 j=0 time=10 do valid = 1

gotoxy(321) cout ltltTime ltlttime gotoxy(2812) do delay(1)

i++ j++ if (j == 600) j = 0

time-- gotoxy(1121) cout ltlt

33 | P a g e

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 34: Quiz using C++

gotoxy(1021) cout ltlttime

gotoxy(2814) while (kbhit() ampamp ilt6000) if (i gt= 6000) played++

sound(500) delay(100) nosound() gotoxy(1316) cout ltltSorry Time up gotoxy(11) getch() if (played)

display_score(nameplayedcorrect) return

gotoxy(321) cout ltlt gotoxy(2812) t_sol = getche() if (t_sol == 27) if (played)

display_score(nameplayedcorrect) return

if (t_sol = 1 ampamp t_sol = 2 ampamp t_sol = 3) valid = 0

sound(500) delay(100) nosound() gotoxy(2812) cout ltlt

while (valid) played++ if (t_sol = sol) sound(500)

delay(100) nosound() gotoxy(1416) cout ltltwrong answer gotoxy(1317) cout ltltCorrect answer ltltsol gotoxy(11)

34 | P a g e

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 35: Quiz using C++

ch = getch() gotoxy(1415)

cout ltlt gotoxy(1316) cout ltlt gotoxy(324) cout ltlt

else correct++

sound(500) delay(100) nosound() gotoxy(1616) cout ltltGOOD CORRECT ANSWER gotoxy(253) cout ltltSCORE ltltcorrect10 gotoxy(11) ch = getch()

if (ch == 27) display_score(nameplayedcorrect)

return gotoxy(322) cout ltltNo more questions available getch() if (played)

return display_score(nameplayedcorrect) FUNCTION NAME main DETAILS IT CALLS THE START FUNCTION AND MENU FUNCTIONvoid main(void) menu m mstart() mmain_menu() END OF PROJECT

35 | P a g e

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 36: Quiz using C++

OUTPUT

36 | P a g e

37 | P a g e

38 | P a g e

39 | P a g e

Page 37: Quiz using C++

37 | P a g e

38 | P a g e

39 | P a g e

Page 38: Quiz using C++

38 | P a g e

39 | P a g e

Page 39: Quiz using C++

39 | P a g e