Project 3
#include <iostream>
#include <vector>
#include <stdlib.h>
using namespace std;
//class vehicle
class Vehicle
{
//protected member variables
protected:
string make;
string model;
int year;
int odometer;
string fueltype;
//public member functions
public:
//function to read data from the user
void getdata()
{
cout<<"\nEnter the make: ";
cin>>make;
cout<<"Enter model: ";
cin>>model;
cout<<"Enter year: ";
cin>>year;
cout<<"Enter odometer reading: ";
cin>>odometer;
cout<<"Enter the fuel type: ";
cin>>fueltype;
}
//function to display the details
void carInformation()
{
//cout<<"Data entered succesfully as follows:"<<endl;
cout<<"\nvehicle make :"<<make<<endl;
cout<<"model: "<<model<<endl;
cout<<"year: "<<year<<endl;
cout<<"odometer reading: "<<odometer<<endl;
cout<<"fuel type: "<<fueltype<<endl;
}
//function to check for tyre rotation
void checkTyreRotation(int odometer)
{
int tyreCycle = 50000; // Tyre cycle in kilometers
int distance = odometer % tyreCycle;
if (distance >= 0 && distance <= 1)
cout << "\nRotate tires." << endl;
else
cout << "\nTires are good to go." << endl;
}
//function to check for oil change
void checkOilChange(int odometer)
{
int oilchangecycle= 3000;//disatnce in kilometers
int distance =odometer%oilchangecycle;
if (distance>=0 && distance<=1)
cout<<"\nNo oil change required."<<endl;
else
cout<<"\nChange oil.";
}
};
//class Gas derived from Vehicle class
class Gas:public Vehicle
{
public:
//function to check for recharge
void checkPower()
{
// Gas cars don't need to recharge power
cout << "Gas car doesn't need to recharge power." << endl;
}
};
class Diesal:public Vehicle
{
public:
//function to check for recharge
void checkPower()
{
// Diesal cars don't need to recharge power
cout << "Diesal car doesn't need to recharge power." << endl;
}
};
class Electric:public Vehicle
{
public:
//function to check for recharge
void checkPower(int odometer)
{
// Electric car need to recharge power
int powerCycle = 400; // Power cycle in kilometers
int distance = odometer % powerCycle;
if (distance == 0)
cout << "\nRecharge power." << endl;
else
cout << "\nVehicle is good to go." << endl;
}
};
//main function
int main()
{
//local variable declarations
int choice,num,repeat,vehicle_no,remove_no,speed_tyre,speed_oil,speed_power,fuel_powercheck;
std::vector<Vehicle>Garage ;//vector declarations
//instances of classes
Vehicle car;
Diesal car_diesal;
Gas car_gas;
Electric car_electric;
do
{
//services offered in the vehicle garage
cout<<"*********SERVICES**********" ;
cout<<"\n0- Quit";
cout<<"\n1- Add Vehicle";
cout<<"\n2- List Vehicle";
cout<<"\n3- Update Vehicle";
cout<<"\n4- Remove Vehicle";
cout<<"\n5- Tyre rotation";
cout<<"\n6- Oil Change";
cout<<"\n7- Recharge";
cout<<"\nEnter your choice: ";
cin>>choice;
//to add vehicles
if(choice==1)
{
cout<<"\nKindly enter the number of vehicles to be added: ";
cin>>num;
for(int i=0;i<num;i++)
{
cout<<"\nEnter the details of vehicle "<<i+1<<":";
Vehicle temp;
temp.getdata();
Garage.push_back(temp);//to add to the vector
}
cout<<"\nData entered successfully";
}
//to list the vehicles in the garage
else if(choice==2)
{
cout<<"\nThe vehicles available in the garage are :";
for (int i = 0; i < Garage.size(); ++i)
{
cout<<"\nVehicle No:"<<i+1;
Garage[i].carInformation();
}
}
//to modify a specific vehicle details
else if(choice==3)
{
cout<<"\nEnter the number of vehicle whose data is to be modified: ";
cin>>vehicle_no;
for (int i = 0; i < Garage.size(); ++i)
{
if((vehicle_no - 1)==i)
{
cout<<"\nEnter the new details of vehicle "<<vehicle_no<<":";
Vehicle temp;
temp.getdata();
Garage[i]=temp;
}
}
cout<<"\nData updated successfully";
}
//to remove a specific vehicle
else if(choice==4)
{
cout<<"\nEnter the vehicle number to be removed: ";
cin>>remove_no;
for (int i = 0; i < Garage.size(); ++i)
{
if((remove_no - 1)==i)
{
Garage.erase(Garage.begin() + i);
}
}
cout<<"\nDetails removed successfully.";
}
//to check for tyre rotation
else if(choice==5)
{
cout<<"Enter the odometer reading i.e. the speed covered: ";
cin>>speed_tyre;
car.checkTyreRotation(speed_tyre);
}
//to check for oil change
else if(choice==6)
{
cout<<"Enter the odometer reading i.e. the speed covered: ";
cin>>speed_oil;
car.checkOilChange(speed_tyre);
}
//to check for Recharge
else if(choice==7)
{
cout<<"Choose the fuel used:1-electric,2-diesal,3-gas ";
cin>>fuel_powercheck;
if(fuel_powercheck==1)
{
cout<<"Enter the odometer reading i.e. the speed covered: ";
cin>>speed_oil;
car_electric.checkPower(speed_power);
}
else if(fuel_powercheck==2)
car_diesal.checkPower();
else if(fuel_powercheck==3)
car_gas.checkPower();
else
cout<<"\nInvalid choice";
}
//to quit
else if(choice==0)
break;
//default statement
else
cout<<"INVALID ENTRY";
cout<<"\nDo you want to continue? If yes enter 1 else enter 0 :";
cin>>repeat;
}while(repeat==1);
return 0;
}