Photo AI

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 icon

Question 3

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.png

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

Answer

Begin by opening the Q3Data.txt file to retrieve data regarding the towns.

Step 2

Set flag to False

99%

104 rated

Answer

Initialize a boolean flag to False to track the existence of a direct route.

Step 3

Loop through the file

96%

101 rated

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

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

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

Answer

Use the found positions to extract the distance between the towns.

Step 7

If mountain pass exists (test)

96%

114 rated

Answer

Check if the mountain pass information indicates the presence of a pass.

Step 8

Display all information regarding the route

99%

104 rated

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

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

Answer

Finally, close the text file to free up resources.

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

;