The manager of a restaurant approached a novice programmer to improve an outdated program used for reservations - NSC Information Technology - Question 5 - 2018 - Paper 2
Question 5
The manager of a restaurant approached a novice programmer to improve an outdated program used for reservations.
5.1 Answer the questions below on general aspects a... show full transcript
Worked Solution & Example Answer:The manager of a restaurant approached a novice programmer to improve an outdated program used for reservations - NSC Information Technology - Question 5 - 2018 - Paper 2
Step 1
5.1.1 State TWO guidelines for writing clear and readable source code.
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
Use descriptive variable names to make the code self-explanatory.
Incorporate comments throughout the code to clarify the purpose of complex sections.
Step 2
5.1.2 Define the concept of an algorithm in programming.
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
An algorithm is a sequence of logical steps or instructions designed to perform a specific task or solve a particular problem efficiently.
Step 3
5.1.3 (a) Explain what is meant by debugging a program.
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
Debugging involves identifying and resolving defects or issues within a program. This process ensures that the software operates correctly by finding bugs or errors and fixing them.
Step 4
5.1.3 (b) What is a runtime error?
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
A runtime error is an error that occurs during the execution of a program, causing it to terminate unexpectedly.
Step 5
5.1.3 (b) (ii) Give an example of a type of error that will lead to a runtime error.
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
An example of a runtime error is division by zero, which occurs when a program attempts to divide a number by zero during execution.
Step 6
5.1.4 Compare the structure and execution of a WHILE…DO loop and a REPEAT…UNTIL loop.
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
In a WHILE…DO loop, the condition is checked before the loop is executed, meaning the statements inside the loop may not run if the condition is false from the beginning. In contrast, a REPEAT…UNTIL loop guarantees that the statements within the loop execute at least once, as the condition is evaluated after the loop's statements.
Step 7
5.1.5 Identify the data types for variables X and Y when executing the following two instructions.
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
For the instruction 'x := 5 mod 2;', X is an integer (as the result of the modulus operation is an integer). For 'y := 5 mod 2 = 0;', Y is a boolean (as it results in true or false).
Step 8
5.2.1 Explain the purpose of the following line of code: AssignFile(tFile, 'Bookings.txt!');
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
This line of code establishes a link between the external text file 'Bookings.txt!' and the program variable tFile, allowing the program to perform file operations on 'Bookings.txt!'.
Step 9
5.2.2 State the effect of replacing Append(tFile) with Rewrite(tFile) in the procedure above.
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
Replacing Append(tFile) with Rewrite(tFile) will empty the existing file 'Bookings.txt!' and create a new file, resulting in the loss of any existing data within that file.
Step 10
5.2.3 Give a possible reason why the I/O error occurred.
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
The I/O error may have occurred because the file 'Bookings.txt!' was not correctly assigned, or it may have been closed beforehand without being reopened.
Step 11
5.3.1 Copy the trace table below into your ANSWER BOOK and complete it to determine the output if 623 is entered as the pin value.
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
Pin
x
c
Is x < 1?
Is c < 5?
Display
623
623
0
False
True
Error in PIN
(Actual calculations should be provided in the trace table as per the instruction.)
Step 12
5.3.2 Analyse the completed trace table and state what the requirement is for the pin to be valid.
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
The requirement for the pin to be valid is that it must contain exactly five digits.
Step 13
5.4 Complete the algorithm from line 3 below to display the pattern based on any input value.
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!