Photo AI

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

Complete-the-code-as-specified-in-QUESTION-3.1-and-QUESTION-3.2-NSC Information Technology-Question 3-2022-Paper 1.png

Complete the code as specified in QUESTION 3.1 and QUESTION 3.2. 3.1.1 Write code for a constructor method that initializes a Delivery trip object. The method shoul... show full transcript

Worked Solution & Example Answer:Complete the code as specified in QUESTION 3.1 and QUESTION 3.2 - NSC Information Technology - Question 3 - 2022 - Paper 1

Step 1

3.1.1 Write code for a constructor method that initializes a Delivery trip object.

96%

114 rated

Answer

To create a constructor method for the Delivery trip object, we define a class with the parameters for departure city, destination city, and load. The constructor will initialize these attributes.

Example:

constructor TDeliveryTrip.create(aDepartureCity, aDestinationCity: string; aLoad: Integer);
begin
  fDepartureCity := aDepartureCity;
  fDestinationCity := aDestinationCity;
  fLoad := aLoad;
  fTripNumber := compileTripNum;
  fDistance := 0;
end;

Step 2

3.1.2 While code for a constructor method that will initialize the departure city...

99%

104 rated

Answer

This method is part of the constructor created in 3.1.1, and initializes the corresponding attributes for departure city, destination city, and load. It's important to ensure that the parameters are of the correct type and assigned correctly.

constructor TDeliveryTrip.create(aDepartureCity, aDestinationCity: string; aLoad: Integer);
begin
  // Initialize attributes
  fDepartureCity := aDepartureCity;
  fDestinationCity := aDestinationCity;
  fLoad := aLoad;
end;

Step 3

3.1.3 Write code for an accessor method called getDistance.

96%

101 rated

Answer

The accessor method getDistance retrieves the distance attribute of the Delivery trip object. It will return the value of the fDistance attribute.

Example:

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

Step 4

3.1.4 While code for a method called setDistance.

98%

120 rated

Answer

SetDistance allows the modification of the distance parameter for the Delivery trip object. It takes a parameter which will set the fDistance value.

Example:

procedure TDeliveryTrip.setDistance(aDistance: Integer);
begin
  fDistance := aDistance;
end;

Step 5

3.1.5 Write code for a method called determineTruckType.

97%

117 rated

Answer

This method will return a string representing the type of truck based on the load. It uses conditional statements to check the load weight and assigns the appropriate truck type.

Example:

function TDeliveryTrip.determineTruckType: string;
begin
  if fLoad <= 1000 then
    Result := 'Light Truck'
  else if fLoad <= 5000 then
    Result := 'Medium Truck'
  else
    Result := 'Heavy Truck';
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

;