Challenge

Project 2

Live Batch: Essaki Vigneshwaran

Project - 2:

Program:


#include <iostream> //Header Files
#include <string.h> //Header file For include String definition

using namespace std; //Header file include namespace std


class Vehicle //Create a class name is Vehicle
{

public: //it is a protected function in class
//Declared Data members of a class
string make,model;
long int year;
long int odometer;
int n;

public: //used to access the protected in main class
enum Type{GAS,DIESEL,ELECTRIC};//enum type list for the vechile
virtual void getType()=0; //pure virtual method to get the type
Vehicle() //default Constructor
{
cout<<"The make of the vehicle"<<endl;
cin>>make;

cout<<"The model of the vechical"<<endl;
cin>>model;

cout<<"The manufacturing year of vehicle"<<endl;
cin>>year;

cout<<"The odometer reading in the vehicle"<<endl;
cin>>odometer;

}
// getter and setter functions
string getMake(){
return make;
}


string getModel(){
return model;
}


int getYear(){
return year;
}

long int getOdo(){
return odometer;
}

void setModel(string val){
model = val;
}

void setMake(string val){
make = val;
}

void setYear(int val){
year = val;
}

void setOdo(int val){
odometer = val;
}

void addVehicle() //Declared member function to add new vehicle to inventory
{
int type = getNewType();
string make = getNewMake();
string model = getNewModel();
long int odometer = getNewOdometer();
int year = getNewYear();

cout<<"Added vehicle ";
}
void listVehicles() //Declared member function to list the vehicles in the inventory
{
cout<<"the list of the inventory details have been uploaded in a proper manner"<<endl;
cout<<"the list has been got approved from RTO"<<endl;
cout<<"Make\t Model\t Odo\t Year"<<endl;

}
void removeVehicle() //Declared member function to remove the vehicle from the inventory list
{
cout<<"there is no vehicle is added in the list to remove"<<endl;

}
void updateVehicle() //Declared member function to update the vehicle in the inventory list
{
int selection;
cout<<"Enter the parameter to be updated: ";
cin>>selection;
if(selection==1){
int year = getNewYear();
}

else if(selection==2){
long int odometer = getNewOdometer();
}

else
cout<<"Invalid selection"<<make;
}
string getNewModel(){ //If input is blank, request again
string model;
cout<<"Enter model: ";
cin>>model;
return model;
}

string getNewMake(){ //If input is blank, request again
string make;
cout<<"Enter make: ";
cin>>make;
return make;
}

long int getNewOdometer(){ //Input should be only numericals
long int odo;
cout<<"Enter odometer reading: ";
cin>>odo;
return odo;
}


int getNewYear(){ //If input doesn’t have 4 digits, request again
long int year;
cout<<"Enter year of manufacture: ";
cin>>year;
return year;
}


int getNewType(){ //Input should be within 0-2, else request again
int type;
do {
cout<<"Enter 0: GAS\n1.DIESEL\n2.ELECTRIC ";
cin>>type;
}while(type<0||type>2);

return type;
}
void getcarinformation()//constructor details of the vehicles
{
cout<<"the information based on the customer vehicle: "<<endl;
cin>>n;
switch(n)
{
case 0:
cout<<"GAS type vehicle came to service"<<endl;
cout<<"it runs in liquidfied gas"<<endl;
break;
case 1:
cout<<"DIESEL type vehicle came to service"<<endl;
cout<<"it runs in liquid petrolium"<<endl;
break;
case 2:
cout<<"ELECTICAL type vehicle came to service"<<endl;
cout<<"it runs in rechargeable battery"<<endl;
break;
default:
cout<<"invalid type of vehicle to select"<<endl;
break;
}
}

};
class maintenance: public Vehicle //Inherit the base class
{
protected://it is a protected function in class
int t,c;
public://used to access the protected in main class
void checkTireRotation()//constructor details of the vehicles
{

cout<<"\nThe information based on the tire rotation is: "<<endl;
if(odometer >= 50000)
{
cout<<"the car tire must be changed the life time is over"<<endl;
}
else
{
long int t=(50000-odometer);
cout<<"\nThe tires is good condition \n After "<<t<<"kms the tier must be changed"<<endl;
}
}
void checkChargerPower() //constructor details of the vehicles
{
cout<<"\nThe information based on the battery usage: "<<endl;
if(odometer >= 400)
{
cout<<"the battery must need be changed"<<endl;
}
else
{
long int c=(400-odometer);
cout<<"\nThe battery is in good condition \n After"<<c<<"kms the battery must be changed"<<endl;
}
}
};
class Gas_car : public Vehicle //This is an derived class that inherits vehicle class
{
public:
void getType(){
Type t = GAS; //Declared the Type of Vehicle in the Enumurated values
cout<<"The VEHICLE TYPE to is "<<t<<endl;
}
void getFuelType(){
cout<<"Fuel Type of car is Gas"<<endl;
}
};
class Disel_car : public Vehicle //This is an derived class that inherits vehicle class
{
public:
void getType(){
Type t = DIESEL; //Declared the Type of Vehicle in the Enumurated values
cout<<"The VEHICLE TYPE to is "<<t<<endl;
}
void getFuelType(){

cout<<"Fuel Type of car is Diesal"<<endl;
}
};
class Electric_car : public Vehicle //This is an derived class that inherits vehicle class
{
public:
void checkTireRotation()//constructor details of the vehicles Electric_car
{
cout<<"The information based on the tire rotation is: "<<endl;
if(odometer >= 50000)
{
cout<<"The car tire must be changed the life time is over"<<endl;
}
else
{
long int t=(50000-odometer); //If remainder >=0 then advice to rotate tires
cout<<"The tires is good condition \n After "<<t<<"kms the tier must be changed"<<endl;
}
}
void checkChargerPower()
{
cout<<"The information based on the battery usage: "<<endl;
if(odometer >= 400)
{
cout<<"the battery must need be changed"<<endl;
}
else
{
long int c=(400-odometer);
cout<<"the battery is in good condition \n After "<<c<<"kms the battery must be changed"<<endl;
}
}
void getType()
{
Type t = ELECTRIC; //Declared the Type of Vehicle in the Enumurated values
cout<<"The VEHICLE TYPE to is"<<t<<endl;
}

};

class FuelVehicle : public Vehicle //This is an abstract class that inherits vehicle class
{
public:
virtual void getFuelType() = 0; //Declared pure virtual function
void checkOil()
{
cout<<"1.Prepare to check.2.Locate the Dipstick.3.Pull the Dipstick.4.Note oil Level.5.Wait and Re-check\n";
}

};
int main() //Driver code
{
int selection,a; //Declared variable
FuelVehicle *f1; //Create object in pointer for an abstract class
maintenance *m1; //Create object in pointer for an abstract class
cout<<"Enter the tpye of the vehicle(0. CNG, 1. Disel, 2. Electric): ";
cin>>a;

switch(a) //select type of vehicle
{

case 0: //Choose 0
{

Gas_car g1; //create object for an Electric_car class
g1.getcarinformation(); //Call the Member Function
g1.getType();
g1.getFuelType();
break;
}

case 1: //choose 1
{
Disel_car d1; //create object for an Disel_car class
d1.getcarinformation(); //Call the Member Function
d1.getType();
d1.getFuelType();
break;
}

case 2: //Choose 2
{

Electric_car e1; //create object for an Electric_car class
e1.getcarinformation(); //Call the Member Function
e1.getType();
e1.checkTireRotation();
e1.checkChargerPower();
break;
}

default:{
cout<<"Invalid Input"<<endl;
break;}
}

start:
/*********** MENU *************/
cout<<"Choose the Required Option: \n"
<< " 0. 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";
cin>>selection; //Get user input menu value
switch(selection) //select type
{
case 0://quit();
cout<<"thanks for doing service with us "<<endl;
cout<<"have a safe journey"<<endl;
break;
case 1:
m1->listVehicles(); //Calling member Function of a class
break;
case 2:

m1->addVehicle();
cout<<"if you want to add the another vehicle bill means we can add it"<<endl;
cout<<"you said no need ok"<<endl;
break;
case 3:
m1->updateVehicle();
cout<<"the old parts has been replaced with the updated parts in the market"<<endl;
cout<<"its an wonderful update in the year"<<endl;
break;
case 4:
m1->removeVehicle();
break;
case 5:
m1->checkTireRotation();
cout<<"the rotation is in good condition"<<endl;
cout<<"there is no need to change the tire"<<endl;
break;
case 6:
f1->checkOil();
cout<<"the oil tank in the car cleaned completely"<<endl;
cout<<"the new oil is filled in the tank"<<endl;
break;
case 7:
m1->checkChargerPower();
cout<<"as per the customer requirement the battery has changed to new version"<<endl;
cout<<"the battery recharged fully and it has 2 year life time"<<endl;
break;
default:
cout<<"Invalid selection"<<selection;
break;
}
while(selection !=0)
{
goto start; //Start again
}

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.