Odometer Functions

can someone walk me through the steps to create this:

Create a program that uses a class called Odometer to calculate the gallons left in a cars tank after a series of trips. The class Odometer has the following data members: mpg, tankGallons, and milesDriven all of type double. Also there is a constructor with two parameters for initializing the mpg and the tankGallons. This constructor shou initialize the milesDriven to zero. There is a member function to add miles, addMiles(double miles), which will accumulate miles. Finally the class should have a function to return the gallons left in the tank after all the miles were accumulated.

The main() function should ask the user for mpg and initial number of gallons in the tank. Acceptable values for mpg are 5-70, and for gallons, 10-30. Must implement input validation for these values from user. After instantiating the Odometer object, your program should run through a series of inputs for collecting miles for different trips and accumulating them using the Odometer object. When there are no more trips to input, the program should display the gallons left in the tank using the Odometer object.

Sample run:
Enter gallons in tank (10-30): 100
Error: Enter gallons in tank (10-30): 20
Enter fuel efficiency (MPG) (5-70): 100
Error: Enter fuel efficiency (MPG) (5-70): 50
Enter miles for trip (-1 to finish, no more trips): 200
Enter miles for trip (-1 to finish, no more trips): 150
Enter miles for trip (-1 to finish, no more trips): 50
Enter miles for trip (-1 to finish, no more trips): -1
Gallons left in the tank: 12 gallons
Last edited on
Write down on a piece of paper what the data members are.

Determine how users will use the class.

Write out the formulas to determine mpg, etc.

Now...

Each formula is a public function in the class, which manipulates the data members that you wrote out earlier.

The data members are private. The formulas are public.
Topic archived. No new replies allowed.