Photo AI

QUESTION 4 - PROBLEM-SOLVING PROGRAMMING SCENARIO Tons of cargo are loaded into containers and stored in the harbour for shipment - NSC Information Technology - Question 4 - 2020 - Paper 1

Question icon

Question 4

QUESTION-4---PROBLEM-SOLVING-PROGRAMMING--SCENARIO-Tons-of-cargo-are-loaded-into-containers-and-stored-in-the-harbour-for-shipment-NSC Information Technology-Question 4-2020-Paper 1.png

QUESTION 4 - PROBLEM-SOLVING PROGRAMMING SCENARIO Tons of cargo are loaded into containers and stored in the harbour for shipment. Do the following: Open the inc... show full transcript

Worked Solution & Example Answer:QUESTION 4 - PROBLEM-SOLVING PROGRAMMING SCENARIO Tons of cargo are loaded into containers and stored in the harbour for shipment - NSC Information Technology - Question 4 - 2020 - Paper 1

Step 1

4.1.1 Button [4.1.1 - Create harbour containers]

96%

114 rated

Answer

To generate fifty (50) random real values:

  1. Implement a loop that iterates 50 times.
  2. Within the loop, generate a random real value using a specific formula that ensures the result lies between 1 and 99 (inclusive).
    • Use a random function and round the value to one decimal place.
  3. Store the generated value in the arrContainers array at the current index.
  4. Increment the index after each iteration.

Step 2

4.1.2 Button [4.1.2 - Display harbour containers]

99%

104 rated

Answer

To display the weights:

  1. Initialize a string variable sLine as an empty string.
  2. Set an index variable to 0 and create a loop for five rows.
  3. Inside this loop, create another nested loop for ten columns.
  4. In the nested loop, increment the index, and concatenate the weight of the container at this index to sLine using the following format: sLine := sLine + FloatToStr(arrContainers[index]) + ' ';.
  5. After populating the row, display sLine in the rich edit redQ4_1_2.

Step 3

4.2 Button [4.2 - Containers loaded to be shipped]

96%

101 rated

Answer

To manage loading of containers:

  1. Initialize TotalTons to zero and prepare a string variable for display.
  2. Set up an index for iterating through arrContainers.
  3. Create a loop that runs while the index is less than 50:
    • Check if adding the container's weight at the current index to TotalTons would stay under or equal to 200 tons.
    • If it does, add this weight to TotalTons, updating the weights loaded and noting which containers are included in a display array.
  4. Increment the index after each iteration.
  5. After the loop, display the total weight in the rich edit component and write the results to a text file called Tons.txt, closing the file afterward.

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

;