5.1 Differentiate between a syntax error and a runtime error - NSC Information Technology - Question 5 - 2020 - Paper 2
Question 5
5.1 Differentiate between a syntax error and a runtime error.
A syntax error occurs when the rules of the programming language are violated, or an example of a prog... show full transcript
Worked Solution & Example Answer:5.1 Differentiate between a syntax error and a runtime error - NSC Information Technology - Question 5 - 2020 - Paper 2
Step 1
5.1.1 Differentiate between a syntax error and a runtime error.
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
A syntax error occurs when the program code violates the rules of the programming language, preventing it from compiling or running. For example, forgetting a semicolon can lead to a syntax error. In contrast, a runtime error occurs during program execution when the program encounters a problem, such as division by zero or an attempt to access a null reference, causing it to crash.
Step 2
5.1.2 Give TWO guidelines on how a programmer can construct useful error messages.
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
Explain in Understandable Terms: Error messages should be clear and convey the issue in terms users can understand, avoiding technical jargon.
Indication of the Source: Include indications on whether the error stems from the software or hardware, helping users identify the root cause of the problem.
Step 3
5.2 What is the prerequisite for an array to be searched when using the binary search algorithm?
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
The prerequisite for an array to be searched using the binary search algorithm is that the array must be sorted. Only sorted arrays guarantee that the binary search can efficiently find an element.
Step 4
5.3.1 Give a possible reason for this unexpected result.
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 likely reason for the unexpected result is that Variable S is not initialized before use. In many programming languages, if a variable is not initialized, it may contain a garbage value that leads to incorrect calculations.
Step 5
5.3.2 Suggest TWO ways in which to improve the code of the novice programmer to be more readable.
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
Indentation: Properly indent the code to visually separate blocks, making it easier to follow the program logic.
Descriptive Variable Names: Use more descriptive names for variables, such as replacing S with sum, to clarify their purpose within the code.
Step 6
5.4 Redraw the following incomplete trace table into your ANSWER BOOK.
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
Refer to the flowchart provided and create the trace table based on the flow of the graph. Track values of f1, f2, and i through each step until the output is generated.
Step 7
5.5 Write an alternative line of Delphi code that will have the same effect as the following line of code: I := I + 1;
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
An alternative line of code that achieves the same effect is: Inc(I);
Step 8
5.6.1 What do the plus (+) and minus (-) symbols represent respectively?
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
The plus (+) symbol indicates public members, methods, or attributes that are accessible outside the class, whereas the minus (-) symbol indicates private members, methods, or attributes that are restricted to the class itself.
Step 9
5.6.2 Identify TWO errors in the class diagram provided.
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
The setLocation() method's parameter does not specify a data type.
The getCapacity() method should return an integer data type.
Step 10
5.6.3 Identify an auxiliary method in the class diagram provided.
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
An auxiliary method in the class diagram is: toString().