Photo AI

Hikers use a distance chart to plan their hiking trips - NSC Information Technology - Question 4 - 2021 - Paper 1

Question icon

Question 4

Hikers-use-a-distance-chart-to-plan-their-hiking-trips-NSC Information Technology-Question 4-2021-Paper 1.png

Hikers use a distance chart to plan their hiking trips. Checkpoints refer to rest areas or overnight locations on a hiking trail. A distance chart consists of the di... show full transcript

Worked Solution & Example Answer:Hikers use a distance chart to plan their hiking trips - NSC Information Technology - Question 4 - 2021 - Paper 1

Step 1

Button - [4.1 – Display distance chart]

96%

114 rated

Answer

To implement the display of the distance chart, follow these steps:

  1. Loop through Checkpoints: Create a loop running from 1 to 5 to iterate through each checkpoint:

    for i := 1 to 5 do
    begin
    
  2. Construct Output String: Initialize an output string that will contain names from arrNames:

    OutputString := '';
    
  3. Nested Loop for Distances: Use a nested loop from 1 to 5 to access the distance:

    for j := 1 to 5 do
    begin
    
  4. Add Checkpoint Names: Append checkpoint names to the output string for each iteration:

    OutputString := OutputString + arrNames[i] + ', ';
    
  5. Display Distances: For each pair of checkpoints, append the corresponding distance from arrDistances:

    OutputString := OutputString + FloatToStr(arrDistances[i][j]) + ', ';
    
  6. Final Formatting: Ensure to format the output string correctly before displaying it:

    OutputString := Trim(OutputString);
    RichEdit1.Lines.Add(OutputString);
    
  7. End of Loops: Close the loops appropriately:

    end;
    end;
    

Step 2

Button - [4.2 – Validation]

99%

104 rated

Answer

For button functionality related to validation, follow these steps:

  1. Loop Through Checkpoints: Start with a loop from 1 to 5 for validating distances:

    for i := 1 to 5 do
    begin
    
  2. Check Valid Distances: Create a nested loop to check if distances are valid:

    for j := 1 to 5 do
    begin
    if (arrDistances[i][j] <> -1) then
    
  3. Build Output String: Build a validation output based on the distances checked:

    ValidationOutput := ValidationOutput + 'Distance from ' + arrNames[i] + ' to ' + arrNames[j] + ' is ' + FloatToStr(arrDistances[i][j]) + ' km.';
    
  4. Display Results: Finally, present the validation results in the GUI:

    RichEdit1.Lines.Add(ValidationOutput);
    
  5. Close Nested Loop: End your nested loop and the main loop correctly:

    end;
    end;
    

Step 3

Button - [4.3 – Route planner]

96%

101 rated

Answer

To implement the route planner functionality, proceed with the following steps:

  1. Extract Selected Route: Retrieve the selected route from the combo box:

    SelectedRoute := ComboBox1.Text;
    
  2. Initialize Distance Variable: Initialize a variable to store total distance:

    TotalDistance := 0;
    
  3. Loop for Route Calculation: Create a loop to parse through each checkpoint combination:

    for i := 1 to length(SelectedRoute) - 1 do
    begin
    
  4. Extract Checkpoints: Extract first and second checkpoints using string manipulation:

    FirstCheckpointIndex := StrToInt(SelectedRoute[i]);
    SecondCheckpointIndex := StrToInt(SelectedRoute[i + 1]);
    
  5. Calculate Distance: Add the distance between these checkpoints to TotalDistance:

    TotalDistance := TotalDistance + arrDistances[FirstCheckpointIndex][SecondCheckpointIndex];
    
  6. Display Distance: Finally, show the total distance to the user:

    ShowMessage('Total Distance: ' + FloatToStr(TotalDistance) + ' km.');
    

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

;