challenge activity 8.9.2: write a copy constructor. write a copy constructor for carcounter that assigns origcarcounter.carcount to the constructed object's carcount. sample output for the given program: cars counted: 5

Respuesta :

The program written in C++ where through copy constructor Car_Counter assigns origCar_Counter.Car_Counter to the constructed object's CarCount.

#include <iostream>

using namespace std;

class Car_Counter

{

 public:

   Car_Counter();

    Car_Counter(const Car_Counter& origCar_Counter);

    void SetCarCount(const int count)

    {

     carCount = count;

    }

       int GetCarCount() const

   {

        return carCount;

    }

 private:

    int carCount;

};

Car_Counter::Car_Counter()

{

 carCount = 0;

 return;

}

Car_Counter::Car_Counter(const Car_Counter &p)

{

carCount = p.carCount;

}

void CountPrinter(Car_Counter carCntr)

{

 cout << "Cars Counted =  " << carCntr.GetCarCount();

 return;

}

int main()

{

 Car_Counter parkingLot;

 parkingLot.SetCarCount(5);

 CountPrinter(parkingLot);

 return 0;

}

Output with running program is given below:

You can learn more about copy constructor at

https://brainly.com/question/13267121

#SPJ4

Ver imagen asarwar