Direct routes:
The GUI allows the user to select the town of departure and the destination town from the combo boxes provided - NSC Information Technology - Question 3 - 2016 - Paper 1
Question 3
Direct routes:
The GUI allows the user to select the town of departure and the destination town from the combo boxes provided.
Use the Q3Data.txt file to determine... show full transcript
Worked Solution & Example Answer:Direct routes:
The GUI allows the user to select the town of departure and the destination town from the combo boxes provided - NSC Information Technology - Question 3 - 2016 - Paper 1
Step 1
Open the text file to read from file
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
Begin by opening the Q3Data.txt file to retrieve data regarding the towns.
Step 2
Set flag to False
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
Initialize a boolean flag to False to track the existence of a direct route.
Step 3
Loop through the file
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
Iterate over each line in the text file, checking if both towns exist in the line.
Step 4
Test if town of departure AND destination has been found
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
If both towns are found but are not the same, set the flag to True.
Step 5
Find position of ‘#’, Find position of ‘*’
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Determine the positions of the '#' and '*' characters in the line to extract distance and mountain pass information.
Step 6
Extract the Distance from the line of text
97%
121 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Use the found positions to extract the distance between the towns.
Step 7
If mountain pass exists (test)
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
Check if the mountain pass information indicates the presence of a pass.
Step 8
Display all information regarding the route
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
If a route exists, display the distance and whether a mountain pass is included or not.
Step 9
If flag is False, Display message 'Not Found'
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
If no route is found by the end of the loop, display a message indicating that no possible route exists.
Step 10
Close File
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Finally, close the text file to free up resources.