Photo AI

The group of IT friends are writing customised programs for their business - NSC Information Technology - Question 5 - 2016 - Paper 2

Question icon

Question 5

The-group-of-IT-friends-are-writing-customised-programs-for-their-business-NSC Information Technology-Question 5-2016-Paper 2.png

The group of IT friends are writing customised programs for their business. 5.1 Indicate how many times each of the following loops will be executed: 5.1.1 k < 1 r... show full transcript

Worked Solution & Example Answer:The group of IT friends are writing customised programs for their business - NSC Information Technology - Question 5 - 2016 - Paper 2

Step 1

5.1.1 k < 1

96%

114 rated

Answer

The loop repeat … instructions to be executed until k = 1 will execute only once, provided that the condition k < 1 is true initially. When the loop condition is no longer true (i.e., when k is changed to be equal to or greater than 1), the loop ends.

Step 2

5.1.2 k >= 0

99%

104 rated

Answer

The loop while k >= 0 begin … increment k end can potentially result in an infinite loop if k never becomes less than 0 because it continues to execute as long as k is greater than or equal to 0. This means that if k starts at a non-negative value and is never decremented, the loop will never terminate.

Step 3

5.2.1 What does it mean to instantiate an object?

96%

101 rated

Answer

To instantiate an object means to create a specific instance of a class in memory. When an object is instantiated, it allocates space in memory to store the attributes (fields) defined in the class and allows the user to interact with the object through its methods.

Step 4

5.2.2 Explain the purpose of:

98%

120 rated

Answer

(a) An accessor method is used to retrieve or access the value of a private attribute of the class without modifying it, ensuring encapsulation by preventing direct access to the private data.

(b) A mutator method allows the modification or updating of a variable's value, providing controlled access to change the state of an object's private attributes.

Step 5

5.2.3 Write an algorithm for the CalculateCost(LogoutTime) method in pseudocode.

97%

117 rated

Answer

  1. get login in minutes
  2. get logout minutes
  3. get login hour
  4. get logout hour
  5. calculate the number of hours
  6. calculate the number of minutes
  7. convert hours to minutes and add minutes
  8. cost = numberOfMinutes * 3

This pseudocode considers the hourly cost of internet connection based on the minutes calculated from the login and logout times.

Step 6

5.3

97%

121 rated

Answer

Found Is Found true? randomNum = number? Counter Display

First iteration: Line 2: Initial value of Found is false. Line 4: randomNum generates first random number. Line 5: Check if randomNum is not equal to number. If True, execute Line 6 to increment Counter.

Repeat until condition is met, checking each iteration.

Errors: Counter not initialised before use, and increment statement should be inside the iteration check.

Step 7

5.4

96%

114 rated

Answer

In this pseudocode segment, whenever the loop is executed, it outputs the value of 'output'. For each iteration:

  • On iteration 1: output could be 1 or 0 based on the evaluated condition.
  • On iteration 2: output is based on the same evaluation. The values displayed depend on the initial values of x, y, and z. The values of x, y, and z need to be defined for a correct output.

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

;