Challenge

Project 3

#include<iostream>

#include<string>

#include<vector>

#include<list>

using namespace std;

//header files

//built-in classes Cin & cout

//User defined enum as Type

enum type

{

GAS,

DISEL,

ELECTRIC

};

class Vehicle

{ //Class vehicle

protected: //Protected members

string Make,Model; //Member variables

int Year;

long int Odometer;

//Get functions to used to get make,model,year and odometer

string getmake()

{

cout<<"Make type : "<<endl;

cin>>Make;

return Make;

}

string getmodel()

{

cout<<"Model : "<<endl;

cin>>Model;

return Model;

}

int getyear()

{

cout<<"Year : "<<endl;

cin>>Year;

return Year;

}

long int getodo()

{

cout<<"Odometer reading : "<<endl;

cin>>Odometer;

return Odometer;

}

//Friend Functions declaration

friend void AddVehicle(Vehicle &add);

friend void AddList(Vehicle &list);

friend void UpdateVehicle(Vehicle &upd);

friend void RemoveVehicle(Vehicle &rem);

private:

static vector<Vehicle> vehicleList; //any modification based will reflect on all the list

};

vector<Vehicle> Vehicle::vehicleList; //storage allocation for vehicle class

//Derived Class Gas car inherited from Base class Vehicle

class Gascar:public Vehicle{};

//Derived Class Disel car inherited from Base class Vehicle

class Diselcar:public Vehicle{};

//Derived Class Electric car inherited from Base class Vehicle

class ElectricCar:public Vehicle

{

public:

int tire;

void CheckTireRotation()

{

cout<<"Tire cycles : "<<endl;

cin>>tire;

if(tire>=50000)

{

cout<<"Tire rotation needed "<<endl;

}

else

{

cout<<"Tyres are good to go"<<endl;

}

}

//Check tyre rotation Function

//Check charging staus for the electric vehicle

void CheckChargePower()

{

cout<<"Enter distance travelled : "<<endl;

cin>>Odometer;

if(Odometer>=400)

{

cout<<"Recharge battery"<<endl;

}

else

{

cout<<"Battery is good"<<endl;

}

}

//Friend functions of electric car

friend void TireRotation(ElectricCar &tire);

friend void Recharge(ElectricCar &reh);

};

//Derived Class Fuel vehicle inherited from Base class Vehicle

class Fuelvehicle:public Vehicle

{

public:

int quarts;

void CheckOil()

{

//Check oil fuction of fuel vehicle

cout<<"Enter oil level(quarts) : "<<endl;

cin>>quarts;

if(quarts<=1)

{

cout<<"Engine oil level low"<<endl;

}

else

{

cout<<"Oil level is Fine"<<endl;

}

}

//Friend function of Fuel vehicle class

friend void OilChange(Fuelvehicle &oil);

};

//Friend functions Definitions

void AddVehicle(Vehicle &list)

{

// get user to enter vehicle details

cout<<"Enter Vehicle details "<<endl;

cout<<"Make type : "<<endl;

//make of the vehicle

string make;

cin>>make;

cout<<"Model : "<<endl;

string model;

cin>>model;

cout<<"Year : "<<endl;

int year;

cin>>year;

//model of the vehicle

//year of the vehicle

cout<<"Type is (Electric, Diesel , Gas) : "<<endl;

string type;

//type of the vehicle

cin>>type;

// list all vehicles after adding a new on

cout<<"Vehicle has been added"<<endl;

cout<<" Make\t" <<make<< " model\t"<<make << " year\t" <<year<<" type\t"<<type <<endl;

}

void ListVehicle(Vehicle &list)

//List all vehicles

{

cout<<"Vehicle List:"<<endl;

cout<<"Make|\tModel\tYear\tType"<<endl;

cout<<"TATA\tNANO\t2008\tGAS"<<endl;

cout<<"KIA\tSONNET\t2022\tPETROL"<<endl;

cout<<"TATA\tEV\t2023\tELECTRIC"<<endl;

}

void UpdateVehicle(Vehicle &upd)

{

//Update the list of vehicle based on user input

cout<<"Enter the vehicle details to be updated : "<<endl;

string make,model,type;

int year;

cout<<"Make : "<<endl;

cin>>make;

cout<<"Model : "<<endl;

cin>>model;

cout<<"Year : "<<endl;

cin>>year;

cout<<"Type : "<<endl;

cin>>type;

cout<<"The vehicle with following details has been updated :"<<endl;

cout<<"Make : "<<make<<"\tModel : "<<model<<"\tYear : "<<year<<"\tType : "<<type<<endl;

}

void RemoveVehicle(Vehicle &rem)

{ //Remove the vehicle from list

cout<<"Enter Vehicle details "<<endl;

rem.getmake();

rem.getmodel();

rem.getyear();

cout<<"Vehicle has been removed"<<endl;

}

void TireRotation(ElectricCar &Tire)

//Check for tire rotation of electric vehicle

{

Tire.CheckTireRotation();

}

void OilChange(Fuelvehicle &oil)

//Check for oil change in fuel vehicle

{

oil.CheckOil();

}

void Recharge(ElectricCar &reh) //Check for Recharge status of vehicle

{

reh.CheckChargePower();

}

//Main function

int main()

{

int option;

//Global variable

//Creating objects for each class

Vehicle veh;

Gascar gc;

Diselcar dc;

ElectricCar ec;

Fuelvehicle fc;

cout<<"Select any Option"<<endl; //inventory display

cout<<"0.Quit"<<endl;

cout<<"1.List Inventory"<<endl;

cout<<"2.Add vehicle"<<endl;

cout<<"3.Update vehicle"<<endl;

cout<<"4.Remove Vehicle"<<endl;

cout<<"5.Tire Rotation"<<endl;

cout<<"6.Oil Change"<<endl;

cout<<"7.Recharge"<<endl<<endl;

//Infinite while loop for description

while(1)

{

cout<<"Option is : "<<endl;

cin>>option;

switch(option)

//Switch case - condition statement for option based on input

{

case 0:

{

cout<<"Goodbye.Thank you"<<endl;

return 1 ;

break;

}

case 1:

{

ListVehicle(veh);

break;

}

case 2:

{

AddVehicle(veh);

break;

}

case 3:

{

UpdateVehicle(veh);

break;

}

case 4:

{

RemoveVehicle(veh);

break;

}

case 5:

{

TireRotation(ec);

break;

}

case 6:

{

OilChange(fc);

break;

}

case 7:

{

Recharge(ec);

break;

}

}

}

//list of vehicle

//addition of new vehicle

//update of vehicle detatils

//remove vehicle from list

//tire rotation of electric vehicle

//oil cycle check for fuel vehicle

//recharge status for electric vehicle

return 0;

}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.