
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 stepSolved in 3 steps with 1 images

- c++arrow_forwardWrite the PrintItem() function for the base class. Sample output for below program: Last name: Smith First and last name: Bill Jones Hint: Use the keyword const to make PrintItem() a virtual function. Partially completed code (C++): #include <iostream>#include <string>#include <vector>using namespace std; class BaseItem {public:void SetLastName(string providedName) {lastName = providedName;}; // FIXME: Define PrintItem() member function /* Your solution goes here */ protected:string lastName;}; class DerivedItem : public BaseItem {public:void SetFirstName(string providedName) {firstName = providedName;}; void PrintItem() const override {cout << "First and last name: ";cout << firstName << " " << lastName << endl;}; private:string firstName;}; int main() {BaseItem* baseItemPtr = nullptr;DerivedItem* derivedItemPtr = nullptr;vector<BaseItem*> itemList;unsigned int i; baseItemPtr = new BaseItem();baseItemPtr->SetLastName("Smith");…arrow_forwardImplement in C Programing 7.10.1: LAB: Product struct Given main(), build a struct called Product that will manage product inventory. Product struct has three data members: a product code (string), the product's price (double), and the number count of product in inventory (int). Assume product code has a maximum length of 20. Implement the Product struct and related function declarations in Product.h, and implement the related function definitions in Product.c as listed below: Product InitProduct(char *code, double price, int count) - set the data members using the three parameters Product SetCode(char *code, Product product) - set the product code (i.e. SKU234) to parameter code void GetCode(char *productCode, Product product) - return the product code in productCode Product SetPrice(double price, Product product) - set the price to parameter product double GetPrice(Product product) - return the price Product SetCount(int count, Product product) - set the number of items in inventory…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





