Write a copy assignment operator for CarCounter that assigns objToCopy.carCount to the new objects's carCount, then returns *this. Sample output for the given program:Cars counted: 12 #include using...


Write a copy assignment operator for CarCounter that assigns objToCopy.carCount to the new objects's carCount, then returns *this. Sample output for the given program:Cars counted: 12


#include
using namespace std;


class CarCounter {
   public:
      CarCounter();
      ~CarCounter();
      CarCounter& operator=(const CarCounter& objToCopy);
      void SetCarCount(const int setVal) {
         *carCount = setVal;
      }
      int GetCarCount() const {
         return *carCount;
      }
   private:
      int* carCount;
};


CarCounter::CarCounter() {
   carCount = new int;
   *carCount = 0;
}


CarCounter::~CarCounter() {
   delete carCount;
}



// FIXME write copy assignment operator



/* Your solution goes here  */


int main() {
   CarCounter frontParkingLot;
   CarCounter backParkingLot;
   int count;


   cin >> count;


   frontParkingLot.SetCarCount(count);
   backParkingLot = frontParkingLot;


   cout < "cars="" counted:="" "=""><>


   return 0;
}



error:


(i tried to type this in but gets an error from down below)


CarCounter& CarCounter::operator=(const CarCounter& objToCopy) {
   carCount = objToCopy.carCount;
   return *this;
}




Testing carCount assigned 12





Your output

Cars counted: 15

Testing carCount assigned 15









Your output

Cars counted: 15







Test aborted




Exited with return code -6 (SIGABRT).

double free or corruption (fasttop)





Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here