Photo AI

Delivery trip system You are to complete the code as specified in QUESTION 3.1 and QUESTION 3.2 - NSC Information Technology - Question 3 - 2022 - Paper 1

Question icon

Question 3

Delivery-trip-system--You-are-to-complete-the-code-as-specified-in-QUESTION-3.1-and-QUESTION-3.2-NSC Information Technology-Question 3-2022-Paper 1.png

Delivery trip system You are to complete the code as specified in QUESTION 3.1 and QUESTION 3.2. 3.1 Trip details 3.1.1 Function compileTripNum: - Repeat Genera... show full transcript

Worked Solution & Example Answer:Delivery trip system You are to complete the code as specified in QUESTION 3.1 and QUESTION 3.2 - NSC Information Technology - Question 3 - 2022 - Paper 1

Step 1

Function compileTripNum:

96%

114 rated

Answer

To implement the compileTripNum function, we need to generate a random four or five-digit number, ensuring the last digit is not zero. This can be achieved using the following pseudo-code:

function compileTripNum: Integer;
var
  sTripNum: String;
begin
  repeat
    sTripNum := IntToStr(Random(10)) +  
                IntToStr(Random(10)) +  
                IntToStr(Random(9) + 1);
  until (sTripNum[Length(sTripNum)] <> '0');
  Result := StrToInt(sTripNum);
end;

Step 2

Constructor Create:

99%

104 rated

Answer

The constructor should accept parameters for departure city, destination city, and load. The implementation can be:

constructor TDeliveryTrip.Create(aDepartureCity, aDestinationCity: String; aLoad: Integer);
begin
  fDeparture := aDepartureCity;
  fDestination := aDestinationCity;
  fLoad := aLoad;
  fTripNumber := compileTripNum;
  fDistance := 0;
end;

Step 3

Function getDistance:

96%

101 rated

Answer

The getDistance function should return the value of fDistance, ensuring it is of the correct type. The implementation can be represented as:

function TDeliveryTrip.getDistance: Integer;
begin
  Result := fDistance;
end;

Step 4

Procedure setDistance:

98%

120 rated

Answer

To set the distance, the procedure should read from a file and extract city information. Here is a sample implementation:

procedure TDeliveryTrip.setDistance;
var
  line: String;
begin
  AssignFile(InputFile, 'distance.txt');
  Reset(InputFile);
  while not EOF(InputFile) do
  begin
    ReadLn(InputFile, line);
    // Process the line to set distance
  end;
  CloseFile(InputFile);
end;

Step 5

Function determineTruckType:

97%

117 rated

Answer

This function determines the type of truck based on the load. Here is how this can be implemented:

function TDeliveryTrip.determineTruckType: String;
begin
  if fLoad = 0 then
    Result := 'No distance'
  else if fLoad <= 1000 then
    Result := 'Light truck'
  else if fLoad <= 5000 then
    Result := 'Medium truck'
  else
    Result := 'Heavy truck';
end;

Step 6

Button [3.2.1 – Create trip]:

97%

121 rated

Answer

For the button that creates a trip, extract relevant values and instantiate the object:

procedure TForm1.btnCreateTripClick(Sender: TObject);
var
  objTrip: TDeliveryTrip;
begin
  objTrip := TDeliveryTrip.Create(edtDepartureCity.Text, edtDestinationCity.Text, StrToInt(edtLoad.Text));
  // Display the object details
  MemoOutput.Text := objTrip.ToString;
end;

Step 7

Button [3.2.2 – Determine and set distance]:

96%

114 rated

Answer

This button reads the distance related to the trip:

procedure TForm1.btnSetDistanceClick(Sender: TObject);
var
  departureCity, destinationCity: String;
begin
  // Implementation to read cities and set distance
  // Example output for distance
  MemoOutput.Text := Format('Distance between %s and %s is ...', [departureCity, destinationCity]);
end;

Step 8

Button [3.2.3 – Determine truck type]:

99%

104 rated

Answer

To determine the truck type, invoke the function and display the result:

procedure TForm1.btnDetermineTruckTypeClick(Sender: TObject);
var
  truckType: String;
begin
  truckType := objTrip.determineTruckType;
  edtTruckType.Text := truckType;
end;

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

;