Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started