Computers and Technology
04.08.2020 13:02
206
468
9
Solved by an expert

Write a destructor for the CarCounter class that outputs the following. End with

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;
}
Show Answers
rebekahlm
rebekahlm
5,0(9 marks)

Following are the code to this question:

CarCounter::~CarCounter()//Defining destructor CarCounter

{

cout << "Destroying CarCounter\n";//print message Destroying CarCounter

}

Explanation:

Following are the full program to this question:

#include <iostream>//Defining header file

using namespace std;

class CarCounter //Defining class CarCounter

{

public:

CarCounter();//Defining constructor CarCounter

~CarCounter();//Defining destructor CarCounter

private:

int carCount;//Defining integer variable carCount

};

CarCounter::CarCounter()//declaring constructor  

{

carCount = 0;//assign value in carCount variable

return;//using return keyword

}

CarCounter::~CarCounter()//Defining destructor CarCounter

{

cout << "Destroying CarCounter\n";//print message Destroying CarCounter

}

int main() //Defining main method

{

CarCounter* parkingLot = new CarCounter();//Defining class object parkingLot

delete parkingLot;//

return 0;

}

In the given C++ language code, a class "CarCounter" is defined, and inside the class, a "constructor, Destructors, and an integer variable" is defined.  Outside the class, the scope resolution operator is used to define the constructor and assign value "0" in the integer variable.  In the above-given code, the scope resolution operator, to define destructor and inside this cout function is used, which prints a message.  In the main method, the class object is created, which automatically calls its class constructor and destructors.  
tushema1
tushema1
4,9(51 marks)
Use this web site 

Popular Questions about the subject: Computers and Technology

You are to write a program that calculates the standard deviation...
Computers and Technology
08.06.2021 00:45
Variables are defined outside all functions and are accessible...
Computers and Technology
19.05.2021 23:23
Complexity of the function seqsearch in an array list is o(n2)....
Computers and Technology
18.06.2023 10:49
Asocket is a combination of what two things? a) power plug b)...
Computers and Technology
22.02.2023 08:47
Define and test a function myrange. this function should behave...
Computers and Technology
03.06.2020 02:54
How can i get a refund of my money back...
Computers and Technology
18.04.2022 08:10
A(n) variable is defined inside a function and is not accessible...
Computers and Technology
05.02.2022 08:12
Question 1 A programmer is writing class scheduling software...
Computers and Technology
02.06.2023 14:34
What is gaining of unauthorized access to data in a system or...
Computers and Technology
22.11.2021 14:51

New questions by subject

Answer please////////...
Mathematics
10.11.2020 16:45
Hey are u guys in any zoo/m rn ?...
Computers and Technology
28.04.2020 21:43
︎help me please ineed answer asp thankyou...
Mathematics
03.07.2020 04:59
sa iyong palagay, alin sa mga kontribusyon ng kabihasnang romano...
History
17.06.2022 20:06
If x=14 and y=7 what does k=...
Mathematics
04.01.2020 20:50
#
#
#
#
# #

We expand our knowledge with many expert answers