Challenge

Project 3

Build an object-oriented library which can be used to track automobile maintenance. There can be different car types such as petrol, diesel, gas, electric etc., This library should be able to support at least three of the car types.

Maintenance tasks include activities like oil change or replace oil filter, replace air filter, replace fuel filter, tire rotations, infotainment system debug, replace spark plugs, replace the cabin or a/c filter, check the level and refill clutch fluid or brake fluid, examine belts, wipers, hoses, check the tire conditions, check the charging systems and battery.

#include<iostream> //header files
#include<string>
#include<vector>
#include<list>
using namespace std; //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() //Check tyre rotation Function
{
cout<<"Tire cycles : "<<endl;
cin>>tire;
if(tire>=50000)
{
cout<<"Tire rotation needed "<<endl;
}
else
{
cout<<"Tyres are good to go"<<endl;
}
}

void CheckChargePower() //Check charging staus for the electric vehicle
{
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; //model of the vehicle
cin>>model;

cout<<"Year : "<<endl;
int year; //year of the vehicle
cin>>year;

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<<"-----------------------------"<<endl;
cout<<"Make\tModel\tYear\tType"<<endl;
cout<<"-----------------------------"<<endl;
cout<<"TOYOTA\tINNOVA\t2021\tDISEL"<<endl;
cout<<"FERRARI\tROMA\t2022\tPETROL"<<endl;
cout<<"TESLA\tS CLASS\t2020\tELECTRIC"<<endl;
cout<<"-----------------------------"<<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); //list of vehicle
break;
}
case 2:
{
AddVehicle(veh); //addition of new vehicle
break;
}
case 3:
{
UpdateVehicle(veh); //update of vehicle detatils
break;
}
case 4:
{
RemoveVehicle(veh); //remove vehicle from list
break;
}
case 5:
{
TireRotation(ec); //tire rotation of electric vehicle
break;
}
case 6:
{
OilChange(fc); //oil cycle check for fuel vehicle
break;
}
case 7:
{
Recharge(ec); //recharge status for electric vehicle
break;
}
}
}

return 0;
}

OUTPUT:

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.