PROGRAM 3
-- Filename: program2.adb Author: Anthony F. Ortiz WITH Text_IO; USE Text_IO; PROCEDURE Ch2p5 Is -- Program will input information about students -- from ch2p5.txt storing the information in an -- array of variant records. Next names and graduation -- dates from ch2p5.chg are input in order to modify -- the original information. TYPE Classification_Type Is (FRESHMAN, SOPHMORE, JUNIOR, SENIOR); SUBTYPE Name_Type Is String (1..20); SUBTYPE Date_Type Is String (1..6); TYPE Student_Info (classification : Classification_Type := FRESHMAN) Is Record name : Name_Type; sex : Character; Case classification Is When FRESHMAN => date_first_enrolled : Date_Type; When SOPHMORE | JUNIOR => Null; When SENIOR => graduation_date : Date_Type; End Case; End Record; TYPE Student_Array Is Array (1..50) Of Student_Info; PACKAGE Int_IO Is New Integer_IO (Integer); USE Int_IO; classification : Character; count : Integer; date : Date_Type; input_file : File_Type; name : Name_Type; next : Integer; new_name : Name_Type; one_student : Student_Info; sex : Character; student : Student_Array; FUNCTION Search_For_Name (student : Student_Array; new_name : Name_Type; last_person : Integer) Return Integer Is index : Integer; BEGIN index := 0; Loop If index >= last_person Then Return 0; End If; index := index + 1; If student (index).name = new_name Then Return index; End If; End Loop; END Search_For_Name; PROCEDURE List_People (last_person : Integer) Is one_student : Student_Info; BEGIN For count In 1..last_person Loop one_student := student (count); Put (count, 2); Put (" "); Put (one_student.name); Put (" "); Put (one_student.sex); Put (" "); Case one_student.classification Is When FRESHMAN => Put ("1 enrollment date - "); Put_Line (one_student.date_first_enrolled); When SOPHMORE => Put ('2'); New_Line; When JUNIOR => Put ('3'); New_Line; When SENIOR => Put ("4 graduation date - "); Put_Line (one_student.graduation_date); End Case; End Loop; New_Line; END List_People; BEGIN -- Ch2p5 Open (input_file, IN_FILE, "ch2p5.txt"); next := 0; Loop Exit When End_Of_File (input_file); next := next + 1; Get (input_file, name); Get (input_file, sex); Get (input_file, classification); Case classification Is When '1' => Get (input_file, date); one_student := (FRESHMAN, name, sex, date); When '2'=> one_student := (SOPHMORE, name, sex); When '3'=> one_student := (JUNIOR, name, sex); When '4' => Get (input_file, date); one_student := (SENIOR, name, sex, date); When Others => Null; End Case; student (next) := one_student; Skip_Line (input_file); End Loop; Close (input_file); Put_Line ("ORIGINAL LIST OF STUDENTS"); List_People (next); Open (input_file, IN_FILE, "ch2p5.chg"); Loop Exit When End_Of_File (input_file); Get (input_file, new_name); count := Search_For_Name (student, new_name, next); If count /= 0 Then Get (input_file, date); one_student := (SENIOR, new_name, student (count).sex, date); End If; Skip_Line (input_file); End Loop; Close (input_file); Put_Line ("UPDATED LIST OF STUDENTS"); List_People (next); END Ch2p5; -- outfile: ch2p5.txt Marilyn Abbott F1082786 Andy Anderson M2 Barbara Benedict F3 George Fielding M3 Robert Hamilton M3 Jerry Knight M1010786 Philip Taylor M4121586 Charlotte Shapiro F4051587 Veronica Victor F1082886 -- data file: ch2p5.chg Barbara Benedict 121586 George Fielding 121586 Robert Hamilton 121586. -- outfile: prog2.out ORIGINAL LIST OF STUDENTS 1 Marilyn Abbott F 1 enrollment date - 082786 2 Andy Anderson M 2 3 Barbara Benedict F 3 4 George Fielding M 3 5 Robert Hamilton M 3 6 Jerry Knight M 1 enrollment date - 010786 7 Philip Taylor M 4 graduation date - 121586 8 Charlotte Shapiro F 4 graduation date - 051587 9 Veronica Victor F 1 enrollment date - 082886 UPDATED LIST OF STUDENTS 1 Marilyn Abbott F 1 enrollment date - 082786 2 Andy Anderson M 2 3 Barbara Benedict F 3 4 George Fielding M 3 5 Robert Hamilton M 3 6 Jerry Knight M 1 enrollment date - 010786 7 Philip Taylor M 4 graduation date - 121586 8 Charlotte Shapiro F 4 graduation date - 051587 9 Veronica Victor F 1 enrollment date - 082886
BACK TO CS3660 PAGE.