Question: C + + Tossing Coins for a Dollar WRITE FULL CODE IN ANSWER BOX Problem 1 . Car Instrument Simulator Design a set of classes
C Tossing Coins for a Dollar WRITE FULL CODE IN ANSWER BOX
Problem Car Instrument Simulator
Design a set of classes that work together to simulate a cars fuel gauge and odometer.
The FuelGauge class will store the cars current amount of fuel in gallons, report the cars current
amount of fuel, indicate when the fuel tank is empty, and refuel the cars fuel tank to a maximum of
gallons. The Odometer class will be a friend of the FuelGauge class, so it will have access to
private members of the FuelGauge class.
The Odometer class will store the cars current mileage, and report the cars current mileage. As well,
it will increment the mileage by mile. When the maximum mileage of miles is exceeded it
will reset the current mileage to For every miles, the Odometer class will decrease the
FuelGauge object by gallon to simulate the cars fuel economy as miles per gallon.
Demonstrate the classes by creating instances of each. Simulate filling the car up with fuel, and then
run a loop that increments the odometer until the car runs out of fuel. During each loop iteration, print
the cars current mileage and amount of fuel.
USE THE NEXT TEMPLATE MANDATORY FOR THE MAIN FUNCTION
COSC Lab Spring
DO NOT MODIFY THIS SECTION
#include
#include "FuelGauge.h
#include "Odometer.h
using namespace std;
int main
ifstream ifile;
Odometer odom; Create and initialize
FuelGauge gauge; Create and initialize to zero
odom.report; Display info from odom
gauge.report; Display info from gauge
gauge.addToTank; Add one gallon
gauge.report; Display new info from gauge
while gauge.getGallonsRepeat while we still have fuel
odom.advance gauge ; Advance mile. Include reference to gauge
odom.report; Report info from odom
gauge.report; Report info from gauge
return ;
ADD YOUR CODE FROM HERE
Compare main with the output to understand the operation.
Output:
Mileage:
Fuel:
EMPTY!
Adding fuel, going from to
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
COSC Lab Spring
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
Mileage:
Fuel:
EMPTY!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
