Question: Declare and define a C++ class called odometer that will track miles driven and gallons used by a vehicle. The class should have member variables

Declare and define a C++ class called odometer that will track miles driven and gallons used by a vehicle. The class should have member variables for "total miles driven" and "gallons consumed".

Include the following mutator functions in your class:

  • miles driven and gallons of gas consumed
  • reset odometer to zero
  • reset gallons

Include the following accessor functions in your class:

  • return fuel efficiency in miles per gallon (MPG)
  • return odometer reading (total miles driven since the last reset)

There should be a total of 5 functions (3 mutator, 2 accessor and be sure to label these accordingly), and your private class should have the following:

int setMPG double gallons double miles double MPG

Your class declaration should be in a header file titled "odometer.h" with inclusion guards. You functions and implementation should be in a cpp file titled "odometer.cpp".

You should have a driver (main) program in a cpp file title "main" to test your class.

Properly label/comment out your accessors and mutators. Make sure you have three runs of output. Once for when you track the first trip, once for when a second trip was added onto the first trip, and once for after you've reset it.

Output should include fuel efficiency, odometer reading (miles driven), and gallons consumed.

*** You may make a default constructor OR rely on the automatically created default constructor. Designate which one you chose with a comment. ***

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 Databases Questions!