program satscore; uses crt; const maxstudents = 9; var students : array[1..maxstudents] of string[20]; scores : array[1..2,1..maxstudents] of integer; x : integer; { misc int } y : char; { misc char } sat : text; fexist : boolean; procedure input; begin writeln; writeln ('Student number ',x,' :'); write ('Name : '); readln (students[x]); repeat write ('Verbal : '); readln (scores[1,x]); until (scores[1,x] >= 400) and (scores[1,x] <= 800); repeat write ('Math : '); readln (scores[2,x]); until (scores[2,x] >= 400) and (scores[2,x] <= 800); end; procedure output; begin writeln; if students[x] <> '' then begin writeln ('Student number ',x,' :'); writeln ('Name : ',students[x]); writeln ('Verbal : ',scores[1,x]); writeln ('Math : ',scores[2,x]); end else writeln ('Student number ',x,' : Empty'); if wherey > 20 then begin writeln; write('Please press any key'); y := readkey; clrscr; end; end; procedure slots_full; var m:integer; begin x := 0; for m := 1 to maxstudents do if students[m] <> '' then x := x + 1; end; procedure convert; begin case y of '1' : x := 1; '2' : x := 2; '3' : x := 3; '4' : x := 4; '5' : x := 5; '6' : x := 6; '7' : x := 7; '8' : x := 8; '9' : x := 9; '0' : x := 0; else y := #1; end; end; procedure FileExists(filename: string); begin {$I-} Assign(sat, filename); Reset(sat); Close(sat); {$I+} fexist := (IOResult = 0) and (filename <> ''); end; begin fexist := false; for x := 1 to maxstudents do students[x] := ''; repeat slots_full; clrscr; gotoxy (36,2); textcolor (green); write ('MAIN MENU'); gotoxy (29,4); textcolor (blue); write ( x,' out of ',maxstudents,' data slots full'); gotoxy (25,5); textcolor (9); write ('[A]dd a student'); gotoxy (25,6); write ('[C]hange an existing student''s info'); gotoxy (25,7); write ('[D]elete an existing student'); gotoxy (25,8); write ('Delete all [E]xisting students'); gotoxy (25,9); write ('View [O]ne student'); gotoxy (25,10); write ('[V]iew all students'); gotoxy (25,11); write ('[S]ave current data'); gotoxy (25,12); write ('[L]oad data from a previous session'); gotoxy (25,13); write ('or [Q]uit?'); gotoxy (29,16); write ('Please enter a letter : '); textcolor (7); repeat y := upcase(readkey); until (y = 'A') or (y = 'C') or (y = 'D') or (y = 'E') or (y = 'O') or (y = 'V') or (y = 'S') or (y = 'L') or (y = 'Q'); clrscr; writeln; writeln; case y of 'A' : begin x := 0; repeat x := x + 1; until (students[x] = '') or (x = maxstudents + 1); if x <> maxstudents + 1 then begin input; end else begin writeln ('You don''t have any more data slots left'); y := readkey; end; end; 'C' : begin write ('Which student''s information do you want to change?'); repeat y := readkey; convert; until y <> #1; writeln; writeln; if students[x] <> '' then begin writeln; writeln ('Old data :'); output; writeln; writeln ('New data :'); input; end else begin writeln ('You don''t currently have data for that student number. To add a new student,'); writeln ('press ''A'' at the main menu.'); y := readkey; end; end; 'D' : begin write ('Which number data slot do you want to delete?'); repeat y := readkey; convert; until y <> #1; writeln; writeln; if students[x] <> '' then begin students[x] := ''; writeln ('Data slot ',x,' erased'); end else writeln ('That slot is already empty'); y := readkey; end; 'E' : begin writeln ('Are you sure you want to delete all of your data?'); write ('(Y or N)'); repeat y := upcase(readkey); until (y = 'Y') or (y = 'N'); if y = 'Y' then begin for x := 1 to maxstudents do students[x] := ''; writeln; writeln; writeln ('Data Erased'); y := readkey; end; end; 'O' : begin write ('What is the number of the student you want to look at?'); repeat y := readkey; convert; until y <> #1; writeln; writeln; output; if wherey <= 20 then y := readkey; end; 'V' : begin clrscr; for x := 1 to maxstudents do output; if wherey <= 20 then y := readkey; end; 'S' : begin writeln ('Do you want to save the data that you have been working on?'); write ('(Y or N)'); repeat y := upcase(readkey); until (y = 'Y') or (y = 'N'); if y = 'Y' then begin rewrite(sat); for x := 1 to maxstudents do begin writeln(sat,students[x]); writeln(sat,scores[1,x]); writeln(sat,scores[2,x]); end; close(sat); writeln; writeln; writeln ('Data Saved'); fexist := true; y := readkey; end; end; 'L' : begin fileexists('data.$$$'); if fexist then begin writeln ('Do you want to load your saved data?'); writeln ('It will overwrite any data you have loaded right now.'); write ('(Y or N)'); repeat y := upcase(readkey); until (y = 'Y') or (y = 'N'); if y = 'Y' then begin reset(sat); for x := 1 to maxstudents do begin readln(sat,students[x]); readln(sat,scores[1,x]); readln(sat,scores[2,x]); end; close(sat); writeln; writeln; writeln ('Data Loaded'); y := readkey; end; end else begin writeln ('You do not have any saved data to load'); y := readkey; end; end; end; until (y = 'Q'); clrscr; end.