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 for reading. Ensure that the file is properly assigned and reset, if necessary.

Step 2

Set flag to False

99%

104 rated

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

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

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

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

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

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

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

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

Answer

Finally, ensure the file is properly closed 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

;