Challenge

Project 3

1.

#include<iostream>
using namespace std;
#include<string.h>
class vehicle{ //creating base class vehicle
public:
int year,odometerreading; //creating variables
string make,model;
enum Type{ //creating enumrated data

GAS,

DIESEL,

ELECTRIC

};
enum Type type;

int y,o;
string m1,m2;
void getNewMake(); //creating functions
void getNewModel();
void getYear();
void getNewOdometer();
void setNewmake();
void setNewmodel();
void setYear();
void setNewodometer();
};
void vehicle::setNewmake() //function definition outside the class
{

cout<<"Enter the maker of the car"<<endl;
cin>>m1;

}
void vehicle::getNewMake()
{
cout<<"The maker of the car is "<<m1<<endl;

}
void vehicle::setNewmodel()
{

cout<<"Enter the model of the car";
cin>>m2;
}
void vehicle::getNewModel()
{
cout<<"The model is "<<m2<<endl;
}
void vehicle::setYear()
{
cout<<"Enter the year of manufacturing for the vehicle ";
cin>>y;

}
void vehicle::getYear()
{
cout<<"The year of the car is "<<y<<endl;
}
void vehicle::setNewodometer()
{
cout<<"Enter the odometer reading:";
cin>>o;

}
void vehicle::getNewOdometer()
{
cout<<"The ODOMETER READING OF THE CAR IS: "<<o<<endl;
}

class Gascar{ //creating gascar function
public:
string getType(); //functions in the class
string getFuelType();
};
class DieselCar{ //created diesel car function
public:
string getType();
string getFuelType();
};
class ElectricCar{ //creating electric car funtion
public:
string checkTireRotation(int odometerreading){ //checking odometer reading

if(odometerreading>=50000){
return "replace the tires";
}
else{
int remainder= 50000-odometerreading;
cout<<"the remainder to reach 50 k kilometers is "<<remainder<<endl;
return "tires are good to go";
}
}
string checkChargerPower(int odometerreading){ //checking charge availability
if(odometerreading>=400){
return "battery to be recharged";
}
else{
return "your vehicle is good to go";
}
}
string getType(){
return "The type of vehicle is Electric Car";

}
};
class FuelVehicle{ //creating class fuelvehicle
public:
virtual void getFuelType()=0;
void checkOil() //check oil function
{
char input;
cout<<"enter whether oil needs replacement"<<endl;
cin>>input;
if(input=='Y') //checking oil to be replaced or not
{
cout<<"Oil is replaced"<<endl;
}
else
{
cout<<"Oil is not replaced"<<endl;
}
}
};
string Gascar::getType() //function definition for getype function for gascar class
{
return "the type of car is Gascar";
}
string Gascar::getFuelType()
{
return "the type of car is LPG Gas";
}
string DieselCar::getType()
{
return "the type of car is DieselCar";
}
string DieselCar::getFuelType() //function definition for getfueltype function for dieselcar class
{
return "the type of car is Diesel";
}
class Maintanence //creating class maintanence
{
public:
string inventory={"benz,audi,tata,xuv"}; //list of vehicles
void addVehicle()
{
string x;
cout<<"Enter the Vehicle you want to add "<<endl;
cin>>x;
inventory=inventory+" "+x; //to add any vehicles
cout<<"inventory "<<inventory<<endl;
}
void ListVehicle()
{
cout<<"inventory "<<inventory<<endl; //display vehicle list
}
void UpdateVehicle()
{
cout<<"inventory :"<<inventory<<endl;
}
void Remove_Vehicle()
{
string re;
cout<<"enter the vehicle to be remove"<<endl;
cin>>re;
int pos=inventory.find(re); //to remove a vechile from the list
if(pos!=string::npos)
{
inventory.erase(pos,re.length()+1);
cout<<" inventory"<<" "<<inventory<<endl;
}
else
cout<<" vehicle is not found"<<endl;
}
void checkTireRotation()
{
int odometerreading;
cout<<"Enter odometerreading"<<endl;
cin>>odometerreading;
if(odometerreading>=50000) //checking tire rotation
{
cout<< "replace the tires"<<endl;
}
else
{
int remainder= 50000-odometerreading; //remainder to reach 50k
cout<<"the remainder to reach 50 k kilometers is "<<remainder<<endl;
cout<< "tires are good to go"<<endl;
}
}
void checkOil() //check oil function
{
char input;
cout<<"enter whether oil needs replacement"<<endl;
cin>>input;
if(input=='Y') //checking the oil is to replaced or not
{
cout<<"Oil is replaced"<<endl;
}
else
{
cout<<"Oil is not replaced"<<endl;
}
}
void checkChargerPower(){
int odometerreading;
cout<<"Enter odometerreading"<<endl;
cin>>odometerreading;
if(odometerreading>=400) //checking the power in the battery
{
cout<< "battery to be recharged"<<endl;
}
else
{
cout<<"your vehicle is good to go"<<endl;
}
}

};
int main()
{

vehicle V; //creating objects
Gascar G;
DieselCar D;
FuelVehicle *F;
ElectricCar E;
Maintanence M;
int choice;
while(1)
{
cout<<"enter the choice"<<endl;
cout<<"choice1=add vehicle"<<endl;
cout<<"choice2=list vehicle"<<endl;
cout<<"choice3=update vehicle"<<endl;
cout<<"choice4=remove vehicle"<<endl;
cout<<"choice5=check tire rotation of vehicle"<<endl;
cout<<"choice6=check oil"<<endl;
cout<<"choice7=check charge power"<<endl;
cin>>choice;

switch(choice) //creating switch
{
case 1: M.addVehicle();
break;
case 2: M.ListVehicle();
break;
case 3: M.UpdateVehicle();
break;
case 4: M.Remove_Vehicle();
break;
case 5: M.checkTireRotation();
break;
case 6: M.checkOil();
break;
case 7: M.checkChargerPower();
break;
default:
break;
}
}
/* V.setNewmake();
V.getNewMake();
V.setNewmodel();
V.getNewModel();
V.setYear();
V.getYear();
V.setNewodometer();
V.getNewOdometer();*/
}

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.