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 (or an example of a programming langu... 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 refers to a violation of the programming language's grammatical rules, making the code unexecutable. Examples include missing semicolons or misspelled keywords.
In contrast, a runtime error occurs while the program is running, generally due to unforeseen issues such as dividing by zero or accessing invalid memory, which leads to the program crashing.
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
Provide clear explanations of the error that a layperson can understand to enhance user experience.
Suggest potential remedies or actions the user can take to resolve the issue, guiding them through troubleshooting steps.
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 array must be sorted in ascending or descending order before applying the binary search algorithm.
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
The variable S has not been initialized before it is used in the loop, leading to unpredictable results. Specifically, it may retain a garbage value, resulting in an incorrect final output.
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
Initialize the variable S to 0 before the loop starts to ensure it holds a known value.
Use meaningful variable names for better clarity, for example, rename S to totalSum.
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
The trace table can be completed with the appropriate logical steps based on the flowchart logic provided. Each row should detail the values of f1, f2, i, the conditional status (i < 3), fn, and the Output for each iteration.
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 could be: Inc(I); which increments the value of I by one.
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 denotes public members of the class, while the minus (-) symbol indicates private members.
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 parameter for setLocation() does not specify a data type.
The method getEventDate() should return a TDate type instead of a generic 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
The method toString() is an auxiliary method, typically used to provide a string representation of the class instance.