Question: Car Class. Write a declaration for a class named Car with two private member variables: double mass, double velocity. ii ) Write set and get

Car Class.
Write a declaration for a class named Car with two private member variables: double mass, double velocity.
ii)
Write set and get functions for m and v, and a function named getMoment um () that returns the momentum of the vehicle. Use m*v for the momentum.
11i) Add a default constructor that initializes m and v to 0 and an overloaded constructor that takes double parameters for m and v.
iv) Write your accessors and mutators inline (within the class declaration), but write the getMomentum () function outside of the declaration using the scope resolution operator (double Car:: getMomentum ()).
v)
In main, construct a Car pointer on the heap using new (that is dynamically allocate memory on the the heap))with a mass of 1000 and a velocity of 100. Use the arrow operator to call getMomentum () and output the Car's momentum.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!