• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
130 views

Problem:

Write a destructor for the carcounter class that outputs the following. end with newline. I am new in programming , can anyone help me write this program in c++. I have just started to learn about destructor .

by (550 points)  
retagged by

1 Answer

0 votes

Solution:

#include <iostream>
using namespace std;

/*
    Program for getting output "Destroying CarCounter" by use of destructor
*/

class CarCounter {
   public:
      CarCounter();
      ~CarCounter();
   private:
      int carTotal;
};

CarCounter::CarCounter() {
   carTotal = 0;
   return;
}

/* Your solution goes here  */
CarCounter::~CarCounter(){
    cout << "Destroying CarCounter" << endl;
}


int main() {
   CarCounter* parkingLot = new CarCounter();
   delete parkingLot;

   return 0;

by (4k points)  
...