Photo AI

Do the following: Open the incomplete program in the Question 4 folder - NSC Information Technology - Question 4 - 2020 - Paper 1

Question icon

Question 4

Do-the-following:--Open-the-incomplete-program-in-the-Question-4-folder-NSC Information Technology-Question 4-2020-Paper 1.png

Do the following: Open the incomplete program in the Question 4 folder. Enter your examination number as a comment in the first line of the Question_4_U.pas file. C... show full transcript

Worked Solution & Example Answer:Do the following: Open the incomplete program in the Question 4 folder - NSC Information Technology - Question 4 - 2020 - Paper 1

Step 1

Button [4.1.1 - Create harbour containers]

96%

114 rated

Answer

To implement this part of the code, create a loop that runs 50 times to generate random real numbers:

  1. Set up your loop to iterate 50 times.
  2. Within the loop, generate a random number between 1 and 99 using a random number generator function.
  3. Round this number to one decimal place.
  4. Assign each generated value to the array arrContainers for each index from 1 to 50.

Here is a sample code snippet:

for i := 1 to 50 do
begin
  arrContainers[i] := Round(Random(99) + 1 * 10) / 10;
end;

Step 2

Button [4.1.2 - Display harbour containers]

99%

104 rated

Answer

For the second part, create a nested loop to display the contents of arrContainers:

  1. Set an index for the rows of display and set it initially to zero.
  2. Loop through rows to display data in 5 rows.
  3. For each row, loop through 10 columns and append the values from arrContainers based on the appropriate index.
  4. Format your output to display in the redQ4_1_2 component and ensure proper spacing.

The code will look something like this:

for row := 0 to 4 do
begin
  line := '';
  for col := 0 to 9 do
  begin
    line := line + FloatToStr(arrContainers[row * 10 + col]) + ' ';
  end;
  redQ4_1_2.Lines.Add(line);
end;

Step 3

Button [4.2 - Containers loaded to be shipped]

96%

101 rated

Answer

In this part, you will need to manage the loading process of containers onto the ship:

  1. Initialize a variable TotalTons to zero.
  2. Loop through arrContainers checking the weight of each container.
  3. If adding the weight of a container keeps the total under or equal to 200 tons, add that weight to TotalTons and store the detail of this container.
  4. If the next container's weight would exceed 200 tons, skip it and proceed to the next.
  5. Display the total weight in the panel pnlQ4 and write it to Tons.txt.

Here’s how you could write the code:

TotalTons := 0;
for index := 1 to 50 do
begin
  if (TotalTons + arrContainers[index]) <= 200 then
  begin
    TotalTons := TotalTons + arrContainers[index];
    redQ4_2.Lines.Add(FloatToStr(arrContainers[index]));
  end;
end;
// Write to file
AssignFile(TonsFile, 'Tons.txt');
Rewrite(TonsFile);
WriteLn(TonsFile, TotalTons);
CloseFile(TonsFile);

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

;