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 for reading. Ensure that the file is properly assigned and reset, if necessary.
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 flag variable and set it to False. This will be used to track whether a direct route is found.
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 through each line of the file to check for the presence of the towns.
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
Within the loop, check if both the town of departure and the destination town are found in the line of text. Ensure they are not the same town.
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
If both towns are found, locate the positions of the '#' and '*' characters in the line. These will help extract the 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
Using the positions found, extract the distance between the two towns from the line of text.
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
Determine if a mountain pass exists based on the data extracted. If it does, display a 'Pass on route' message; otherwise, display a 'No pass' message.
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 is found (i.e., flag is True), display the distance and whether there is a mountain pass.
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 the flag remains False after looping through the file, display a message indicating that no possible route was found.
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, ensure the file is properly closed to free up resources.