THIS USER ASKED ๐
Write a destructor for the CarCounter class that outputs the following. End with newline.
Destroying CarCounter
#include
using namespace std;
class CarCounter {
public:
CarCounter();
~CarCounter();
private:
int carCount;
};
CarCounter::CarCounter() {
carCount = 0;
return;
}
/* Your solution goes here */
int main() {
CarCounter* parkingLot = new CarCounter();
delete parkingLot;
return 0;
}
THIS IS THE BEST ANSWER ๐
The code for this question is as follows:
CarCounter :: ~ CarCounter () // CarCounter destructor define
{
cout << "CarCounter Deleted n"; // print print Destroying CarCounter
}
Explanation:
The full program for this question is as follows:
#include
using std spacepace;
CarCounter class // CarCounter definition class
{
public:
CarCounter (); // CarCounter definition builder
~ CarCounter (); // Define CarCounter destructor
private:
int carCount; // CarCount define an integer variable
};
CarCounter :: CarCounter () // builder declarator
{
carCount = 0; // assign a value in a carCount variable
return; // using a return keyword
}
CarCounter :: ~ CarCounter () // CarCounter destructor define
{
cout << "CarCounter Deleted n"; // print print Destroying CarCounter
}
int main () // Define main mode
{
CarCounter * parkLot = new CarCounter (); // ClassLot object parking definition
destroy parkingLot; //
return 0;
}
The given C ++ language code defines a “CarCounter” class, and within the class, a “builder, eraser, and integer variable”. Outside of class, the scope resolution operator is used to define the constructor and assign a value of “0” in the integer variable. In the above code, the scope resolution operator is used, to define a destructor and within this cout function, prints a message. In the main mode, the class object is created, which automatically calls its builder and class destroyers.
Leave a Reply