Challenge

Project 3 Object Oriented Library to track Automobile Maintenance

//============================================================================
// Name : Project.c++
// Author : A.PAVAN KUMAR
//============================================================================

#include //Standard library function
using namespace std; //Contains built-in classes,Cin cout

enum type{ //User defined enum as Type
GAS,
DISEL,
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 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 tyres 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 charge for the 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
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 &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 all vehicles
{
cout<<"INOVVA:CRYSTA:2021:DISEL"<<endl;
cout<<"FERRARI:SPORT :2020:PETROL"<<endl;
cout<<"TESLA:SUV :2021: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 tire rotation
{
Tire.CheckTireRotation();
}

void OilChange(Fuelvehicle &oil) //Check for oil change
{
oil.CheckOil();
}

void Recharge(ElectricCar &reh) //Check for Recharge
{
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;
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
while(1){
cout<<"Option is : "<<endl;
cin>>option;

switch(option) //Switch case - condition statement
{
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;
}
}
}
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.