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/fore bugs: Modular programming allows developers to isolate and correct issues in individual modules without affecting the entire program.
Reuse of code: Modules can be reused in different programs or parts of the same program, promoting efficiency and reducing duplication.
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
Private Function: Accessible only within the class or unit it is defined in, providing encapsulation.
Public Function: Accessible from outside the class, allowing for interaction with other parts of the program.
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
Since both y and z are initialized to 4, the expression evaluates to True. Therefore, bAnswer will be 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, x is false, so NOT (x) is True. However, since y is 4, y <> 4 evaluates to False. The combined condition becomes True AND False, which is 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 complete the pseudocode, we need to reverse the input word. Conditionally check against the reversed word for both equality and palindrome status:
reverseWord ⇐ ''
for loop from length of word down to 1
reverseWord ⇐ reverseWord + word[loop]
end for
If word = reverseWord then
Output 'Word is a palindrome'
else
Output 'Word is NOT a palindrome'
This will correctly determine if the provided word is a palindrome.
Step 6
5.4.1 The values in the array indicated in the diagram...
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 calculate the total value of the left diagonal area, we can implement the following single-loop approach:
// Initialize total sum
iSum := 0;
// Loop through indices of the array
for r := 1 to 5 do
iSum := iSum + arrLightBulbs[r, r];
end for;
This will add all the arrays in the left diagonal only.
Step 7
5.4.2(a) arrLightBulbs[5, 3] := 7;
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
Type of Error: Syntax Error. This is because the index exceeds the declared size of the array which is only 5x5.
Step 8
5.4.2(b) arrLightBulbs[2, 2, 4] := 9;
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
Type of Error: Syntax Error. The array is declared with only two dimensions and accessing three indices is invalid.
Step 9
5.4.2(c) Code must be added to save the data in a text file.
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
Type of Error: Logical Error. The code needs to implement file handling to achieve data persistence, which is not being done here.
Step 10
5.5.1(a) objSchool.create('MySchool',500);
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
Error: Object cannot instantiate itself. The object creation command is incorrect since it must assign the result of the constructor to a variable.
Sign up now to view full answer, or log in if you already have an account!
Answer
Error: Incorrect order of arguments/parameters. The data types passed do not align with the class definition, which expects a String for SchoolName and an Integer for Learners.
Sign up now to view full answer, or log in if you already have an account!
Answer
Error: Data type type mismatch. Using a string instead of an integer for the number of learners violates the type requirement established in the class declaration.
Step 13
5.5.2(a) Change 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
Method Type: Mutator. This method will modify the existing data in the class.
Step 14
5.5.2(b) Calculate the ratio of the number of learners per teacher.
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
Method Type: Accessor. This method retrieves and calculates information without modifying the state of the class.