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 1. 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
15 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 1 mile. When the maximum mileage of 999,999 miles is exceeded it
will reset the current mileage to 0. For every 24 miles, the Odometer class will decrease the
FuelGauge object by 1 gallon to simulate the cars fuel economy as 24 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 2321 Lab 10 Spring 2024
//DO NOT MODIFY THIS SECTION
#include
#include "FuelGauge.h"
#include "Odometer.h"
using namespace std;
int main()
{
//ifstream ifile;
Odometer odom(999990); //Create and initialize
FuelGauge gauge(0); //Create and initialize to zero
odom.report(); //Display info from odom
gauge.report(); //Display info from gauge
gauge.addToTank(1); //Add one gallon
gauge.report(); //Display new info from gauge
while( gauge.getGallons()>0)//Repeat while we still have fuel
{
odom.advance(1, gauge ); //Advance 1 mile. Include reference to gauge
odom.report(); //Report info from odom
gauge.report(); //Report info from gauge
}
return 0;
}
//ADD YOUR CODE FROM HERE
Compare main() with the output to understand the operation.
Output:
Mileage: 999990
Fuel: 0
EMPTY!
Adding fuel, going from 0 to 1
Fuel: 1
Mileage: 999991
Fuel: 1
Mileage: 999992
Fuel: 1
Mileage: 999993
Fuel: 1
Mileage: 999994
Fuel: 1
Mileage: 999995
Fuel: 1
Mileage: 999996
Fuel: 1
Mileage: 999997
Fuel: 1
Mileage: 999998
Fuel: 1
Mileage: 999999
Fuel: 1
Mileage: 0
Fuel: 1
Mileage: 1
Fuel: 1
Mileage: 2
COSC 2321 Lab 10 Spring 2024
Fuel: 1
Mileage: 3
Fuel: 1
Mileage: 4
Fuel: 1
Mileage: 5
Fuel: 1
Mileage: 6
Fuel: 1
Mileage: 7
Fuel: 1
Mileage: 8
Fuel: 1
Mileage: 9
Fuel: 1
Mileage: 10
Fuel: 1
Mileage: 11
Fuel: 1
Mileage: 12
Fuel: 1
Mileage: 13
Fuel: 1
Mileage: 14
Fuel: 0
EMPTY!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!