Photo AI
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. 2.1.1 Write a mutator method cal... show full transcript
Step 1
Step 2
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
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
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
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
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
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
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
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.');
Report Improved Results
Recommend to friends
Students Supported
Questions answered