Question

In: Computer Science

(Using C++ create a Car Instrument Simulator) Car Instrument Simulator Create the following classes: Car, Odometer,...

(Using C++ create a Car Instrument Simulator)

Car Instrument Simulator

Create the following classes: Car, Odometer, FuelGauge.

The Car class allows for the instantiation of a Car object.

The Car object will contain (via composition) an Odometer object, and a FuelGauge object.

The Car object will also include "make", "model", and "color" as string properties (instance variables).

In the Car constructor method, you will create a FuelGauge object, passing 15 as an argument into the FuelGauge constructor indicating the number of gallons.

In the Car constructor method, you will create an Odometer object, passing 0 and the address of the FuelGauge object as arguments to the Odometer constructor, indicating the number of miles driven and the address of the FuelGauge object respectively.

The Car class will have a "drive(int miles)" method.

The Odometer object will contain a pointer to a FuelGauge object.

The Odometer object will contain a "milesDriven" instance variable.

The Odometer object will have an "incrementMileage()" method.

The implementation of the Odometer incrementMileage method will be such that if the fuel level is greater than zero, the Odometer increments its mileage instance variable by 1. Also, at every interval of GAS_MILEAGE (a constant that specifies the miles per gallon), and if the FuelGauge's fuelLevel is greater than zero, the Odometer will call the decreaseFuelLevel() method on the FuelGauge object.

The FuelGauge object will have a "decreaseFuelLevel()" method.

The FuelGauge object will contain a "fuelLevel" instance variable.The FuelGauge object will have a "getFuelLevel()" method that returns the current value of the fuelLevel instance variable.

The FuelGauge object will have a "decreaseFuelLevel(int gallons)" method.

The implementation of the FuelGauge decreaseFuelLevel method will be such that the FuelGauge decrements the fuelLevel instance variable by the specified number of gallons. Do not decrease the fuelLevel to a negative value.

The implementation of the Car "drive(int miles)" method will be such that it has a loop wherein...


while you've driven less then the number of miles specified by the "drive" method parameter value (make it 500) and the fuel level is greater than zero,call the incrementMileage method on the Odometer object.


When the car stops driving because it has run out of fuel, display the number of miles driven.

Deliverables:

7 files: a .h file for each class, a .cpp file for each class, and one .cpp file for your main function.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// FuelGuage.h

#ifndef FUELGUAGE_H
#define FUELGUAGE_H

class FuelGuage
{
public:
FuelGuage();
FuelGuage(int gallons);
void decreaseFuelLevel();
int getFuelLevel();
private:
// Declaring variables
int fuelLevel;
  
};
#endif

_____________________

// FuelGuage.cpp

#include <iostream>
using namespace std;
#include "FuelGuage.h"

void FuelGuage::decreaseFuelLevel()
{

if(fuelLevel>0)
{
fuelLevel--;
}
}
int FuelGuage::getFuelLevel()
{
return fuelLevel;
}

FuelGuage::FuelGuage(int gallons)
{
this->fuelLevel=gallons;
}
FuelGuage::FuelGuage()
{
  
}

___________________

// Odometer.h

#ifndef ODOMETER_H
#define ODOMETER_H
#include "FuelGuage.h"

class Odometer
{
public:
Odometer();
Odometer(int milesDriven,FuelGuage *fg);

void incrementMileage();
private:
// Declaring variables
FuelGuage *fg;
int milesDriven;
static const int GAS_MILEAGE=15;
};
#endif

____________________

// Odometer.cpp

#include <iostream>
using namespace std;
#include "Odometer.h"
#include "FuelGuage.h"


Odometer::Odometer(int milesDriven,FuelGuage *fg)
{
this->milesDriven=milesDriven;
this->fg=fg;
}
void Odometer::incrementMileage()
{
if(fg->getFuelLevel()>0)
{
milesDriven++;
cout<<"Mileage :"<<milesDriven<<endl;
cout<<"Fuel Level :"<<fg->getFuelLevel()<<endl;
cout<<"------------------------------------"<<endl;
}
if(milesDriven%GAS_MILEAGE==0)
{
fg->decreaseFuelLevel();
}
}

Odometer::Odometer()
{
  
}

_______________________

// Car.h

#ifndef CAR_H
#define CAR_H

#include "FuelGuage.h"
#include "Odometer.h"

class Car
{
public:
Car();
void drive(int miles);
private:
// Declaring variables
FuelGuage fg;
Odometer odo;
string make;
string model;
int year;
};

#endif

________________________

// Car.cpp

#include <iostream>
using namespace std;
#include "Car.h"
#include "Odometer.h"
#include "FuelGuage.h"

Car::Car()
{
FuelGuage f(15);
this->fg=f;
Odometer odo(0,&fg);
this->odo=odo;
}

void Car::drive(int miles)
{
for(int i=1;i<=miles;i++)
odo.incrementMileage();
}

_______________________

// main.cpp

#include <iostream>
using namespace std;

#include "Car.h"
int main()
{
Car c;
c.drive(500);
return 0;
}

_________________________

Output:

_______________Could you plz rate me well.Thank You


Related Solutions

Create a C++ code for the mastermind game using classes(private classes and public classes). Using this...
Create a C++ code for the mastermind game using classes(private classes and public classes). Using this uml as a reference.
Create a dice simulator in C#. The simulator must roll the dice 6 times and it...
Create a dice simulator in C#. The simulator must roll the dice 6 times and it must add the 3 highest rolls. So say it simulates: 4 4 5 2 1 3 the total would be 13 (4+4+5=13). Repeat this 6 different times. So if the random dice simulator simulates the outcomes below it should output: 13, 13, 14, 12, 16, 12 1) 4 4 5 2 1 3 2) 2 3 6 1 3 4 3) 5 3 1...
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
Write a DFA simulator using the C++ programming language. Please refer to the following UDACITY website...
Write a DFA simulator using the C++ programming language. Please refer to the following UDACITY website if you do knot know C++. This is a free online tutorial for learning C++. Read your DFA from a textfile. First line contains a list of the final states (as integers), separated by a space. Rest of file contains the transitions in form: startstate, blank, symbol read, blank, tostate Prompt user for name of file. From there, program prompts the user for strings...
Create a Snake game project in C++ using all these which are given below. 1. Classes...
Create a Snake game project in C++ using all these which are given below. 1. Classes 2. structures 3. files ( MULTFILLING AND FILE HANDLING ) 4. loops 5. conditions 6. switch 7. functions 8. array Note: Also upload the zip file.
C++ Drink Machine Simulator Create a class that simulates and manages a soft drink machine. Information...
C++ Drink Machine Simulator Create a class that simulates and manages a soft drink machine. Information on each drink type should be stored in a structure that has data members to hold the drink name, the drink price, and the number of drinks of that type currently in the machine. The class should have an array of five of these structures, initialized with the following data. Drink Name      Cost   Number in Machine Cola       1.00   20 Root beer         ...
5.9 Online shopping cart (Java) Create a program using classes that does the following in the...
5.9 Online shopping cart (Java) Create a program using classes that does the following in the zyLabs developer below. For this lab, you will be working with two different class files. To switch files, look for where it says "Current File" at the top of the developer window. Click the current file name, then select the file you need. (1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method Build the ItemToPurchase class with the...
C++ Assignment 1: Make two classes practice For each of the two classes you will create...
C++ Assignment 1: Make two classes practice For each of the two classes you will create for this assignment, create an *.h and *.cpp file that contains the class definition and the member functions. You will also have a main file 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them. Class #1 Ideas for class one are WebSite, Shoes, Beer, Book, Song, Movie, TVShow, Computer, Bike, VideoGame, Car, etc Take your chosen class from...
Parking Ticket simulator For this assignment you will design a set of classes that work together...
Parking Ticket simulator For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: • The ParkedCar Class: This class should simulate a parked car. The class’s responsibili-ties are as follows: – 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....
parking Ticket simulator For this assignment you will design a set of classes that work together...
parking Ticket simulator For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: • The ParkedCar Class: This class should simulate a parked car. The class’s responsibili-ties are as follows: – 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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT