Question

write a c++ program A class called car (as shown in the class diagram) contains: o...

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.

Homework Answers

Answer #1

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);

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will be filled with Car objects. It will call the displayMenu method to display the menu. Use a sentinel-controlled loop to read the user’s choice from stdin, call the appropriate method based on their choice, and redisplay the menu by calling displayMenu. Be sure to use the most appropriate statement for this type of repetition. displayMenu Parameters:             none Return value:          none Be sure to use...
Q.Write a program that shows a class called gamma that keeps track of how many objects...
Q.Write a program that shows a class called gamma that keeps track of how many objects of itself there are. Each gamma object has its own identification called ID. The ID number is set equal to total of current gamma objects when an object is created. Test you class by using the main function below. int main()    {    gamma g1;    gamma::showtotal();    gamma g2, g3;    gamma::showtotal();    g1.showid();    g2.showid();    g3.showid();    cout << "----------end...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class Test { int a, b; Test(int i, int j) { a = i; b = j; } void meth(Test s) { s.a *= 2; s.b /= 2; } } class demo { public static void main(String args[]) { Test ob = new Test(15, 20); System.out.println("Before call: " + ob.a + " " + ob.b); ob.meth(ob); System.out.println("After call: " + ob.a + " " +...
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
THIS IS A JAVA PROGRAM THAT NEEDS TO BE WRITTEN Write a recursive method void reverse(ArrayList<Object>...
THIS IS A JAVA PROGRAM THAT NEEDS TO BE WRITTEN Write a recursive method void reverse(ArrayList<Object> obj) that reverses an ArrayList of any type of object. For example, if an ArrayList held 4 strings: "hi", "hello", "howdy", and "greetings" the order would become "greetings", "howdy", "hello", and "hi". Implement a recursive solution by removing the first object, reversing the ArrayList consisting of the remaining Objects, and combining the two. Use the following class ArrayListReverser to write and test your program....
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...
Program C++ (use visual studio) Q1. What default copy constructor does the compiler insert in the...
Program C++ (use visual studio) Q1. What default copy constructor does the compiler insert in the following class? class Student { string name; string id; double grade; }; =========================== Q2 .What is the factor transfer method used when the f() function is called from? void f(int n[]); int main() { int m[3]= {1, 2, 3}; f(m); } ================================== Q3. Write a program that produces a bigger() with a prototype as shown below and outputs a large value by inputting two...
we defined, implemented, and tested a class Time. In this lab, we will continue working with...
we defined, implemented, and tested a class Time. In this lab, we will continue working with the Time class. A. Separate the class definition and class implementation from the client program. Move the class definition into a header file named Time.h and move the class implementation into a cpp file named Time.cpp. Use preprocessor directive to include header files as needed. B. Modify the Time class as follows: 1. Replace the default constructor and overloaded constructor with a constructor with...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT