Project 3
CODE :
#include<iostream>
#include <string>
#include <vector>
using namespace std;
class Vehicle //base class declaring
{
protected: //declaring the variables in protected access
string make;
string model;
int year;
int odometer;
public: //declaring the setter and getter functions in public mode
void setMake ();
void setModel ();
void setYear ();
void setOdometer ();
string getMake ();
string getModel ();
int getYear ();
int getOdometer ();
virtual void getType () = 0; //defining the pure virtual function
void Tire_Rotation(); // declaring the function check whether tire's has tobe rotate or not
void getCarInformation (); //declaring the function to get the car information
};
void Vehicle::setMake () //defining the setter function for make
{
cout << "\n Enter the make of the vehicle: ";
cin >> make;
}
void Vehicle::setModel () //defining the setter function for model
{
cout << "\n Enter the model of the vehicle: ";
cin >> model;
}
void Vehicle::setYear () //defining the setter function for year
{
cout << "\n Enter the year of the vehicle: ";
cin >> year;
}
void Vehicle::setOdometer () //defining the setter function for odometer
{
cout << "\n Enter the odometer reading of the vehicle: ";
cin >> odometer;
}
string Vehicle::getMake () //defining the getter function for make
{
return make;
}
string Vehicle::getModel () //defining the getter function for model
{
return model;
}
int Vehicle::getYear () //defining the getter function for year
{
return year;
}
int Vehicle::getOdometer () //defining the getter function for odometer
{
return odometer;
}
void Vehicle::getCarInformation () //defining the function to get car information
{
string getMake ();
string getModel ();
int getYear ();
int getOdometer ();
}
class GasCar:public Vehicle //defining the subclass
{
public:
void getType (string Gascar) //defining the function to get type
{
cout << "Gascar";
}
void getFuelType (string gas) //defining the function to get fueltype
{
cout << "gas";
}
};
class DieselCar:public Vehicle //defining the subclass
{
public:
void getType (string Diselcar) //defining the function to get type
{
cout << "Diselcar";
}
void getFuelType (string diesel) //defining the function to get fueltype
{
cout << "diesel";
}
};
class ElectricCar:public Vehicle //defining the subclass
{
public:
void Tire_Rotation (); // declaring the function check whether tire's has tobe rotate or not
void check_power (); //defining the function to check batteries has to be charge or not
void getType (string Elecric_car)//defining the function to get type
{
cout << "Electric_car";
}
};
//abstract class - containing one pure virtual method
class FuelVehicle:public Vehicle
{
virtual void getFuelType () = 0; //defining the pure virtual function
public: //access specifier
void Oil_Change (); //defining function to check oil has to be change or not
};
class Maintenance //abstract class for defining maintanance library of the car show room
{
public:
string list;
void List__inventory() //defining the inventory list of the cars in a show room
{
cout << "\n list of inventories are \n";
cout << "\n 1.Tata ";
cout << "\n 2.Toyota Innova Crysta";
cout << "\n 3.Jeep Grand Cherokee";
cout << "\n 4.Toyota Camry";
cout << "\n 4.BMW X1";
cout<< "\n 5.Creta";
cout<< "\n 6.Ertiga";
}
void Add_Vehicle() //defining function to add new cars in the show room
{
string newcar, newmake, newmodel;
int newyear;
//string list;
int type=-1;
do
{
cout<<"\n 0: GAS \n 1.DIESEL \n 2.ELECTRIC \n3.FUEL";
cout<<"\n enter the type of car "; //to choose the type of car which we have to add
cin>>type;
if(type==0) //for adding of GAS type car details
{
cout<<"\n Give the following details of the entered GAS type ";
cout<<"\n enter the car name need to be added ";
cin>>newcar;
cout<<"\n enter the car newmake to be added ";
cin>>newmake;
cout<<"\n enter the newmodel need to be added";
cin>>newmodel;
cout<<"\n enter the newyear to be added";
cin>>newyear;
list= list+" "+newcar;
cout<<"\n addedlist"<<" ";
}
else if (type==1) //for adding of DIESEL type car details
{
cout<<"\n Give the following details of the entered Diesel type";
cout<<"\n enter the car name need to be added";
cin>>newcar;
cout<<"\n enter the car newmake to be added";
cin>>newmake;
cout<<"\n enter the newmodel need to be added";
cin>>newmodel;
cout<<"\n enter the newyear to be added";
cin>>newyear;
list= list+" "+newcar;
cout<<"\n addedlist"<<" ";
}
else if (type==2) //for adding of ELECTRIC type car details
{
cout<<"\n Give the following details of the entered Electric type";
cout<<"\n enter the car name need to be added";
cin>>newcar;
cout<<"\n enter the car newmake to be added";
cin>>newmake;
cout<<"\n enter the newmodel need to be added";
cin>>newmodel;
cout<<"\n enter the newyear to be added";
cin>>newyear;
list= list+" "+newcar;
cout<<"\n addedlist"<<" ";
}
else if(type==3) //for adding of FUEL type car details
{
cout<<"\n Give the following details of the entered FUEL type";
cout<<"\n enter the car name need to be added";
cin>>newcar;
cout<<"\n enter the car newmake to be added";
cin>>newmake;
cout<<"\n enter the newmodel need to be added";
cin>>newmodel;
cout<<"\n enter the newyear to be added";
cin>>newyear;
list= list+" "+newcar;
cout<<"\n addedlist"<<" ";
}
}while(type<0||type>3);
}
void Update_Vehicle() //defining the function to update the car details
{
int m,year,odometer;
string make,model;
cout << "\n 0.make";
cout << "\n 1.model";
cout << "\n 2.year";
cout << "\n 3.odometer";
cout << "\n please select which you have to update"; //choosing the option which we have to update
cin>>m;
switch(m)
{
case 0: // updating the make
cout<<"\n the update is";
cin>>make;
break;
case 1: // updating the model
cout<<"\n the update is";
cin>>model;
break;
case 2: // updating the year
cout<<"\n the update is";
cin>>year;
break;
case 3: // updating the odometer
cout<<"\n the update is";
cin>>odometer;
break;
}
cout<<"\n updatelist";
}
void Remove_Vehicle() //defining the function which we have to remove from the list
{
string word;
cout<<"\n remove the vehicle from the inventory list"; //string word;
cin>>word;
int pos=list.find(word); //checking the given value is in the list or not
if(pos!=string::npos) //if yes,then it removes the word from the list
{
list.erase(pos,word.length()+1);
cout<<"\n The updated list"<<" ";
}
else
cout<<"\n The vehicle is not found";
}
void Tire_Rotation() // declaring the function check whether tire's has tobe rotate or not
{
int odometer;
cout<<"\n Enter the odometer reading";
cin>>odometer;//40000
int remainder = odometer-50000;
if (remainder>0)
cout<<"\n change tire";
else
{
cout<<"\n you are good to go";
}
}
void check_power() //defining the function to check batteries has to be charge or not
{
int distance;
cout<<"\n Enter the distance";
cin>>distance;
if(distance>=400000)
cout<<"\n advise battery to be recharged";
else
{
cout<<"\n your vehicle is good to go";
}
}
void Oil_Change() //defining function to check oil has to be change or not
{
int distance;
cout<<"\n Enter the distance";
cin>>distance;
if(distance>=4000)
cout<<"\n car requires oil change ";
else
cout<<"\n your vehicle is good to go";
}
};
void selectCar() //defing the function to retrieve the cars
{
int a;
cout << "1.Gas car";
cout << "2.Disel car";
cout << "3.Electric car";
cout << "4.Fuel car";
cout << "please select the car";
cin >> a;
switch (a)
{
case 1:
class GasCar;
break;
case 2:
class DieselCar;
break;
case 3:
class ElectricCar;
break;
case 4:
class FuelVehicle;
break;
}
}
int main() //the main source which has to execute
{
int n;
Vehicle *v; //declaring the base class objective
Maintenance M; //declaring the class objective
// showing the menus for updating the car information in the showroom
cout<<"\n The Menu is follows \n";
cout << " 0. Quit.\n";
cout << " 1. List inventory.\n";
cout << " 2. Add vehicle.\n";
cout << " 3. Update vehicle.\n";
cout << " 4. Remove vehicle.\n";
cout << " 5. Tire rotation.\n";
cout << " 6. Oil change.\n";
cout << " 7. Recharge.\n";
//beginning:
while(1) //defining the while loop to run infinitely
{
cout<<"\n Enter the choice you want";
cin>>n;
switch(n)
{
case 0:
cout<<"\n You have chosen option 0"; //exit(0)
break;
case 1:
M.List__inventory();
break;
case 2:
M.Add_Vehicle();
break;
case 3:
M.Update_Vehicle();
break;
case 4:
M.Remove_Vehicle();
break;
case 5:
M.Tire_Rotation();
break;
case 6:
M.Oil_Change();
break;
case 7:
M.check_power();
break;
}
}
void selectCar(); //declaring the retrieve car function
return 0;
}
OUTPUT :
The Menu is follows
0. Quit.
1. List inventory.
2. Add vehicle.
3. Update vehicle.
4. Remove vehicle.
5. Tire rotation.
6. Oil change.
7. Recharge.
Enter the choice you want 1
list of inventories are
1.Tata
2.Toyota Innova Crysta
3.Jeep Grand Cherokee
4.Toyota Camry
4.BMW X1
5.Creta
6.Ertiga
Enter the choice you want 2
0: GAS
1.DIESEL
2.ELECTRIC
3.FUEL
enter the type of car 0
Give the following details of the entered GAS type
enter the car name need to be added FORD
enter the car newmake to be added FORDGALAXY
enter the newmodel need to be added CNG
enter the newyear to be added 1998
addedlist
Enter the choice you want 2
0: GAS
1.DIESEL
2.ELECTRIC
3.FUEL
enter the type of car 1
Give the following details of the entered Diesel type
enter the car name need to be added BMW
enter the car newmake to be added ILandFSltd
enter the newmodel need to be added 520D
enter the newyear to be added 2012
addedlist
Enter the choice you want 2
0: GAS
1.DIESEL
2.ELECTRIC
3.FUEL
enter the type of car 2
Give the following details of the entered Electric type
enter the car name need to be added citroen
enter the car newmake to be added stellanties
enter the newmodel need to be added eCMP
enter the newyear to be added 2021
addedlist
Enter the choice you want 2
0: GAS
1.DIESEL
2.ELECTRIC
3.FUEL
enter the type of car 3
Give the following details of the entered FUEL type
enter the car name need to be added Revotron
enter the car newmake to be added TaTamotors
enter the newmodel need to be added nexonSUV
enter the newyear to be added 1992
addedlist
Enter the choice you want 3
0.make
1.model
2.year
3.odometer
please select which you have to update 1
the update is BMW
updatelist
Enter the choice you want 4
remove the vehicle from the inventory list Revotron
The updated list
Enter the choice you want 5
Enter the odometer reading 50023
change tire
Enter the choice you want 6
Enter the distance 500456
car requires oil change
Enter the choice you want 7
Enter the distance 5241
your vehicle is good to go
Enter the choice you want 0
You have chosen option 0