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
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 allows for easier troubleshooting as each module can be tested individually.
Reuse of code/Avoids duplication of code: Once a module is created, it can be reused in different programs, saving time and preventing errors from duplicated code.
Step 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 accessible only within the class or unit in which it is declared, while a public function can be accessed from outside the class or project it belongs to.
Step 3
Determine the result of the Boolean variable, bAnswer, in EACH of the following statements:
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
5.2.1 bAnswer := y = z;
The value of bAnswer will be True because both y and z have been initialized with the value of 4.
5.2.2 If (NOT (x)) AND (y <> 4) then
bAnswer will be False because y equals 4, making the condition y <> 4 false.
Step 4
Complete the missing block of the pseudocode to construct the word that was entered in reverse format.
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
To reverse the string, you can use the following pseudocode:
reverseWord ⇐ ''
for loop from 1 to length of word do
reverseWord ⇐ word[loop] + reverseWord
end for
This will construct reverseWord by adding characters from word in reverse order.
Step 5
The values in the array indicated in the diagram (left diagonal area) must be added to find a total 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
To achieve a total using a single loop:
iSum := 0;
iRows := 5;
for r := 1 to iRows do
iSum := iSum + arrLightBulbs[r, r];
end for;
This uses only one loop to go through each index where row equals column.
Step 6
Indicate in EACH case the type of error (syntax/runtime/logical) that occurred as a result of the incorrect statement.
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
(a) arrLightBulbs[5, 3] := 7;
Type of Error: Syntax error - as index 5 is out of bounds in a 5x5 array.
(b) arrLightBulbs[2, 2, 4] := 1;
Type of Error: Syntax error - the array only takes two indices.
(c)Type of Error: Logical error - the statement is vague and does not specify how to save data.
Step 7
Identify AND briefly explain the error in 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) objSchool.create('MySchool',500);
Error: This statement will throw an error because it is attempting to call a method, but the object must be instantiated first.
(b) objSchool := TSchool.create(80,'MySchool');
Error: The argument types do not match; the first argument is expected to be a String, but an Integer was passed instead.
(c) objSchool := TSchool.create('MySchool',745);
Error: This will not produce an error if there is a proper constructor, but if there's a type mismatch, that would be the issue.
Step 8
Choose the appropriate method type to perform EACH of the following tasks:
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) Change the number of learners from 1150 to 1200.
Method Type: Mutator - as it modifies the state of the object.
(b) Calculate the ratio of the number of learners per teacher.
Method Type: Accessor - as it retrieves data without modifying the object.