Hikers use a distance chart to plan their hiking trips - NSC Information Technology - Question 4 - 2021 - Paper 1
Question 4
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To display the distance chart, we need to loop through the array of checkpoints and create a formatted string that contains both the names and the corresponding distances.
Loop through checkpoints:
Use a loop that iterates from 1 to 5 for the rows.
Within that loop, initiate another loop that also goes from 1 to 5 for the columns.
Build the output string:
For each checkpoint, append its name using arrNames[i] to the output string.
Test the distance using arrDistances[i][j], ensuring you cross-check each distance.
Display the output:
Finally, output the complete string in a rich edit component.
Step 2
Button - [4.2 – Validation]
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The validation step involves checking the distances and ensuring they are accurately represented within the provided limits.
Loop through the arrays:
Use a loop structure from 1 to 5 to iterate through both rows and columns.
Test the distances:
For each index, check if the distance at arrDistances[i][j] is not equal to arrDistances[j][i] and build the output string accordingly.
Include conditions to validate if distances are logical/equal.
Display the output string:
Once the loop completes, display the resultant output string.
Step 3
Button - [4.3 – Route planner]
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The route planner will involve extracting and calculating route distances based on user input.
Extract the route from the combo box:
Obtain the user's selected route and initialize a variable for total distance.
Loop through combinations:
Create nested loops to generate all possible combinations of checkpoints, allowing dynamic route setup.
Calculate distances:
Use previous distance functions to compute and sum distances between the selected checkpoints, displaying calculations in real-time.
Display summary:
Finally, retrieve and display total distances and checkpoint information through the GUI.