Question: Define a class called Odometer that will contain member variables to define the number of miles driven, the number of gallons, and the fuel efficiency
Define a class called Odometer that will contain member variables to define the number of miles driven, the number of gallons, and the fuel efficiency (miles per gallon). The class should have a default constructor that will initialize all the variables to zero. It should also have a constructor that will take the number of miles driven and the number of gallons as parameters. This constructor will calculate the miles per gallon. There will be a function that can add a trip and a function to check mileage. Include a function that will print out the information from the function. Write a main program that will test the class. You should create at least three trips and make sure all of the member functions are executed and work properly. Put your class definition in odometer.hpp. Your member functions should be in odometer.cpp, and your main function that implements and tests the class should be in main.cpp. Turn in all three files and a makefile. driven - integer number gallons - should be able to hold a fractional number miles per gallon - should be able to hold a fractional number Default constructor - zeros out all of the variables Constructor - takes the number of gallons and number of miles and calculates miles per gallon - replaces previous values Add trip - takes the number of gallons and number of miles and adds it to the previous values, calculating the new miles per gallon for the total trip Check mileage - Given a number of gallons as a parameter, based on the miles per gallon in the class will return how many miles can be driven. Print - prints out the miles, gallons, and miles per gallon Test at least 3 trips The following declarations should be able to be made: Odometer od: Odometer od1 (10, 100): Sample output to check miles per gallon Miles driven: 100 Gallons Used: 10 Miles Per Gallon: 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
