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.
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++ 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....
Using the Java programming language: Create and implement a class Car that models a car. A...
Using the Java programming language: Create and implement a class Car that models a car. A Car is invented to have a gasoline tank that can hold a constant max of 12.5 gallons, and an odometer that is set to 0 for a new car. All cars have an original fuel economy of 23.4 miles per gallon, but the value is not constant. Provide methods for constructing an instance of a Car (one should be zero parameter, and the other...
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality:...
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality: Configures pin RA2 of the PIC24to be an output to control an attached LED. Configures pin RB13 of the PIC24 to be an input to read the value on an attached switch (this switch will connect to ground when pressed). Configures pin RB13 to use the internal pull-up resistor. After configuration, the LED will be "off" when the push-button is pressed, and "on" when...
Use inheritance to implement the following classes: A: A Car that is a Vehicle and has...
Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called the...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT