Program StudentsRecords;
Uses Crt;
Type
ExamRecord = Record
{Stores ID Number of student may begin with 0 so string}
IdNum : String ;
Name : String ; {Store Student Name}
Mod1 : Real ; {Percentage score for module 1 may be decimal}
Mod2 : Real ; {Percentage score for module 2 may be decimal}
Mod3 : Real ; {Percentage score for module 3 May Be Decimal}
Avg : Real ; {Store average of all module marks}
Grade : Char ; {Store grade calculated from Average mark}
Active : boolean ; {Flag for the file to see if active or not}
End; {Record Layout}
Var
StudentFile : File Of ExamRecord;
Student : ExamRecord;
Choice : Char; {Global Variable used in several procedures}
Grade : Char; {Global Variable used in several procedures}
Avg : Real; {Global Variable used in several procedures}
Procedure CreateFile;
Begin
Assign(StudentFile, 'C:\Students'); {Where file is located}
{$I-} {Turn Checking Off}
Reset(StudentFile); {Goto Begining of file}
If IOResult <> 0 Then {If File Not Found}
Begin
ClrScr;
GotoXY(29,12);
WriteLn('Creating File');
Rewrite(StudentFile);{Make the file}
Readkey;
End; {If}
{SI+} {Turn Checking Back On}
End;
Procedure Calculations(M1,M2,M3:Real);
Begin
Avg := (M1+M2+M3)/3;
If Avg < 40 Then
Grade := 'U';
If Avg > 40 Then
Grade := 'E';
If Avg > 50 Then
Grade := 'D';
If Avg > 60 Then
Grade := 'C';
If Avg > 70 then
Grade := 'B';
If Avg > 80 Then
Grade := 'A';
End;{Procedure}
Procedure AddStudents;
Var
Ans : Char; {Local Variable for this procedure}
Begin
Reset(StudentFile); {Goto Begining of file}
ClrScr;
GotoXY(19,12);
WriteLn('Do you wich to add another Student?');
GotoXY(19,13);
Ans := Readkey;
While (Ans = 'Y') or (Ans = 'y') Do
Begin
ClrScr;
Seek(StudentFile, FileSize(StudentFile)); {Goto End Of File}
GotoXY(23,4);
WriteLn('ID Number :');
GotoXY(23,7);
WriteLn('Name :');
GotoXY(23,10);
WriteLn('Module 1 :');
GotoXY(23,13);
WriteLn('Module 2 :');
GotoXY(23,16);
WriteLn('Module 3 :');
GotoXY(36,4);
ReadLn(Student.IdNum);
GotoXY(36,7);
ReadLn(Student.Name);
GotoXY(36,10);
ReadLn(Student.Mod1);
GotoXY(36,13);
ReadLn(Student.Mod2);
GotoXY(36,16);
ReadLn(Student.mod3);
Calculations(Student.Mod1,Student.Mod2,Student.Mod3);
Student.Active := True;
Student.Grade := Grade;
Student.Avg := Avg;
Write(StudentFile, Student);{Save Record}
ClrScr;
GotoXY(19,12);
WriteLn('Do you wish to enter another student''s Record? Y/N');
Ans := Readkey;
End;
End; {Procedure}
Procedure Table;
{Procedure to display the table of data on-screen}
Begin
ClrScr;
GotoXY(3,4);
WriteLn('ID');
GotoXY(8,4);
WriteLn('Name');
GotoXY(22,4);
WriteLn('Mod1');
GotoXY(28,4);
WriteLn('Mod2');
GotoXY(34,4);
WriteLn('Mod3');
GotoXY(40,4);
WriteLn('Average');
GotoXY(49,4);
WriteLn('Grade');
End;{Procedure}
Procedure ViewAStudents;
Var
Loop : Integer ; {Used as a control }
Begin
Reset(StudentFile); {Goto Begining of file}
ClrScr;
Loop:= 1;
Table; {Call Procedure Table}
While Not EOF (StudentFile) Do {While not end of file}
Begin
Read(StudentFile, Student);
If (Student.Active = True) and (Student.Grade = 'A') Then
Begin
GotoXY(3,4+Loop);
WriteLn(Student.IdNum);
GotoXY(8,4+Loop);
WriteLn(Student.Name);
GotoXY(22,4+Loop);
WriteLn(Student.Mod1:3:2);
GotoXY(28,4+Loop);
WriteLn(Student.Mod2:3:2);
GotoXY(34,4+Loop);
WriteLn(Student.Mod3:3:2);
GotoXY(40,4+Loop);
WriteLn(Student.Avg:3:2);
GotoXY(49,4+Loop);
WriteLn(Student.Grade);
Loop:=Loop+1;
Readkey;
End; {If}
End;{While}
End; {Procedure}
Procedure DisplayMenu;
Begin
ClrScr;
GotoXY(24,9);
WriteLn('1. Search By ID Number');
GotoXY(24,10);
WriteLn('2. Display Students With A''s ');
GotoXY(24,11);
WriteLn('3. Exit');
GotoXY(24,13);
WriteLn(' Please Choose From The Above');
End; {Procedure}
Procedure SearchIdNumber;
{A Procedure to search by Id Nunber}
Var
IDNumber : String; {The Number may begin with 0}
Begin
Reset(StudentFile); {Goto Begining of file}
ClrScr;
GotoXY(17,9);
WriteLn('Please Enter The Student Number ');
GotoXY(17,10);
ReadLn(IDNumber);
ClrScr;
Table; {Call Procedure Table}
While Not EOF (StudentFile) Do {While not end of file}
Begin
Read(StudentFile, Student);
If (Student.Active = True) and (Student.IdNum = IdNumber) Then
Begin
GotoXY(3,5);
WriteLn(Student.IdNum);
GotoXY(8,5);
WriteLn(Student.Name);
GotoXY(22,5);
WriteLn(Student.Mod1:3:2);
GotoXY(28,5);
WriteLn(Student.Mod2:3:2);
GotoXY(34,5);
WriteLn(Student.Mod3:3:2);
GotoXY(40,5);
WriteLn(Student.Avg:3:2);
GotoXY(49,5);
WriteLn(Student.Grade);
Readkey;
End; {If}
End;{While}
End; {Procedure}
Begin{Main Program}
ClrScr;
CreateFile;
AddStudents;
Repeat
DisplayMenu;
GotoXY(24,14);
ReadLn(Choice);
Case Choice of
'1' : SearchIdNumber;
'2' : ViewAStudents;
'3' : Begin
ClrScr;
GotoXY(29,12);
WriteLn('GoodBye!!');
End;
End; {Case}
Until Choice = '3';
Readkey;
End.