Photo AI
Question 3
OBJECT-ORIENTATED PROGRAMMING Information on some of the popular hiking trails in South Africa are available in the format of text files. The incomplete program pro... show full transcript
Step 1
Answer
To display the hiking trail details, implement the toString
method within the HikingTrail class. This method will format the object's attributes and output them to the redQ3_2
component:
procedure HikingTrail.toString;
begin
redQ3_2.Text := Format('Hiking trail information:%s%sHiking Trail: %s%sDistance: %d km in %d days%sCost: R%.2f',
[LineEnding, LineEnding, TrailName, LineEnding, Distance, NumberOfDays, LineEnding, Cost]);
end;
Step 2
Answer
To calculate the cost based on the number of hikers, utilize the calculateCost
method in conjunction with an input box to get the number of hikers:
var
numberOfHikers: Integer;
begin
numberOfHikers := StrToInt(InputBox('Input', 'Enter number of hikers in group:', ''));
cost := objHikingTrail.calculateCost(numberOfHikers);
ShowMessage(Format('Cost of group is: R%.2f', [cost]));
end;
Report Improved Results
Recommend to friends
Students Supported
Questions answered