IN C++ Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Provide another parameterized constructor which takes both efficiency and fuel as parameters. Also supply methods getGasInTank, returning the current amount of gasoline in the fuel tank. getEfficiency() return the efficiency of car. setGasInTank(double fuel), to add gasoline to the fuel tank. setEfficiency(double efficiency) Supply a method Drive () that simulates driving the car for a certain distance, reducing the amount of gasoline in the fuel tank according to its efficiency. Sample usage: Car myHybrid (50); // 50 miles per gallon myHybrid.addGas(20); // Tank 20 gallons myHybrid.Drive(100); // Drive 100 miles double gasLeft = myHybrid.getGasInTank(); // Get gas remaining in tank Supply a main method that tests all methods of the class.
IN C++
Implement a class Car with the following properties.
A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank.
The efficiency is specified in the constructor, and the initial fuel level is 0.
Provide another parameterized constructor which takes both efficiency and fuel as parameters.
Also supply methods
getGasInTank, returning the current amount of gasoline in the fuel tank.
getEfficiency() return the efficiency of car.
setGasInTank(double fuel), to add gasoline to the fuel tank.
setEfficiency(double efficiency)
Supply a method Drive () that simulates driving the car for a certain distance, reducing the amount of gasoline in the fuel tank according to its efficiency.
Sample usage:
Car myHybrid (50); // 50 miles per gallon
myHybrid.addGas(20); // Tank 20 gallons
myHybrid.Drive(100); // Drive 100 miles
double gasLeft = myHybrid.getGasInTank(); // Get gas remaining in tank
Supply a main method that tests all methods of the class.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images