Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment you will design a set of classes that work together to simul

ID: 3784943 • Letter: F

Question

For this assignment you will design a set of classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are:

    The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are

        To know the car’s current amount of fuel, in gallons.

        To report the car’s current amount of fuel, in gallons.

        To be able to increment the amount of fuel by 1 gallon. This simulates putting fuel in the car. (The car can hold a maximum of 15 gallons.)

        To be able to decrement the amount of fuel by 1 gallon, if the amount of fuel is greater than 0 gallons. This simulates burning fuel as the car runs.

    The Odometer Class: This class will simulate the car’s odometer. Its responsibilities are:

        To know the car’s current mileage.

        To report the car’s current mileage.

        To be able to increment the current mileage by 1 mile. The maximum mileage the odometer can store is 999,999 miles. When this amount is exceeded, the odometer resets the current mileage to 0.

        To be able to work with a FuelGauge object. It should decrease the FuelGauge object’s current amount of fuel by 1 gallon for every 24 miles traveled. (The car’s fuel economy is 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 car’s current mileage and amount of fuel.

Mileage: 348
Fuel level: 1.00 gallons
------------------------------
Mileage: 349
Fuel level: 0.96 gallons
------------------------------
Mileage: 350
Fuel level: 0.92 gallons
------------------------------
Mileage: 351
Fuel level: 0.88 gallons
------------------------------
Mileage: 352
Fuel level: 0.83 gallons
------------------------------
Mileage: 353
Fuel level: 0.79 gallons
------------------------------
Mileage: 354
Fuel level: 0.75 gallons
------------------------------
Mileage: 355
Fuel level: 0.71 gallons
------------------------------
Mileage: 356
Fuel level: 0.67 gallons
------------------------------
Mileage: 357
Fuel level: 0.63 gallons
------------------------------
Mileage: 358
Fuel level: 0.58 gallons
------------------------------
Mileage: 359
Fuel level: 0.54 gallons
------------------------------
Mileage: 360
Fuel level: .5 gallons
------------------------------

etc. to 0

Explanation / Answer

// Main.cpp
#incluude <iostream>
#include "Fuel Gauge.h"
#include "Odo meter.h"
using name space std;

int main()
{
Fuel Gauge fuel(1);
Odometer odm(0, &fuel);

for (int i = 0; i < 15; i++)
fuel.increment Fuel Tank();

while (fuel.get Current Amount OfFuel() > 0)
{
odm.increment current Mileage();
cout << "Mileage: " << odm.get Current Mileage() << endl;
cout << "Fuel level" << fuel.get Current Amount Of Fuel() << " gallons" << endl;
}

return 0;
}

// Fuel Gauge.h
using name space std;

#ifndef FUEL GAUGE_H
#define FUEL GAUGE_H

class Fuel Gauge
{
private:
int current Amount OfFuel;
public:
Fuel Gauge(int gallons)
{
current Amount Of Fuel = gallons;
}

int get Current Amount Of Fuel() const
{
return current Amount Of Fuel;
}
void increment Fuel Tank()
{
if (current Amount Of Fuel< 15)
current Amount Of Fuel++;
}
void decrement Fuel Tank()
{
if (current Amount Of Fuel > 0)
current Amount Of Fuel--;
}
};

#endif

// Odo meter.h
#include "Fuel Gauge.h"
using name space std;

#ifndef ODOMETER_H
#define ODOMTER_H

class Odometer
{
private:
int current Mileage;
Fuel Gauge *fuelG;
public:
Odometer(int miles, Fuel Gauge *f)
{
current Mileage = miles;
fuelG = f;
}

int get Current Mileage()
{
return current Mileage;
}
void increment current Mileage()
{
if (current Mileage < 999999)
current Mileage++;
if (current Mileage == 999999)
current Mileage = 0;
}
void decrement current Mileage()
{
if (current Mileage > 24)
current Mileage--;
}
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote