I have an assignment where I do not know the number of entries there will be prior to getting them from a user. In this assignment, I am to use unbounded arrays. Once the user states this maximum number, it will be used as the upper bound of the array, and there will be three of these declarations. Then, I need to accept the value to fill each of tose arrays that will be held in a record, which will be held in another array. Then, once populated, The array needs to be passed to another procedure to then output to screen.
I have put together a demo of what needs to happen. This is not the assignment, but just a rough idea/pseudo of one small spart of the larger assignment. I am right away running into the problem of using an unconstrained array in a record.
WITH Ada.Text_IO; USE Ada.Text_IO;
WITH Ada.Integer_Text_Io; USE Ada.Integer_Text_Io;
PROCEDURE Vehicles IS
TYPE Year_Array IS ARRAY (Positive RANGE <>) OF Integer;
TYPE Vehicle_Record IS
RECORD
Name: String (1 .. 40);
Cars_Array : Year_Array;
Trucks_Array: Year_Array;
Bikes_Array : Year_Array;
END RECORD;
TYPE O_Array IS ARRAY (1 .. 4) OF Vehicle_Record;
PROCEDURE Get_No_Vehicles (Cars, Trucks, Bikes : OUT Positive) IS
BEGIN
Put("Total number of cars:");
Get(Cars);
Put("Total number of trucks:");
Get(Trucks);
Put("Total number of bikes:");
Get(Bikes);
END Get_No_Vehicles;
Owner : O_Array;
Cars, Trucks, Bikes : Positive;
BEGIN
Get_No_Vehicles(Cars, Trucks, Bikes);
-- Call a procedure that will get the the owner name and the year of each vehicle for all 4 owners.
-- Call a procedure that will pull the records from the owner array and output to screen.
END Vehicles;
Does anyone have a suggestion on how to make this work? I thought about creating the record in a declare block, but it will go out of scope when I before I can pass it to the procedure that will output the entire array.I am not sure how to proceed. Thanks for taking the time to look.