Photo AI

5.1 An algorithm is a step by step breakdown to solving a problem - NSC Information Technology - Question 5 - 2021 - Paper 2

Question icon

Question 5

5.1-An-algorithm-is-a-step-by-step-breakdown-to-solving-a-problem-NSC Information Technology-Question 5-2021-Paper 2.png

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... 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

Answer

One technique that can be used to represent an algorithm is a flowchart. Flowcharts visually depict the sequence of steps and decisions needed to perform a process.

Step 2

5.1.2 Give ONE reason why algorithms should NOT be language specific.

99%

104 rated

Answer

Algorithms should not be language specific because they are designed to be understood and implemented in various programming languages. This universality allows for greater flexibility and applicability across different contexts.

Step 3

5.2.1 What can be done to make the code in the example above more readable?

96%

101 rated

Answer

To enhance the readability of the code, it can be indented properly, add line spacing or blank lines where appropriate, and include comments to explain the functionality of different sections.

Step 4

5.2.2 When the program is executed, the output displayed in line 17 will be... (a) What type of error is this?

98%

120 rated

Answer

(a) This is a logical error because the variable iSum is local to the displayAnswer procedure and is not correctly assigned before it is used.

(b) Two reasons why the sum is displayed as 0:

  1. The variable iSum in displayAnswer is not initialized; it's declared but remains empty (default to 0).
  2. The iSum in the displayAnswer procedure is a different variable from the iSum in the btnCalculateClick procedure, leading to a scope issue.

Step 5

5.3.1 Line 5 needs to be completed. Write Delphi code to generate a random number in the range 10 to 40.

97%

117 rated

Answer

The line should be completed with the following code:

 iRandom := random(31) + 10;

Step 6

5.3.2 (a) The IF statement to determine if the randomly generated number is an odd number will be ...

97%

121 rated

Answer

(a) The correct option is:

(iii) if (iRandom MOD 2 <> 0) then

(b) The statement inc(iCountOdd) should be placed at line:

(ii) 8.

(c) The correct replacement will be:

(iii) Repeat Until iCountOdd = 15;

Step 7

5.4.1 Write down the most suitable data types for variables X and Y in the following statements where the data type of the Number variable is not known:

96%

114 rated

Answer

For variable X, the suitable data type is Integer since the result of Floor(80/12*2) will always yield an integer value.

For variable Y, the most suitable data type is Real or Double, as the Sqr function involves square root operations, which can produce non-integer results.

Step 8

5.5.2 (a) What does the positive sign (+) and the negative sign (-) refer to in the UML diagram?

99%

104 rated

Answer

(a) The positive sign (+) indicates public access to a method or variable, meaning it can be accessed from outside the class. The negative sign (-) indicates private access, meaning it can only be accessed from within the class.

(b) The instance fields/attributes should be declared with the negative sign (-) to restrict access from outside the class and prevent unintended changes to the object's state.

Step 9

5.5.3 Identify ONE procedure in the UML diagram above.

96%

101 rated

Answer

One procedure in the UML diagram is setContactNumber(ContactNumber:String); which is used to set the contact number of the staff.

Step 10

5.6 Complete the algorithm above to display the required output.

98%

120 rated

Answer

To complete the algorithm, we can add a loop that calculates the Fibonacci sequence as follows:

 for i from 1 to iNumTerms - 2 do
 begin
   iTerm3 ← iTerm1 + iTerm2;
   sLine ← sLine + ' ' + iTerm3;
   iTerm1 ← iTerm2;
   iTerm2 ← iTerm3;
 end;
 display sLine;

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;