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

Hello, need help implementing the following classes in c++. Please read the comm

ID: 655662 • Letter: H

Question

Hello, need help implementing the following classes in c++. Please read the comments in order to correctly implement the classes.

class Tank

{

Public:

Tank(float); // creates a tank with certain capacity (taken from parameter)

virtual ~Tank(); // does nothing

void consumeFuel(float); //Decrements fuel by a value specified in the parameter. It also checks

// if the fuel gets to 0, in which case it sets empty to true.

float getFuel(); // fuel reading

virtual void refuel();

bool isEmpty();

int getNumTanks(); //In some vehicles there can be more than one gas tank. This funcion returns

// the number of tanks for that vehicle.

float getTankCapacity();

void setFuel(float fl);

protected:

static int numTanks;

const float tankCapacity;

float fuel;

bool empty;

};

class Engine

{

public:

Engine(int);

~Engine(){};

void setTrip(int tr);

int getTrip();

bool isStarted();

void start(Tank &);

void stop();

protected:

bool started;

int trip, numCyl;

};

The constructor in this class takes the number of cylinders from the argument and assigns it to the corresponding number of the class. It then initializes all other members to 0 or false as appropiate. The start function can only start the engine if the tank is not empty. The stop function cannot stop the engine that has not been started.

class Vehicle

{

public:

~Vehicle(){}; // does nothing

bool startEngine(); // This fuction checks for the number of occupants. it starts the engine only if the number of occupants is > 0; in which case, it calls the Engine's method to start and passes the tank object there.

void stopEngine(); // stops the engine.

void setOccupants(int occ);

int getOccupants();

bool engineStatus();// Checks and returns engine status if the engine was started.

double fuelMeter();

void addFuel(); // should call refuel method of the tank.

bool moving(int &, float); // Moves the car, which can only move if the engine was started, tanks are not empty, and trip is not complete. If these conditions are satisfied, function will enter a loop to move the car. In than loop, the odometer gets incremented, fuel gets decremented (by callin ghte method of tank to consume fuel. When trip gets completed or tank gets empty, the loop should exit. Function should call stop method of engine and output statistics of the trip

protected:

Vehicle(int occ, float tankCapacity, int numCyl);

int occupants;

Engine engine;

Tank tank;

private:

Vehicle(); // does nothing

};

Constructor creates a vehicle with number of occupants in it, creates a tank with capacity, and creates engine with number of cylinders. These parameters are taken from the cosntructor of the derived class, when it is called. Vehicle(int occ, float tankCapacity, int numCyl)

class policeCar : public Vehicle

{

public:

policeCar(); // Constructor takes no parameters but we need to pass parameters to the base class Vehicle.

~policeCar();

void trafficStop(Vehicle &);

};

Class policeCar has only one method, which is to do a traffic stop. When a traffic stop is made, it results in sttoping the vehicle's engine and decrementing the number of vehicle's occupants. After the traffic stop, the vehicle can move, but the vehicle should not start the engine if there is no occupants in it.

class familyCar

Here we need to declare

enum Status{notReady, ready, disabled} and

class OnStar

{

pubilc:

OnStar();

~OnStar();

Status onStarActivate();

Status status;

};

OnStar class has only one method, which is onStarActivate. This method should ask the user if help is needed, if so, return status disabled; otherwise, it returns status ready.

class familyCar

{

friend class OnStar;

friend Status onStar(FamilyCar &);

public:

familyCar(int, float, int = 4); //Creates a vehicle with default number of cylinders in engine to 4

~familiyCar(){}; // does nothign

void stopCar(); // stops the vehicle's engine.

Status airbag(OnStar &); // Calls the OnStar method onStarActivate. If method returns status disabled, the vechicle should stop.

};

class lightTruck : public Vehicle

{

public:

lightTruck(int, float, int);

~lightTruck(){};

int getLoad();

void setLoad(int);

protected:

int load;

};

class heavyTruck : public lightTruck

{

public:

heavyTruck(int, float, int);

~heavyTruck(){};

double fuelMeter(); // should give the reading of both tanks, the total of two tanks, and the current level of the working tank.

void refuel(); // should fill each tank, but not beyond its capacity. After the refuel, both tanks should be filled.

void switchTanks();// allows the user to switch tanks. The user can only swicth to the tanks that is not empty. If the user swicthes to an empty tank, the engine will stop and the OnStar should activate.

private:

Tank tank2;

};

Here the light truck is based an a family car. In addition to the family car, the light truck adds a load property. The heavy truck adds additional fuel tank, and because of that, it should override methods fuelMeter() and refuel(), inherited from Vehicle. Each type of vehicle should have different mileage.

The full implementation of these clasess should allow the user to launch a family car and a heavy truck(with load) for a trip of 100 miles. While on that trip, the vehicles got stopped by the police car( each vehicle at random miles). Both vehicles had their airbag activated (due to factory defect) which caused the OnStar system to activate and ask for the status. At the end of the trip, the program should output the statictics, which should include when the vehicles were stop by the police, when the OnStar was activated, how many times the vehicles stopped to refuel.

The implementation of the classes should work with the following test driver program:

int main()

{

Status status = ready;

bool ready = true;

bool response = false;

int trip = 50;

int i = 0;

familyCar fc(0, 12.2f, 4);

policeCar trooper;

fc.startEngine()

fc.stopEngine();

fc.setOccupants(4);

fc.startEngine();

fc.startEngine()

while(trip > 0 && status == ready)

{

if (fc.moving(trip,2))

{

if (!fc.engineStatus())

if(fc.fuelMeter() <= 2.0)

fc.addFuel();

}

if(trip <= 30 && !response)

{

reponse = true;

status = fc.airbag();

}

if (trip <= 20)

{

trooper.trafficStop(fc);

}

}

return 0;

}

Explanation / Answer

You need to mention the class header first because classes are not different .Class definition are need to be mention in header in order to use the facilities to reuse in multiple fie or multiple project .Class definition in header file must have the smae name as class so that it can be accesed easily

You need to use friend function  is a function that can access the private members of a class as though it were a member of that class. In all other regards, the friend function is just like a normal function. A friend function may or may not be a member of another class. To declare a friend function, simply use the friend keyword in front of the prototype of the function you wish to be a friend of the class. It does not matter whether you declare the friend function in the private or public section of the class.

You need to use Friend classes is also possible to make an entire class a friend of another class. This gives all of the members of the friend class access to the private members of the other class.is also possible to make an entire class a friend of another class. This gives all of the members of the friend class access to the private members of the other class.

Dr Jack
Hire Me For All Your Tutoring Needs
Quick quotes • Clear explanations • Study support
Chat Now And Get Quote