5.1 An algorithm is a step by step breakdown to solving a problem - NSC Information Technology - Question 5 - 2021 - Paper 2
Question 5
5.1 An algorithm is a step by step breakdown to solving a problem.
5.1.1 Name ONE technique/tool/diagram that can be used to represent an algorithm.
5.1.2 Give ONE r... show full transcript
Worked Solution & Example Answer:5.1 An algorithm is a step by step breakdown to solving a problem - NSC Information Technology - Question 5 - 2021 - Paper 2
Step 1
5.1.1 Name ONE technique/tool/diagram that can be used to represent an algorithm.
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
One technique that can be used to represent an algorithm is a flowchart. Flowcharts visually represent the steps of an algorithm using various symbols, making them easy to understand.
Step 2
5.1.2 Give ONE reason why algorithms should NOT be language specific.
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
Algorithms should not be language specific because they are conceptual frameworks designed to outline a solution, independent of any programming language syntax. This universality allows algorithms to be implemented in any language, depending on programmer preference or requirements.
Step 3
5.2.1 What can be done to make the code in the example above more readable?
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
To enhance the readability of the code, you can:
Indent the code consistently to reflect the structure and flow.
Add comments that explain the purpose of the variables and procedures.
Use spacing to separate logical sections, making it visually easier to follow.
Step 4
5.2.2(a) What type of error is this?
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 represents a logical error. This type of error occurs when the program runs without crashing but produces incorrect results due to flaws in the logic.
Step 5
5.2.2(b) Give TWO reasons why the sum is displayed as 0, even though the sum is calculated correctly in line 9.
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
Two reasons why the sum is displayed as 0:
Scope Issue: The variable iSum in displayAnswer is a local variable and does not reference the iSum calculated in btnCalculateClick, leading to the default initialized value of 0 being displayed.
Variable Life Cycle: The iSum is reset or not retained between procedure calls, resulting in an output of 0 rather than the calculated sum.
Step 6
5.3.1 Line 5 needs to be completed. Write Delphi code to generate a random number in the range 10 to 40.
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 Delphi code to generate a random number in the specified range can be written as:
iRandom := random(31) + 10;
Step 7
5.3.2(a) The IF statement to determine if the randomly generated number is an odd number will be …
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
The correct IF statement to determine if the randomly generated number is odd is:
if (iRandom MOD 2 <> 0) then
Step 8
5.3.2(b) The statement inc(iCountOdd) should be added to the code above. Choose the line number for the correct position of the 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 statement inc(iCountOdd) should be added at line 11, right after displaying the message.
Step 9
5.3.2(c) Which ONE of the following will provide the correct solution if the While statement in the given code on the previous page must be replaced by a Repeat..Until statement:
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 correct replacement with a Repeat..Until statement is:
Repeat
// logic here
Until iCountOdd = 15;
Step 10
5.4.1 Write down the most suitable data type for variable X.
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 most suitable data type for variable X, which represents the result of Floor(80/12*2), is Integer. This is because the result will be a whole number.
Step 11
5.4.2 Write down the most suitable data type for variable Y.
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
The most suitable data type for variable Y, calculated as Sqr(Sqrt(Number)), is Real/Double. This is appropriate as the square root function can return decimal values.
Step 12
5.5.1 Differentiate between an accessor method and a mutator method.
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
An accessor method retrieves the value of a property or field from a class but does not alter it. On the other hand, a mutator method changes the value of a property, allowing modifications.
Step 13
5.5.2(a) What does the positive sign (+) and the negative sign (-) refer to in the UML diagram?
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
In the UML diagram, the positive sign (+) represents public visibility, meaning that the attribute or method can be accessed from outside the class. The negative sign (-) signifies private visibility, meaning that the attribute or method is not accessible from outside the class.
Step 14
5.5.2(b) Refer to the answer in QUESTION 5.5.2(a) and motivate why instance fields/attributes should rather be declared with the negative sign (-) rather than with the positive sign (+).
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
Instance fields should be declared with the negative sign (-) to encapsulate data and preserve integrity. This prevents unauthorized access and modification from external classes, thus maintaining the internal state of the class consistent and secure.
Step 15
5.5.3 Identify ONE procedure in the UML diagram above.
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
One procedure identified in the UML diagram is setContactNumber(ContactNumber:String);. This is a mutator method that allows setting of the Contact Number for the TStaff class.
Step 16
5.6 Complete the algorithm above to display the required output.
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 complete the Fibonacci algorithm:
else if iNumTerms > 2 then
begin
for v from 1 to iNumTerms - 2 do
begin
item3 <- item1 + item2;
sLine <- sLine + item3 + ' ';
item1 <- item2;
item2 <- item3;
end;
end;
Display sLine;