Question: Language is ADA. --------------------------------------------------------------------------------------------------- The code is an Ada program that has comments that indicate what its functionality should be. Your task is to: Implement
Language is ADA. --------------------------------------------------------------------------------------------------- The code is an Ada program that has comments that indicate what its functionality should be. Your task is to:
Implement the body of GetStudent. Do this by doing some kind of Get/Get_Line for each of the fields of a StudentRecord from the file. Assume the order of the data in the file is id, gpa, name (one student per line).
Implement the body of PutStudent. Do this by Putting each of the fields of the record on a single line in a well organized way.
Finish lines in the main program that output a header for the output.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
with Ada.Text_IO; with Ada.Integer_Text_IO; procedure StudentFileLab is ------------------------------------------------------------------------ --| This program stores records in an array, reading them in from a file --| and writing them out. ------------------------------------------------------------------------ subtype NameType is String(1..30); subtype IDType is natural range 0..9999; subtype GPAType is float range 0.0..4.0; type StudentRecord is record ID : IDType; GPA : GPAType; Name : NameType := (others => ' '); end record; subtype StudentIndex is integer range 1..100; type StudentArrayType is array (StudentIndex) of StudentRecord; -- Specification of input procedure. You are to write the body. Procedure GetStudent (File: in Ada.Text_IO.File_Type; Student : out StudentRecord); -- Specification of output procedure. You are to write the body. Procedure PutStudent (Student : in StudentRecord); StudentList : StudentArrayType; -- our array of students CurrentIndex : Natural := 0; -- the index to the current array item CurrentStudent : StudentRecord; -- the current student Filename : String(1..30); -- name of the data file Flength : Integer; -- length of the name of the data file infile : Ada.Text_IO.File_Type; begin -- StudentLab Ada.Text_IO.Put_Line(Item=>"Welcome to the Student Information Program."); Ada.Text_IO.Put_Line(Item=>"Please enter the student filename: "); Ada.Text_IO.Get_Line(Item=>Filename, Last => Flength); Ada.Text_IO.Open(File=>Infile, Mode=>Ada.Text_IO.In_File, Name=>Filename(1..Flength)); loop -- Get the next student GetStudent(File=> infile, Student => CurrentStudent); exit when CurrentStudent.Id = 0; CurrentIndex := CurrentIndex + 1; StudentList(CurrentIndex) := CurrentStudent; END LOOP; Ada.Text_IO.close(file=>infile); -- close the data file after all data is read. -- Output the header for the nicely formatted output. for Index in 1..CurrentIndex loop PutStudent(Student => StudentList(Index)); end loop; end StudentFileLab;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
