Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Car class having three private member variables called tank, speed and model (model is string). Write public functions called pumpGas, goFast and display.

Write a Car class having three private member variables called tank, speed and model (model is string). Write public functions called pumpGas, goFast and display. The function pumpGas gets an integer for the amount of gas that must be pumped. That value needs to be added to tank (no more than 20 gallons). It must return the amount of gas that is purchased ($4 per gallon). The function goFast should increase the speed by 5 each time it is called. Also write the getters and setters for this class.

Modify the above class to enforce principle of least privilege by writing const in the header file where needed.

Write the constructor to initialize the tank to 5, the speed to 0 and model to new car.

Write the main code to test the above class.

Then:

Write the operator overloading for the class Car for the following operators: The operator + should only add the tanks together.

The operator should subtract the tanks and calculate the absolute difference of the two cars.

The operator post decrement operator must subtract 1 from speed but the speed should not become less than 0. In other words, if the speed is 0 and you perform post decrement, it should keep it as zero.

The operator pre decrement should subtract 1 from speed as well.

In c++

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

Understand the nature of authority, power, and empowerment

Answered: 1 week ago

Question

Describe several uses for a position description.

Answered: 1 week ago