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

To start, we need to open the Q3Data.txt file which contains the data about the towns and routes.

Step 2

Set flag to False

99%

104 rated

Answer

Initialize a boolean flag to False. This will be used to determine if a direct route exists.

Step 3

Loop through the file

96%

101 rated

Answer

Iterate through each line in 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

Answer

Check if both the town of departure and destination are present in the current line of text, ensuring they are not the same.

Step 5

Find position of ‘#’, Find position of ‘*’

97%

117 rated

Answer

Locate the positions of the special characters '#' and '*' in the line to extract relevant information.

Step 6

Extract the Distance from the line of text

97%

121 rated

Answer

Using the positions found, extract the distance between the two towns.

Step 7

Test if mountain pass exists

96%

114 rated

Answer

Check if the text indicates a mountain pass. If it does, display a message indicating so.

Step 8

Display all information regarding the route

99%

104 rated

Answer

If a direct route exists, output the distance and whether there is a mountain pass. If not, set the flag to False and prepare a message.

Step 9

If flag is False, Display message 'Not Found'

96%

101 rated

Answer

If no valid route is found after checking all entries, display a message stating that no possible route exists.

Step 10

Close File

98%

120 rated

Answer

Finally, make sure to properly close the file after reading to prevent memory leaks.

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

;