write a c++ program
A class called car (as shown in the class diagram) contains: o Four private variables: carId (int), carType (String), carSpeed (int) and numOfCars (int). numOfCars is a static counter that should be Incremented whenever a new Car object is created. Decremented whenever a Car object is destructed. o Two constructors (parametrized and copy constructor) and one destructor. o Getters and setters for the Car type, ID, and speed. And static getter function for numOfCars. o All member functions that do not modify data members should be constant. o A function print() that prints the details of object.
Write the main function that uses car class as follows: Print out the number of available cars. Declare 3 objects of type car. Ask the user to enter the details of these objects. Print out the details of the three objects. Print out the Car ID of which is speeder. Print out the number of available cars. Add a new function called newCarthat receive the second object as parameter. User the Psuecode below to write the function body: void newCar( ob: car){ Declare new object of type car as a copy of ob. Print the number of available cars. } Call the function in the main. Print out the number of available cars.
class car
{
private:
int carId;
string carType;
int carSpeed;
static int numOfCars;
public:
car(int Id, string Type, int Speed)
{
cin>>Id;
cin>>Type;
cin>>Speed;
carId=Id;
carType=Type;
carSpeed=Speed;
numofCars++;
}
car( car &c2)
{
carId=c2.cardId;
carType=c2.carType;
carSpeed=c2.carSpeed;
}
~car()
{
numofCars--;
}
void print(int carId,string carType, int carSpeed)
{
cout<<carId;
cout<<carType;
cout<<carSpeed;
}
void newCar(car c)
car c4=c;
cout<<numofCars;
};
int main()
{
car c1,c2,c3;
c1.print();
c2.print();
c3.print();
cout<<"the no of available cars are"<<numofCars;
newCar(c2);
}
Get Answers For Free
Most questions answered within 1 hours.