Photo AI

OBJECT-ORIENTATED PROGRAMMING Information on some of the popular hiking trails in South Africa are available in the format of text files - NSC Information Technology - Question 3 - 2021 - Paper 1

Question icon

Question 3

OBJECT-ORIENTATED-PROGRAMMING--Information-on-some-of-the-popular-hiking-trails-in-South-Africa-are-available-in-the-format-of-text-files-NSC Information Technology-Question 3-2021-Paper 1.png

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

Worked Solution & Example Answer:OBJECT-ORIENTATED PROGRAMMING Information on some of the popular hiking trails in South Africa are available in the format of text files - NSC Information Technology - Question 3 - 2021 - Paper 1

Step 1

Button [3.2.2 - Display hiking trail details]

96%

114 rated

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

Button [3.2.3 - Display cost]

99%

104 rated

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;

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;