Project 3
Answer:
I learnt one thing when i implementing this project, i was stucked with this error "crosses initialization of ‘electriccar* selected_electriccar’""
Error is related to creation of variables and pointers inside the case, i got to know after doing some searching on google
i found the solution at:https://stackoverflow.com/questions/23599708/how-do-i-resolve-this-error-jump-to-case-label-crosses-initialization.
After keeping braces issue was resolved.

#include<iostream>
#include<string.h>
#include<vector>
using namespace std;
enum fuel_type{//enumerated data types for fuel types
GAS,
DIESEL,
ELECTRIC
};
class vehicle {// vehicle class - bas class
protected:
string Make;
string Model;
int Year;
int Odometer;
public:
vehicle(){// in constructor initiating the parameters from the taking user
cout<<"Please enter the make of the vehicle:";
cin>>Make;
cout<<"Please enter the Model of the vehicle:";
cin>>Model;
cout<<"Please enter the Year of the vehicle:";
cin>>Year;
cout<<"Please enter the Odomenter of the vehicle:";
cin>>Odometer;}
// these individual functions to display but these i didnt used any where
void GetMake(){cout<<"Make is :"<<Make<<endl;}
void GetModel(){cout<<"Model is :"<<Model<<endl;}
void GetYear(){cout<<"Year is :"<<Year<<endl;}
void GetOdomenter(){cout<<"Odometer reading is :"<<Odometer<<endl;}
void SetMake(){// to update/correct the Make
cout<<"Please Enter the correct Make:";
cin>>Make;}
void SetModel(){// to update/correct the Model
cout<<"Please Enter the correct Model:";
cin>>Model;}
void SetYear(){// to update/correct the year
cout<<"Please Enter the correct Year:";
cin>>Year;}
void SetOdomenter(){// to update/correct the Odomenter
cout<<"Please Enter the correct Odometer:";
cin>>Odometer;}
// to display the total car information
void getCarInformation(){cout<<"Make is :"<<Make<<" Model is : "<<Model<<" Year is : "<<" Odometer reading is : "<<Odometer<<endl;}
//to check the need of change oil of the vehicle
void oilchange(){cout<<"Oil change is Adviced"<<endl;}
//to check the fuel type of the vehicle
virtual fuel_type gettype() = 0;
//to check the tyre rotation of the vehicle
void checkTireRotation(){
int tyre_driven = Odometer % 50000;
if(tyre_driven >= 0)
{cout<<"Tyres rotation is adviced"<<endl;}
else
{cout<<"Tyres are good to go"<<endl;}}
};
class Gascar : public vehicle{ // class Gas car with inheritance of vehicle
public:
Gascar(){}
fuel_type gettype(){return GAS;}
};
class Dieselcar : public vehicle{// class Diesel car with inheritance of vehicle
public:
Dieselcar(){}
fuel_type gettype(){return DIESEL;} // it will the fuel type
};
class Electriccar : public vehicle{ // class Electric car with inheritance of vehicle
public:
Electriccar(){}
void checkChargerPower(){//to check the charge status
if(Odometer == 400){cout<<"Need to charge"<<endl;}
else{cout<<"Good to go"<<endl;}}
fuel_type gettype(){return ELECTRIC;}
};
int main(){
int selected_car;// defining the integer for internal selection of the car
vector<vehicle*>inventory_list; //defining the dynamic array for storing the inventory list of the vehicles
int select_menu; // integer to select menu index
while(true){
cout <<"\n0. 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"
<<"Please select the menu by entering serial number of the menu:";
cin>>select_menu;
switch(select_menu){ // switch case to select the proper menu
case 0:
break;
case 1:// to print inventory list
cout<<"Inventory List"<<endl;
for (const auto& sekhar : inventory_list){
sekhar->getCarInformation();
}
break;
case 2://case to Add vehicle
cout<<"Please select the vehicle fuel type(0 for GAS, 1 for Diesel and 2 for Electric):";
int fueltype;
cin>> fueltype;
vehicle* newvehicle;
if( fueltype == GAS){newvehicle = new Gascar();}
else if( fueltype == DIESEL){newvehicle = new Dieselcar();}
else if( fueltype == ELECTRIC){newvehicle = new Electriccar();}
else {cout<<"Invalid fuel type.\n"<<endl; continue;}
inventory_list.push_back(newvehicle);
break;
case 3://case to Update or correction
{int temp;
cout<<"select the index of the car to update or correct the data:";
cin>>selected_car;
if (selected_car >= 0 && selected_car < inventory_list.size()){
vehicle* selected_edit = dynamic_cast<vehicle*>(inventory_list[selected_car]);
cout<<"Please select to index value 0 - Make, 1 - Model, 2 -Year, 3 - Odometer:";
cin>>temp;
if (temp == 0){selected_edit->SetMake();}
else if(temp == 1){selected_edit->SetModel();}
else if(temp == 2){selected_edit->SetYear();}
else if(temp == 3){selected_edit->SetOdomenter();}
break;}
else
{cout << "Invalid car index\n";}
}
case 4: // to remove the vehicle from inventory
cout << "select the index of the car to remove:";
cin >> selected_car;
if (selected_car >= 0 && selected_car < inventory_list.size())
{delete inventory_list[selected_car]; // Free memory for the vehicle object
inventory_list.erase(inventory_list.begin() + selected_car);}
else
{cout << "Invalid car index\n";}
break;
case 5: // to check the tyre rotation
{cout<<"select the index of the car to check the tyre rotation:";
cin>>selected_car;
if (selected_car >= 0 && selected_car < inventory_list.size()) {
Electriccar* selected_electriccar = dynamic_cast<Electriccar*>(inventory_list[selected_car]);
if (selected_electriccar)
{selected_electriccar->checkTireRotation();}
else
{cout<<"Tyre roation is not applicable for this type of vehicle\n"<<endl;}}
else
{cout << "Invalid car index\n";}
break;}
case 6: //case to check oil change requirement
{cout << "select the index of the car to check oil change requirement:";
cin >> selected_car;
if (selected_car >= 0 && selected_car < inventory_list.size()) {
Electriccar* selected_caroilchange = dynamic_cast<Electriccar*>(inventory_list[selected_car]);
if (selected_caroilchange)
{cout << "Oil change is not applicable for this type of vehicle\n" << endl;}
else
{selected_caroilchange->oilchange();}}
else
{cout << "Invalid car index\n";}
break;
}
case 7: //case to check the charge
{cout << "select the index of the car to check the charge:";
cin >> selected_car;
if (selected_car >= 0 && selected_car < inventory_list.size()) {
Electriccar* selected_electriccar_charge = dynamic_cast<Electriccar*>(inventory_list[selected_car]);
if (selected_electriccar_charge)
{selected_electriccar_charge->checkChargerPower();}
else
{cout << "Charge check is not applicable for this type of vehicle\n" << endl;}}
else
{cout << "Invalid car index\n";}
break;}
default:
{cout<<"Please Enter Valid index"<<endl;
break;
}
}
if(select_menu ==0){return 0;}// exitinf the inifinite loop
}
}
OUTPUT:



