Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program as described below Description: Define a class called Odometer that will contain member variables to define the number of miles driven,

Write a C++ program as described below

Description:

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.

Class variable definitions:

miles driven integer number

gallons should be able to hold a fractional number

miles per gallon should be able to hold a fractional number

Class member functions

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

Requirements:

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago