This is, as you could tell, a programming assignment for a class. It's far over due and I'm not getting any points however there is a test coming up soon and I'd rather like to know how to use the specific functions in ADA. The program is different now, when I run it with test put statements in the initial procedure, GetStudent, it will output them fine. However now it goes to the bottom, line 96, and gets an end error
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
USE Ada.Integer_Text_IO;
WITH Ada.Float_Text_IO;
USE Ada.Float_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 File_Type; Student : OUT StudentRecord) is
Length : Integer;
BEGIN
For I In 0..Length Loop
Get(File, Student.ID);
For J In 0..Length Loop
Get(File, Student.GPA);
For K In 0..Length Loop
Get_Line (File, Student.Name, Length);
End Loop;
END LOOP;
End LOOP;
END GetStudent;
PROCEDURE PutStudent (Student : IN StudentRecord) IS
BEGIN
FOR Studentlist IN StudentIndex LOOP
Put (Student.ID,
width => 0);
Put (Item => " ");
Put (Student.GPA,
Exp => 0,
Fore=> 0,
Aft => 0);
Put (Item => ", ");
Put (Student.Name);
New_Line;
END LOOP;
END PutStudent;
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 : File_Type;
begin -- StudentLab
Put_Line(Item=>"Welcome to the Student Information Program.");
Put_Line(Item=>"Please enter the student filename: ");
Get_Line(Item=> Filename, Last => Flength);
Open(File => Infile, Mode => 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;
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;
The Program is supposed to read from a file that looks like this.
1435 3.75 Jane Smith
2233 2.94 Robert Robertson
9634 3.86 Jennie Diver
4325 3.42 Matt Pratt
0
So, Line 96 is literally the end loop line.
FOR Index IN 1..CurrentIndex loop
PutStudent(Student => StudentList(Index));
-----> end loop;
I may be wrong but I feel like my main problem is now with the body of PutStudent seen here:
FOR Studentlist IN StudentIndex LOOP
Put (Student.ID,
width => 0);
Put (Item => " ");
Put (Student.GPA,
Exp => 0,
Fore=> 0,
Aft => 0);
Put (Item => ", ");
Put (Student.Name);
New_Line;
END LOOP;
I feel like it's the for line but I can't tell how to fix it.