C+++ CODE NEED MISSING CODE BELOW for 5.13.2 Operator Overloading Overload the + operator as indicated. Sample output for the given program with inputs 7 3:First vacation: Days: 7, People: 3 Second vacation: Days: 12, People: 3 #include using namespace std; class FamilyVacation { public: void SetNumDays(int dayCount); void SetNumPeople(int peopleCount); void Print() const; FamilyVacation operator+(int moreDays); private: int numDays; int numPeople; }; void FamilyVacation::SetNumDays(int dayCount) { numDays = dayCount; } void FamilyVacation::SetNumPeople(int peopleCount) { numPeople = peopleCount; } // FIXME: Overload + operator so can write newVacation = oldVacation + 5, // which adds 5 to numDays, while just copying numPeople. ******** MISSSING CODE NEEDED GOES HERE. THE REST OF THE CODE CANNOT BE TOUCHED. THANK YOU*************** void FamilyVacation::Print() const { cout << "Days: " << numDays << ", People: " << numPeople << endl; } int main() { FamilyVacation firstVacation; FamilyVacation secondVacation; int userDays; int userPeople; cin >> userDays; cin >> userPeople; cout << "First vacation: "; firstVacation.SetNumDays(userDays); firstVacation.SetNumPeople(userPeople); firstVacation.Print(); cout << "Second vacation: "; secondVacation = firstVacation + 5; secondVacation.Print(); return 0; }
C+++ CODE
NEED MISSING CODE BELOW for 5.13.2 Operator Overloading
Overload the + operator as indicated. Sample output for the given program with inputs 7 3:First vacation: Days: 7, People: 3 Second vacation: Days: 12, People: 3
#include <iostream>
using namespace std;
class FamilyVacation {
public:
void SetNumDays(int dayCount);
void SetNumPeople(int peopleCount);
void Print() const;
FamilyVacation operator+(int moreDays);
private:
int numDays;
int numPeople;
};
void FamilyVacation::SetNumDays(int dayCount) {
numDays = dayCount;
}
void FamilyVacation::SetNumPeople(int peopleCount) {
numPeople = peopleCount;
}
// FIXME: Overload + operator so can write newVacation = oldVacation + 5,
// which adds 5 to numDays, while just copying numPeople.
******** MISSSING CODE NEEDED GOES HERE. THE REST OF THE CODE CANNOT BE TOUCHED. THANK YOU***************
void FamilyVacation::Print() const {
cout << "Days: " << numDays << ", People: " << numPeople << endl;
}
int main() {
FamilyVacation firstVacation;
FamilyVacation secondVacation;
int userDays;
int userPeople;
cin >> userDays;
cin >> userPeople;
cout << "First vacation: ";
firstVacation.SetNumDays(userDays);
firstVacation.SetNumPeople(userPeople);
firstVacation.Print();
cout << "Second vacation: ";
secondVacation = firstVacation + 5;
secondVacation.Print();
return 0;
}
Step by step
Solved in 3 steps with 1 images