My code works perfectly fine but I was wondering if there was any better ways I could write my code like tidy it up a bit or rewrite a part of it. I want to learn how I can write my code in a better way. The code prompts the user to type the details of 3 different boats and then prints them.
program BoatDetails;
uses TerminalUserInput;
type
Boat = record
ID : integer;
Manufacturer : string;
Model : string;
Registration : string;
end;
Boats = Array of Boat;
function ReadBoat(const prompt : string): Boat;
begin
WriteLn(prompt);
ReadBoat.ID := readInteger('Please enter the Boat ID: ');
ReadBoat.Manufacturer := readString('Please enter the manufacturer of the Boat: ');
ReadBoat.Model := readString('Please enter the model of the Boat: ');
ReadBoat.Registration := readString('Please enter the registration number for the Boat: ');
end;
procedure WriteBoat(b: Boat);
begin
WriteLn('ID - ', b.ID);
WriteLn('Manufacturer - ', b.Manufacturer);
WriteLn('Model - ', b.Model);
WriteLn('Registration - ', b.Registration);
end;
function ReadAllBoats(count: integer): Boats;
var i : integer;
begin
SetLength(result, count);
for i := Low(result) to High(result) do
result[i] := readBoat('Enter Boat details');
end;
procedure WriteAllBoats(BoatArray: Boats);
var i : integer;
begin
for i := Low(BoatArray) to High(BoatArray) do
WriteBoat(BoatArray[i]);
end;
procedure Main();
var Boats: Array of Boat;
index: integer;
begin
Boats := ReadAllBoats(3);
WriteAllBoats(Boats);
end;
begin
Main();
end.