program quiz_program; uses crt; const Country: array[1..68] of string[26] = ('Brasil','Argentina','Bolivia','China', 'Germany','Hungary','Israel','Italy','Japan','Kuwait','Costa Rica','Peru', 'Portugal','Spain','Turkey','Belgium','Denmark','Norway','Sweden','Austria', 'Bulgaria','Finland','Greece','Poland','Switzerland','Australia','Canada', 'New Zealand','Egypt','Iran','El Savlador','Iraq','Lebanon','South Africa', 'South Korea','Albania','Chile','Cuba','Malta','Oman','Seychelles','Sri Lanka', 'Togo','Vietnam','Afghanistan','Burma','Scotland','England','Wales', 'Northern Ireland','Republic of Ireland','United States of a America', 'France','Holland','Romania','Russia','Mexico','Algeria','Fiji','Singapore', 'Iceland','India','Indonesia','Jamaica','Panama','Thailand','Tunisia', 'Jordon'); Capital: array[1..68] of string[12] = ('Brasilia','Buenos Aires','La Paz','Peking', 'Berlin','Budapest','Jerusalem','Rome','Tokyo','Kuwait','San Jos‚','Lima', 'Lisbon','Madrid','Ankara','Brussels','Copenhagen','Olso','Stockholm','Vienna', 'Sofia','Helsinki','Athens','Warsaw','Berne','Canberra','Ottawa','Wellington', 'Cairo','Teheran','San Salvador','Baghdad','Beirut','Pretoria','Seoul', 'Tirane','Santiago','Havana','Valletta','Muscat','Victoria','Colombo', 'Lome','Hanoi','Kabul','Rangoon','Edinburgh','London','Cardiff','Belfast', 'Dublin','Washington','Paris','Amsterdam','Bucharest','Moscow','Mexico City', 'Algiers','Suva','Singapore','Reykjavik','New Delhi','Jakarta','Kingston', 'Panama','Bangkok','Tunis','Amman'); TermsQ: array[1..30] of string[5] = ('PC','RAM','ROM','CPU','DOS', 'GUI','VDU','IBM','DTP','CAD','HTML','SVGA','ISP','GIF','UMB', 'TSR','XMS','GIGO','BIOS','HMA','DLL','PCI','IDE','DDE','SCSI', 'FAT','OLE','SIMM','MODEM','ISA'); TermsA: array[1..30] of string[33] = ('Personal Computer', 'Random Access Memory','Read Only Memory','Central Processing Unit', 'Disk Operating System','Graphical User Interface', 'Visual Display Unit','International Business Machines', 'Desk Top Publishing','Computer Aided Design', 'Hypertext Markup Language','Super Video Graphics Array', 'Internet Service Provider','Graphics Interchange Format', 'Upper Memory Block','Terminate Stay Resident', 'Extended Memory','Garbage In Garbage Out', 'Basic Input Output System','High Memory Area', 'Dynamic Link Library','Peripheral Component Interconnect', 'Integrated Drive Electronics','Dynamic Data Exchange', 'Small Computer System Interface','File Allocation Table', 'Object Linking And Embedding','Single Inline Memory Module', 'Modulator Demodulator','Industry Standard Architecture'); type pos_type = array[1..68] of boolean; temp_type = array[1..68] of integer; procedure readxy(var reply : string; row,colour : integer); procedure centre_line(reply : string; row : integer; letter : char); var column : integer; begin window(1,row,80,row); clrscr; window(1,1,80,25); column := 40-(length(reply) div 2); if (not odd(length(reply))) and (letter=#13) then column := column + 1; gotoxy(column,row); write(reply); end; var letter : char; count : integer; len : integer; begin count := 1; reply := ''; textcolor(colour); repeat letter := readkey; if letter=#8 then begin count := count - 1; if count < 1 then count := 1; write(chr(8),' ',chr(8)); delete(reply,count,1); centre_line(reply,row,letter); end else begin count := count + 1; reply := reply + letter; centre_line(reply,row,letter); end; until letter=#13; len := length(reply); delete(reply,len,2); end; function uppercase(txt1 : string) : string; var a : byte; begin for a := 1 to length(txt1) do txt1[a] := upcase(txt1[a]); uppercase := txt1; end; procedure writexy(text1,text2,text3 : string; row,colour : integer); var len,column : integer; tempstr : string; begin tempstr := text1+text2+text3; len := length(tempstr); column := 40-(len div 2); gotoxy(column,row); textcolor(colour); write(tempstr); gotoxy(1,25); end; procedure display_menu(var option : integer; var row : integer); var pause : char; begin repeat clrscr; writexy('Select the quiz you want to play','','',10,6); writexy('Capital Cities','','',12,4); writexy('Computer Terms','','',13,4); writexy('Maths Quiz','','',14,4); writexy('Exit','','',15,4); textcolor(6); gotoxy(30,row); writeln(chr(175)); gotoxy(49,row); writeln(chr(174)); gotoxy(1,25); pause := readkey; case pause of #72 : row := row - 1; #80 : row := row + 1; end; if row < 12 then row := 12; if row > 15 then row := 15; until pause = #13; option := row; clrscr; end; procedure random_numbers(var rnd : integer; var pos : pos_type; max : integer); var ok : boolean; begin ok := false; randomize; repeat rnd := random(max)+1; if pos[rnd] = false then begin ok := true; pos[rnd] := true; end else ok := false until ok; end; procedure ask_capital(var score : integer; pos : pos_type; var temp : temp_type); var answer : string; loop,rnd : integer; pause : char; begin for loop := 1 to 10 do begin random_numbers(rnd,pos,68); temp[rnd] := temp[rnd] + 1; clrscr; writexy('What is the capital of ',country[rnd],'',10,6); readxy(answer,11,3); if answer = 'x' then break; if uppercase(answer) = uppercase(capital[rnd]) then begin inc(score); writexy('Correct answer','','',13,2); pause := readkey; end else begin writexy('Wrong answer','','',13,2); writexy('The correct answer is ',capital[rnd],'',14,4); pause := readkey; end; end; end; procedure ask_terms(var score : integer; pos : pos_type); var answer : string; loop,rnd : integer; pause : char; begin for loop := 1 to 10 do begin random_numbers(rnd,pos,30); clrscr; writexy('What does ',termsQ[rnd],' stand for',10,6); readxy(answer,11,3); if answer = 'x' then break; if uppercase(answer) = uppercase(termsA[rnd]) then begin inc(score); writexy('Correct answer','','',13,2); pause := readkey; end else begin writexy('Wrong answer','','',13,2); writexy('The correct answer is ',termsA[rnd],'',14,4); pause := readkey; end; end; end; procedure ask_sum(var score : integer); var num1,num2 : integer; reply : string; answer : string; loop : integer; pause : char; begin randomize; for loop := 1 to 10 do begin clrscr; repeat num1 := random(20)+1; num2 := random(20)+1; until (num1>=5) and (num2>=5); gotoxy(32,10); textcolor(6); writeln('What is ',num1,' x ',num2); gotoxy(1,25); readxy(reply,11,3); str(num1*num2,answer); if reply = 'x' then break; if reply = answer then begin inc(score); writexy('Correct answer','','',13,2); pause := readkey; end else begin writexy('Wrong answer','','',13,2); writexy('The correct answer is ',answer,'',14,4); pause := readkey; end; end; end; procedure display_results(score : integer; var temp : temp_type); var rating,tempstr : string; pause : char; begin clrscr; str(score,tempstr); writexy('You scored ',tempstr,' out of 10',10,6); case score of 0..3 : rating := 'Poor '; 4..6 : rating := 'Average'; 7..8 : rating := 'Very Good'; 9..10 : rating := 'Excellent'; end; writexy('Rating = ',rating,'',11,2); writexy('Press the space bar to continue','','',13,4); repeat pause := readkey; until pause = #32; end; { Start of main program } var pos : pos_type; score : integer; option : integer; row : integer; temp : temp_type; begin textmode(80); row := 12; while option <> 15 do begin score := 0; display_menu(option,row); case option of 12 : ask_capital(score,pos,temp); 13 : ask_terms(score,pos); 14 : ask_sum(score); end; if option <> 15 then display_results(score,temp); end; textcolor(7); clrscr; end. { End of main program }