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 4
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To generate fifty (50) random real values:
Implement a loop that iterates 50 times.
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.
Store the generated value in the arrContainers array at the current index.
Increment the index after each iteration.
Step 2
4.1.2 Button [4.1.2 - Display harbour containers]
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
To display the weights:
Initialize a string variable sLine as an empty string.
Set an index variable to 0 and create a loop for five rows.
Inside this loop, create another nested loop for ten columns.
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]) + ' ';.
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To manage loading of containers:
Initialize TotalTons to zero and prepare a string variable for display.
Set up an index for iterating through arrContainers.
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.
Increment the index after each iteration.
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.