Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BOTH QUESTIONS ONLY FILL IN C++ CODE Write a copy constructor for CarCounter that assignsorigCarCounter.carCount to the constructed object's carCount.Sample output for the given program:

BOTH QUESTIONS ONLY FILL IN C++ CODE

Write a copy constructor for CarCounter that assignsorigCarCounter.carCount to the constructed object's carCount.Sample output for the given program:

Cars counted: 5



Sample program:

#include using namespace std;class CarCounter {   public:      CarCounter();      CarCounter(const CarCounter& origCarCounter);      void SetCarCount(const int count) {          carCount = count;      }      int GetCarCount() const {          return carCount;      }   private:      int carCount;};CarCounter::CarCounter() {   carCount = 0;   return;}// FIXME add copy constructorvoid CountPrinter(CarCounter carCntr) {   cout << "Cars counted: " << carCntr.GetCarCount();   return;}int main() {   CarCounter parkingLot;   parkingLot.SetCarCount(5);   CountPrinter(parkingLot);   return 0;

}

QUESTION#2!!!!!!!!!!!!!!!!_______________----------------------------------------------_______________________________

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

First vacation: Days: 7, People: 3Second vacation: Days: 12, People: 3



Sample program:

#include using namespace std;class FamilyVacation{   public:      void  SetNumDays(int dayCount);      void  SetNumPeople(int peopleCount);      void  Print() const;      FamilyVacation operator+(int moreDays) const;   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.  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;}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions