Challenge

Project 2

Esakki Vigneswaran:Live Batch:

A):

#include <iostream> //header file
using namespace std;
//enum Type{GAS,DIESEL,ELECTRIC};
class Vehicle //base class
{
public : //access specifier
//data members
int Year, Odometer,Type;
string Make, Model;

void getMake() //member function
{
cout<<endl<<" Make Type :";
cin>>Make;
}
int getYear() //member function
{
cout<<endl<<" Year :";
cin>>Year;
return Year;
}
int getOdometer() //member function
{
cout<<endl<<" Odometer Reading :";
cin>>Odometer;
return Odometer;
}
void getModel() //member function
{
cout<<endl<<" Model :";
cin>>Model;
}

int getType()
{
cout<<endl<<" Type : ";
cin>>Type;
return Type;
}
//virtual Type getType() = 0;
friend void AddVehicle(Vehicle &add); // friend function declaration
friend void ListVehicle(Vehicle &list); // friend function declaration
friend void UpdateVehicle(Vehicle &upd); // friend function declaration
friend void RemoveVehicle(Vehicle &rmv); // friend function declaration
};
//derived class GasCar
class GasCar : public Vehicle
{

};
//derived class DieselCar
class DieselCar : public Vehicle
{

};
//derived class ElectricCar
class ElectricCar : public Vehicle
{
public: //access specifier
int tire_c; //data member
void checkTireRotation() //member function
{
cout<<endl<<" Tire Cycle (in Kms) : ";
cin>>tire_c;
if(tire_c >= 50000)
{
cout<<endl<<" Advice : Tire Rotation Needed ";
}
else
cout<<endl<<" Tires are good to go !! ";
}
void checkChargerPower() //member function
{
cout<<endl<<" Enter Distance Travelled (in Kms) : ";
cin>>Odometer;
if(Odometer >= 400)
{
cout<<endl<<" Advice : Recharge Battery ";
}
else
cout<<endl<<" Battery good to go !!";
}

friend void TireRotation(ElectricCar &tire); // friend function declaration
friend void Recharge(ElectricCar &rchg); // friend function declaration
};
//abstract class - containing one pure virtual method
class FuelVehicle : public Vehicle
{
public: //access specifier
int quarts; //data member
void checkOil() //member function
{
cout<<endl<<" Enter oil Level (in Quarts) : ";
cin>>quarts;
if(quarts <= 1)
{
cout<<endl<<" Engine Oil Level : Low";
}
else
cout<<endl<<" Engine Oil Level is Fine";
}
friend void OilChange(FuelVehicle &oil); // friend function declaration
};
//friend function definitions (defining object for friend class and accessing the members)
void AddVehicle(Vehicle &add) //– to add new vehicle to inventory
{
cout<<endl<<" Enter Vehicle Details : "<<endl;
add.getMake();
add.getModel();
add.getYear();
cout<<endl<<" * The vehicle has been Added * ";
}
void ListVehicle(Vehicle &list) //- to list the vehicles in the inventory
{
cout<<endl<<" Tesla : SUV : 2022 : Type - 2 (EV)";
cout<<endl<<" KIA : Carnival : 2019 : Type - 1 (Diesel)";
cout<<endl<<" KIA : EV6 : 2021 : Type - 2 (Diesel)";
}
void UpdateVehicle(Vehicle &upd) //- to update the vehicle in the inventory list
{
cout<<endl<<" Enter Vehicle Details : "<<endl;
upd.getMake();
upd.getModel();
upd.getYear();
cout<<endl<<" * The vehicle has been Updated * ";
}
void RemoveVehicle(Vehicle &rmv) //- to remove the vehicle from the inventory list
{
cout<<endl<<" Enter Vehicle Details : "<<endl;
rmv.getMake();
rmv.getModel();
rmv.getYear();
cout<<endl<<" * The vehicle has been Removed *";
}
void TireRotation(ElectricCar &tire) //– Check if tires need rotation
{
cout<<endl<<" Enter Vehicle Type : 0->Gas ; 1->Diesel ; 2->Electric :: ";
cin>>tire.Type;
if(tire.Type == 2)
{
cout<<endl<<" Enter Vehicle Details : "<<endl;
tire.checkTireRotation();
}
else
{
cout<<endl<<" * Cannot be checked * ";
}

}
void OilChange(FuelVehicle &oil) //- check if car requires oil change
{
cout<<endl<<" Enter Vehicle Details : "<<endl;
oil.checkOil();
}
void Recharge(ElectricCar &rchg) //– check if vehicle needs recharge
{
cout<<endl<<" Enter Vehicle Type : 0->Gas ; 1->Diesel ; 2->Electric :: ";
cin>>rchg.Type;
if(rchg.Type == 2)
{
cout<<endl<<" Enter Vehicle Details : ";
rchg.checkChargerPower();
}
else
{
cout<<endl<<" * Cannot be checked * ";
}
}
int main() //main function
{
int option; //local variable
cout<<endl<<"_____________CAR MAINTENANCE SITE_____________"<<endl;

//creating objects of each class
Vehicle veh;
GasCar gc;
DieselCar dc;
ElectricCar ec;
FuelVehicle fv;



cout<<endl<<" Select option ______ ";
cout<<endl<< " 0. Quit";
cout<<endl<< " 1. List inventory";
cout<<endl<< " 2. Add vehicle";
cout<<endl<< " 3. Update vehicle";
cout<<endl<< " 4. Remove vehicle";
cout<<endl<< " 5. Tire Rotation";
cout<<endl<< " 6. Oil Change";
cout<<endl<< " 7. Recharge";

while(1) //infinite loop
{

cout<<endl<<" Option : ";
cin>>option;

switch(option) //switch- case conditional statement
{
case 0:
{
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(fv);
break;
}
case 7:
{
Recharge(ec);
break;
}
}

cout<<endl<<"____________________________"<<endl;
}
return 0; //returning zero to main function
}

Output:

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.