5.1 Procedures and functions are used to enhance modularity in programs - NSC Information Technology - Question 5 - 2017 - Paper 2
Question 5
5.1 Procedures and functions are used to enhance modularity in programs.
5.1.1 State TWO advantages of modular programming.
5.1.2 Distinguish between a private fun... show full transcript
Worked Solution & Example Answer:5.1 Procedures and functions are used to enhance modularity in programs - NSC Information Technology - Question 5 - 2017 - Paper 2
Step 1
5.1.1 State TWO advantages of modular programming.
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
Easier to debug/fever bugs: Modular programming divides a program into modules, making it easier to isolate issues and debug them.
Reuse of code/Avoids duplication of code: Functions and procedures can be reused across different parts of a program or in different programs, which promotes efficiency.
Step 2
5.1.2 Distinguish between a private function and a public function.
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
A private function is only accessible within the class or unit where it is defined, whereas a public function can be accessed from outside the class or project that defines it.
Step 3
5.2.1 bAnswer := y = z;
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 expression evaluates to True because both y and z have the value 4. Thus, bAnswer will be set to True.
Step 4
5.2.2 If (NOT (x)) AND (y <> 4) then bAnswer := true; else bAnswer := false;
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
In this case, since x is false, NOT (x) evaluates to True. However, since y equals 4, (y <> 4) evaluates to False. Therefore, bAnswer will be set to False.
Step 5
5.3 Complete the missing block of the pseudocode.
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
To check if a word is a palindrome, you can follow these steps:
reverseWord <- empty string
for loop from length of word down to 1 do
reverseWord <- reverseWord + word[loop]
if word = reverseWord then
Output 'Word is a palindrome'
else
Output 'Word is NOT a palindrome'
Step 6
5.4.1 The values in the array must be added.
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
To sum the values in the left diagonal area, the algorithm could be structured as follows:
iSum := 0;
iRows := 5;
for r := 1 to iRows do
iSum := iSum + arrLightBulbs[r, r];
Step 7
5.4.2 Indicate the type of error for each statement.
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: Incorrect array index format.
(b) Logical Error: The statement is missing a closing bracket for the assignment.
(c) Syntax Error: Index out of bounds for the defined array.
Step 8
5.4.3 Distinguish between the Reset statement and the Rewrite statement.
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 Reset statement opens an existing text file for reading and moves the file pointer to the first record, allowing you to read from it.
The Rewrite statement creates a new text file and clears the contents of an existing file if it already exists, allowing you to write new data.
Step 9
5.5.1(a) Identify and explain the error.
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 error in this statement is that objSchool.create('MySchool',500); incorrectly implies instantiation instead of calling a constructor directly. An object cannot create or instantiate itself; it needs to be initialized with the new keyword.
Step 10
5.5.1(b) Identify and explain the 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
This statement is incorrect due to an improper order of arguments, as the first argument should match the class type for instantiation.
Step 11
5.5.1(c) Identify and explain the 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
Here, there is a data type mismatch error; the second parameter must be an integer, whereas a string is provided.
Step 12
5.5.2(a) Change the number of learners from 1150 to 1200.
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
This task should use a Mutator method which changes the value of the NumberLearners attribute in the TSchool class.
Step 13
5.5.2(b) Calculate the ratio of the number of learners per teacher.
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
This task requires an Accessor method to retrieve the values necessary for calculating the ratio from the TSchool class.