Challenge

Project 3

AIM: 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.

/*

select any option according to your choice

<< " 0. Quit.\n"

<< " 1. List inventory.\n"

<< " 2. Add vehicle.\n"

<< " 3. Update vehicle\n"

<< " 4. Remove vehicle\n"

<< " 5. Tire Rotation\n"

<< " 6. Oil Change\n"

<< " 7. Recharge\n"

*/

#include <iostream> //Standard library function

using namespace std; //Contains built-in classes,Cin cout

enum type //User defined enum as Type

{

GAS,

DIESEL,

ELECTRIC

};

//Base Class

class Vehicle //Class vehicle

{

protected: //Protected members

string Make,Model; //Member variables

int Year;

long int Odometer;

//Get functions for 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);

};

//Derived Class Gas car inherited from Base class Vehicle

class Gascar:public Vehicle

{

};

//Derived Class Diesel car inherited from Base class Vehicle

class Dieselcar:public Vehicle

{

};

//Derived Class Electric car inherited from Base class Vehicle

class ElectricCar:public Vehicle

{

public:

int tire;

void CheckTireRotation() //Check tyres Function

{

cout<<"Enter the running kilometers of car: "<<endl;

cin>>tire;

if(tire>=50000)

{

cout<<"Rotation needed,Rotate the tyres in cross direction..."<<endl;

}

else{

cout<<"Tyres are in good condition,No need to replace..."<<endl;

}

}

void CheckChargePower() //Check charge for the vehicle

{

cout<<"Enter the running kilometers of car: "<<endl;

cin>>Odometer;

if(Odometer>=400){

cout<<"Recharge the battery as soon as possible"<<endl;

}

else{

cout<<"Battery voltage level & gravity is okay"<<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

{

cout<<"Enter oil level(1 to 4) : "<<endl;

cin>>quarts;

if(quarts<=1)

{

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

}

else{

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

}

}

//Friend function of Fuel vehicle class

friend void OilChange(Fuelvehicle &oil);

};

//Friend functions Definitions

void AddVehicle(Vehicle &add) //Add new vehicle

{

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

add.getmake();

add.getmodel();

add.getyear();

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

}

void ListVehicle(Vehicle &list) //List of all the vehicles

{

cout<<"suzuki:swift:2014:DIESEL"<<endl;

cout<<"kia:sonet:2022:PETROL"<<endl;

cout<<"Mahindra:xuv400:2024:ELECTRIC"<<endl;

}

void UpdateVehicle(Vehicle &upd) //Update the list

{

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

upd.getmake();

upd.getmodel();

upd.getyear();

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

}

void RemoveVehicle(Vehicle &rem) //Remove the vehicle

{

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

rem.getmake();

rem.getmodel();

rem.getyear();

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

}

void TireRotation(ElectricCar &Tire) //Check for the tyre rotation or not

{

Tire.CheckTireRotation();

}

void OilChange(Fuelvehicle &oil) //Check for the Engine oil change or not

{

oil.CheckOil();

}

void Recharge(ElectricCar &reh) //Check for Battery Recharge or not

{

reh.CheckChargePower();

}

//Main function

int main()

{

int option; //Global variable declare

//Creating objects for each class

Vehicle veh;

Gascar gc;

Dieselcar dc;

ElectricCar ec;

Fuelvehicle fc;

cout<<"Select any Option"<<endl;

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.Tyre Rotation"<<endl;

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

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

// while loop

while(1)

{

cout<<"Enter the option number : "<<endl;

cin>>option;

switch(option) //Switch case - condition statement

{

case 0:

{

cout<<"Thank You for vehicle inspection, Have a safe day !!"<<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;

}

}

}

return 0;

}

OUTPUT 1

Select any Option

0.Quit

1.List Inventory

2.Add vehicle

3.Update vehicle

4.Remove Vehicle

5.Tyre Rotation

6.Oil Change

7.Recharge

Enter the option number :

0

Thank You for vehicle inspection, Have a safe day !!

OUTPUT 2

Select any Option

0.Quit

1.List Inventory

2.Add vehicle

3.Update vehicle

4.Remove Vehicle

5.Tyre Rotation

6.Oil Change

7.Recharge

Enter the option number :

1

suzuki:swift:2014:DISEL

kia:sonet:2022:PETROL

Mahindra:xuv400:2024:ELECTRIC

OUTPUT 3

Select any Option

0.Quit

1.List Inventory

2.Add vehicle

3.Update vehicle

4.Remove Vehicle

5.Tyre Rotation

6.Oil Change

7.Recharge

Enter the option number :

2

Enter Vehicle details

Make type :

suzuki

Model :

wagonr

Year :

2007

Vehicle has been added

OUTPUT 4

Select any Option

0.Quit

1.List Inventory

2.Add vehicle

3.Update vehicle

4.Remove Vehicle

5.Tyre Rotation

6.Oil Change

7.Recharge

Enter the option number :

4

Enter Vehicle details

Make type :

suzuki

Model :

swift

Year :

2014

Vehicle has been removed

OUTPUT 5

Select any Option

0.Quit

1.List Inventory

2.Add vehicle

3.Update vehicle

4.Remove Vehicle

5.Tyre Rotation

6.Oil Change

7.Recharge

Enter the option number :

5

Enter the running kilometers of car:

15000

Tyres are in good condition,No need to replace...

Enter the option number :

5

Enter the running kilometers of car:

85000

Rotation needed,Rotate the tyres in cross direction...

OUTPUT 6

Select any Option

0.Quit

1.List Inventory

2.Add vehicle

3.Update vehicle

4.Remove Vehicle

5.Tyre Rotation

6.Oil Change

7.Recharge

Enter the option number :

6

Enter oil level(1 to 4) :

1

Engine oil level is low

Enter the option number :

6

Enter oil level(1 to 4) :

3

Oil level is okay

OUTPUT 7

Select any Option

0.Quit

1.List Inventory

2.Add vehicle

3.Update vehicle

4.Remove Vehicle

5.Tyre Rotation

6.Oil Change

7.Recharge

Enter the option number :

7

Enter the running kilometers of car:

100

Battery voltage level & gravity is okay

Enter the option number :

7

Enter the running kilometers of car:

450

Recharge the battery as soon as possible

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.