Photo AI

Complete the code in the given Excursion object class (Excursion/Excursion) as described in QUESTION 2.1.1 to QUESTION 2.1.5 below - NSC Information Technology - Question 2 - 2016 - Paper 1

Question icon

Question 2

Complete-the-code-in-the-given-Excursion-object-class-(Excursion/Excursion)-as-described-in-QUESTION-2.1.1-to-QUESTION-2.1.5-below-NSC Information Technology-Question 2-2016-Paper 1.png

Complete the code in the given Excursion object class (Excursion/Excursion) as described in QUESTION 2.1.1 to QUESTION 2.1.5 below. 2.1.1 Write a mutator method cal... show full transcript

Worked Solution & Example Answer:Complete the code in the given Excursion object class (Excursion/Excursion) as described in QUESTION 2.1.1 to QUESTION 2.1.5 below - NSC Information Technology - Question 2 - 2016 - Paper 1

Step 1

2.1.1 Write a mutator method called setVisitDate

96%

114 rated

Answer

Define a method setVisitDate that takes a date parameter and assigns it to the attribute that stores the visit date.

procedure setVisitDate(aDate: Date);
begin
  visitDate := aDate;
end;

Step 2

2.1.2 Write a method called requireTourGuide

99%

104 rated

Answer

Create a method requireTourGuide that checks if a tour guide is required. It should return "Yes" or "No" based on the boolean tourGuide value.

function requireTourGuide: String;
begin
  if tourGuide then
    Result := 'Yes'
  else
    Result := 'No';
end;

Step 3

2.1.3 Write a method called isConfirmed

96%

101 rated

Answer

Define the isConfirmed method that checks if the total number of learners does not exceed 600 when combined with learners from other schools attending on the requested date.

function isConfirmed(groupSize: Integer): Boolean;
begin
  if (dayTotal + groupSize) <= 600 then
    Result := true
  else
    Result := false;
end;

Step 4

2.1.4 Write a method called calcAmount

98%

120 rated

Answer

Implement the calcAmount method that calculates the amount to be paid, considering the number of free entries based on group size.

function calcAmount(costPerPerson: Real): Real;
begin
  numberFree := groupSize div 10;
  amount := (groupSize - numberFree) * costPerPerson;
  Result := amount;
end;

Step 5

2.1.5 Complete the toString method

97%

117 rated

Answer

Build the toString method that formats the output with the excursion details in a readable format.

function toString: String;
begin
  Result := 'School name: ' + schoolName + #13#10 +
            'Visit date: ' + visitDate + #13#10 +
            'Number of learners: ' + IntToStr(groupSize) + #13#10 +
            'Tour guide: ' + requireTourGuide;
end;

Step 6

2.2.1 Button [2.2.1 – Instantiate object]

97%

121 rated

Answer

Extract the school name and group size from the user input and instantiate an Excursion object using the data entered in the appropriate fields. Show a message that the object was instantiated successfully.

var
   newExcursion: Excursion;
begin
   newExcursion := Excursion.Create;
   newExcursion.setVisitDate(visitDate);
   newExcursion.groupSize := StrToInt(txtGroupSize.Text);
   // Display message to user
   ShowMessage('Excursion object instantiated successfully.');
end;

Step 7

2.2.2(a) Button [2.2.2 – Confirm availability]

96%

114 rated

Answer

Define the determineDayTotal method to process the available data from the text file and check the group size to confirm availability for the excursion date.

procedure determineDayTotal(var dayTotal: Integer);
begin
  dayTotal := 0;
  // Read from the file and calculate total
  // Extract the date, total count from the text file
end;

Step 8

2.2.2(b) Using the method determineDayTotal

99%

104 rated

Answer

Call determineDayTotal, then use the result to check availability. If confirmed, proceed to calculate amount; otherwise, display a message.

begin
  determineDayTotal(dayTotal);
  if isConfirmed(groupSize) then begin
    // Call calcAmount to get final charge
    ShowMessage('The total amount is: ' + FloatToStr(calcAmount(costPerPerson)));
  end
  else
    ShowMessage('No availability for the selected date.');
end;

Step 9

2.2.3 Button [2.2.3 – Confirm new date]

96%

101 rated

Answer

Check if the date selection combo box has alternative dates; if so, display the selected date information. Otherwise, indicate that no alternatives were found.

if cmbDates.ItemIndex > -1 then begin
  // Display selected date
end
else
  ShowMessage('No alternative dates available.');

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

;