Define a class called Odometer that will be used to track fuel and mileage for an automotive vehicle. Include private member variables to track the miles driven and the fuel efficiency of the vehicle in miles per gallon. The class should have a constructor that initializes these values to zero. Include a member function to reset the odometer to zero miles, a member function to set the fuel efficiency, a member function that accepts miles driven for a trip and adds it to the odometer’s total, and a member function that returns the number of gallons of gasoline that the vehicle has consumed since the odometer was last reset. Use your class with a test program that creates several trips with different fuel efficiencies.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
c++
Define a class called Odometer that will be used to track fuel and mileage for
an automotive vehicle. Include private member variables to track the miles
driven and the fuel efficiency of the vehicle in miles per gallon. The class
should have a constructor that initializes these values to zero. Include a
member function to reset the odometer to zero miles, a member function
to set the fuel efficiency, a member function that accepts miles driven for a
trip and adds it to the odometer’s total, and a member function that returns
the number of gallons of gasoline that the vehicle has consumed since the
odometer was last reset. Use your class with a test
with different fuel efficiencies.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images