Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Can someone help me with this C++ code?

Create a class called "MPG" to represent fuel economy of a car. Include the following:

1) Attributes: starting odometer reading (int), ending odometer reading (int), gallons (double), number of stops (int).

2) Default constructor: all attributes are set to zero.

3) Initial value constructor. You must make sure that the ending odometer reading is greater than the starting odometer reading. If this condition is not met, output an error message and exit the program.

4) Accessors and mutators for all attributes. You must make sure that the ending odometer reading is greater than the starting odometer reading. If this condition is not met, output an error message and exit the program.

5) A method that calculates the average miles-per-gallon for the last fill-up, determines whether it's a city reading (miles per stop < 0.5), highway reading (miles per stop > 1), or combined reading (miles per stop between 0.5 and 1, inclusive), and then estimates the other two readings. Use the estimate that (city MPG) = 0.75*(combined MPG) and (combined MPG) = 0.75*(highway MPG). The output for this method must be an array with three elements (city MPG, combined MPG, and highway MPG).

The attached file contains 8 values: starting odometer reading, ending odometer reading, gallons, and number of stops for car 1, then the same sequence of quantities for car 2. Read the data and create a formatted output file that contains the read values for each car as well as each car's three calculated MPG values.

20265 20970 12.2 46

51350 51780 13.1 14

1 Answer

Relevance
Still have questions? Get your answers by asking now.