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

This loop will be executed once. The loop condition 'k < 1' must initially be true for the loop to execute. When 'k' equals 1, the loop will stop.

Step 2

5.1.2 k < 0

99%

104 rated

Answer

This loop will result in an infinite loop because the condition 'k >= 0' will always be true if 'k' starts from any non-negative value and never changes. Thus, the instructions within the loop will execute continuously.

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, allocating the necessary resources to hold the attributes associated with that object.

Step 4

5.2.2 (a) An accessor method

98%

120 rated

Answer

An accessor method is used to retrieve private data from an object without allowing external modification. It provides a way to obtain attribute values.

Step 5

5.2.2 (b) A mutator method

97%

117 rated

Answer

A mutator method is used to modify the values of an object's attributes. It sets or changes the state of an object.

Step 6

5.2.3 Write an algorithm for the CalculateCost(LogoutTime)

97%

121 rated

Answer

  1. Get login minutes
  2. Get logout minutes
  3. Get login hour
  4. Get logout hour
  5. Calculate the number of minutes
  6. Determine total minutes logged in = (logout hour * 60 + logout minutes) - (login hour * 60 + login minutes)
  7. Cost = total minutes logged in * 3

Step 7

5.3 Copy and complete the trace table

96%

114 rated

Answer

To correct the algorithm:

  1. Initialize the counter before the loop starts.
  2. Increment the counter in both branches of the conditional statement.

Trace Table: Found Is Found true? randomNum = number? Counter Display False No/False 5 No Undefined 40 Yes Undefined

The number of iterations will determine how many times the random number is generated until it matches the user's input.

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

;