Question

The assignment is to write a program in unix using C++ environment Car Instrument Simulator For this assignment you w...

The assignment is to write a program in unix using C++ environment

Car Instrument Simulator

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. Programming Challenges 889

– 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.

1 0
Add a comment Improve this question Transcribed image text
Answer #1

// Main.cpp
#include
#include "FuelGauge.h"
#include "Odometer.h"
using namespace std;

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

for (int i = 0; i < 15; i++)
fuel.incrementFuelTank();

while (fuel.getCurrentAmountOfFuel() > 0)
{
odm.incrementcurrentMileage();
cout << "Mileage: " << odm.getCurrentMileage() << endl;
cout << "Fuel level" << fuel.getCurrentAmountOfFuel() << " gallons" << endl;
}

return 0;
}

// FuelGauge.h
using namespace std;

#ifndef FUELGAUGE_H
#define FUELGAUGE_H

class FuelGauge
{
private:
int currentAmountOfFuel;
public:
FuelGauge(int gallons)
{
currentAmountOfFuel = gallons;
}

int getCurrentAmountOfFuel() const
{
return currentAmountOfFuel;
}
void incrementFuelTank()
{
if (currentAmountOfFuel< 15)
currentAmountOfFuel++;
}
void decrementFuelTank()
{
if (currentAmountOfFuel > 0)
currentAmountOfFuel--;
}
};

#endif

// Odometer.h
#include "FuelGauge.h"
using namespace std;

#ifndef ODOMETER_H
#define ODOMTER_H

class Odometer
{
private:
int currentMileage;
FuelGauge *fuelG;
public:
Odometer(int miles, FuelGauge *f)
{
currentMileage = miles;
fuelG = f;
}

int getCurrentMileage()
{
return currentMileage;
}
void incrementcurrentMileage()
{
if (currentMileage < 999999)
currentMileage++;
if (currentMileage == 999999)
currentMileage = 0;
}
void decrementcurrentMileage()
{
if (currentMileage > 24)
currentMileage--;
}
};

#endif

Add a comment
Know the answer?
Add Answer to:
The assignment is to write a program in unix using C++ environment Car Instrument Simulator For this assignment you w...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Car Instrument Simulator

    Car Instrument SimulatorFor this assignment, you will design a set of classes that work together to simulate a car’s fuel gauge andodometer. The classes you will design are the following: The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are as follows:o To know the car's current amount of fuel, in gallons.o To report the car s current amount of fuel, in gallons.o To be able to increment the amount of fuel by I gallon. This simulates...

  • Assignment 4 Due Mar 22 by 11:59pmPoints 100 Submitting a file upload A4 OOP 2 "Car...

    Assignment 4 Due Mar 22 by 11:59pmPoints 100 Submitting a file upload A4 OOP 2 "Car Instrument Simulator" Access A4 from pdf assignment file & Turn in the following files: a4main.java FuelGauge.java Odometer.java program compile and run screenshots design document (including UML) A4 10. Car Instrument Simulator 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 following: · The Pue|Gauge Class:...

  • For this assignment, you will design tow classes that work together to simulate a car's fuel...

    For this assignment, you will design tow classes that work together to simulate a car's fuel gauge and odometer. The classes you will design are the following: 1. 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 one gallon. This simulates putting fuel in the car....

  • In JAVA In this assignment you will use a class Car to represent a car that travels to various de...

    In JAVA In this assignment you will use a class Car to represent a car that travels to various destinations. Your car has a fuel economy rating of 32.3 miles per gallon. The gas tank holds 19.5 gallons. Your program will need to simulate two trips: 1) BC to Yosemite Valley, and 2) BC to Washington, D.C.. For each trip you will start with a full tank of gas. The output should look as follows. Trip one: Bakersfield College to...

  • Parking Ticket Simulator C++ HELP PLEASE

    For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should designare:• The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are:o To know the car’s make, model, color, license number, and the number of minutes that the car has been parked• The ParkingMeter Class: This class should simulate a parking meter. The class’s only responsibility is:o To know the number...

  • Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment =====================...

    Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment ===================== For this assignment you will create a set of classes from scratch (no provided class files for this assignment) that work together to simulate a police officer issuing a parking ticket. You should design the following classes / functionality within them: ===================== ParkedCar.java: ===================== This class should simulate a parked car. The class's responsibilities are as follows: - To store the car's make, model,...

  • python code DC Final Project Implement a class Car with the following properties. A car has...

    python code DC Final Project Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. The following two lines are written in a File called FuelEffic.txt (you have to read these from the txt file) Miles per gallon: 20 Tank Size (in gallons): 25 Therefore, based on these...

  • I did a program in computer science c++. It worked fine the first and second time...

    I did a program in computer science c++. It worked fine the first and second time when I ran the program, but suddenly it gave me an error. Then, after a few minutes, it started to run again and then the error showed up again. This is due tonight but I do not know what is wrong with it. PLEASE HELP ME! Also, the instruction for the assignment, the code, and the error that occurred in the program are below....

  • In C++ program Fishing Game Simulation   For this assignment, you will write a program that simulates a fishing game. In this game, a six-sided die is rolled to determine what the user has caught. Eac...

    In C++ program Fishing Game Simulation   For this assignment, you will write a program that simulates a fishing game. In this game, a six-sided die is rolled to determine what the user has caught. Each possible item is worth a certain number of fishing points. The points will not be displayed until the user has finished fishing, and then a message is displayed congratulating the user depending on the number of fishing points gained.   Here are some suggestions for the...

  • == Programming Assignment == For this assignment you will write a program that controls a set...

    == Programming Assignment == For this assignment you will write a program that controls a set of rovers and sends them commands to navigate on the Martian surface where they take samples. Each rover performs several missions and each mission follows the same sequence: deploy, perform one or more moves and scans, then return to base and report the results. While on a mission each rover needs to remember the scan results, in the same order as they were taken,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT