Question

Overload the + operator as indicated. Sample output for the given program: First vacation: Days: 7,...

Overload the + operator as indicated. Sample output for the given program:

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;
return;
}

void FamilyVacation::SetNumPeople(int peopleCount) {
numPeople = peopleCount;
return;
}

// FIXME: Overload + operator so can write newVacation = oldVacation + 5,
// which adds 5 to numDays, while just copying numPeople.

FamilyVacation FamilyVacation::operator+(int SetNumDays) {
int dayCount = dayCount + 5;
}

void FamilyVacation::Print() const {
cout << "Days: " << numDays << ", People: " << numPeople << endl;
return;
}

int main() {
FamilyVacation firstVacation;
FamilyVacation secondVacation;

cout << "First vacation: ";
firstVacation.SetNumDays(7);
firstVacation.SetNumPeople(3);
firstVacation.Print();

cout << "Second vacation: ";
secondVacation = firstVacation + 5;
secondVacation.Print();

return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Overload the + operator as indicated. Sample output for the given program: First vacation: Days: 7,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • C++ Define a constructor as indicated. Sample output for below program: Year: 0, VIN: -1 Year:...

    C++ Define a constructor as indicated. Sample output for below program: Year: 0, VIN: -1 Year: 2009, VIN: 444555666 #include <iostream> using namespace std; class CarRecord { public: void   SetYearMade(int originalYear); void   SetVehicleIdNum(int vehIdNum); void   Print() const; CarRecord(); private: int    yearMade; int    vehicleIdNum; }; // FIXME: Write constructor, initialize //year to 0, vehicle ID num to -1. /* Your solution goes here */ void CarRecord::SetYearMade(int originalYear) { yearMade = originalYear; } void CarRecord::SetVehicleIdNum(int vehIdNum) { vehicleIdNum = vehIdNum; } void...

  • Hello, im looking for help on adding overload operators to my code. It needs to consist...

    Hello, im looking for help on adding overload operators to my code. It needs to consist of + (addition) for the Fraction class * (multiplication), no need not reduce == (equality operator) = (assignment operator) << and >> so in main you can use << and >> as follows:  cin>>frac1; cout<< frac1; where frac1 is a an object of the Fraction class   the original code is: #include <iostream> using namespace std; class Fractions { private:    int numerator;    int denominator;...

  • ////****what am i doing wrong? im trying to have this program with constructors convert inches to...

    ////****what am i doing wrong? im trying to have this program with constructors convert inches to feet too I don't know what im doing wrong. (the program is suppose to take to sets of numbers feet and inches and compare them to see if they are equal , greater, less than, or not equal using operator overload #include <stdio.h> #include <string.h> #include <iostream> #include <iomanip> #include <cmath> using namespace std; //class declaration class FeetInches { private:    int feet;   ...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor...

    Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &); //copy constror Matrix(int row, int col); Matrix operator+(const Matrix &)const; //overload operator“+” Matrix& operator=(const Matrix &); //overload operator“=” Matrix transpose()const; //matrix transposition void display()const; //display the data private: int row; //row int col; //column int** mat; //to save the matrix }; //main.cpp #include <iostream> #include"Matrix.h" using namespace std; int main() { int row, col; cout << "input the row and the col for Matrix...

  • Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &);...

    Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &); //copy constror Matrix(int row, int col); Matrix operator+(const Matrix &)const; //overload operator“+” Matrix& operator=(const Matrix &); //overload operator“=” Matrix transpose()const; //matrix transposition void display()const; //display the data private: int row; //row int col; //column int** mat; //to save the matrix }; //main.cpp #include <iostream> #include"Matrix.h" using namespace std; int main() { int row, col; cout << "input the row and the col for Matrix...

  • I need assistance with the C++ code below to remove the "this" pointers while maintaining the...

    I need assistance with the C++ code below to remove the "this" pointers while maintaining the code's current output and functionality. Also, there should be a private class in the header file, but I'm not sure what I should include there. Any help would be greatly appreciated! ***main.cpp driver file*** #include <iostream> #include "vector.h" using namespace std; int main() {   vectorInfo v1(7, 6);   vectorInfo v2(5, 4);       v1.set(3, 2);   cout << "v1 : ";   v1.print();       cout << "v2 :...

  • For the LinkedList class, create a getter and setter for the private member 'name', constructing your...

    For the LinkedList class, create a getter and setter for the private member 'name', constructing your definitions based upon the following declarations respectively: std::string get_name() const; and void set_name(std::string); In the Main.cpp file, let's test your getter and setter for the LinkedLIst private member 'name'. In the main function, add the following lines of code: cout << ll.get_name() << endl; ll.make_test_list(); ll.set_name("My List"); cout << ll.get_name() << endl; Output should be: Test List My List Compile and run your code;...

  • Task: Tasks to complete: ------------------------------------------------------------------------------------------------------------------------------------------ given code: --------------------...

    Task: Tasks to complete: ------------------------------------------------------------------------------------------------------------------------------------------ given code: ------------------------------------------------------------------------------------------------------------------------------------------ main.cpp #include #include "rectangleType.h" using namespace std; // part e int main() { rectangleType rectangle1(10, 5); rectangleType rectangle2(8, 7); rectangleType rectangle3; rectangleType rectangle4; cout << "rectangle1: " << rectangle1 << endl; cout << "rectangle2: " << rectangle2 << endl; rectangle3 = rectangle1 + rectangle2;    cout << "rectangle3: " << rectangle3 << endl; rectangle4 = rectangle1 * rectangle2;    cout << "rectangle4: " << rectangle4 << endl; if (rectangle1 > rectangle2) cout << "Area...

  • C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares...

    C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT