Challenge

Project 3

1)
#include <iostream>//standard input output library
#include <string>//for using string functionality
#include <cstring>
#include <cctype>
using namespace std;
int r_no=102;
int i=0,j=0,k=0;
int index1=-1;
int index2=-1;
int index3=-1;
string data1="NOT APPLICABLE";//for showing the status what all services are available for a particular car
string data2="NOT APPLICABLE";
string data3="NOT APPLICABLE";
class vehicle//creating a class with name vehicle
{
protected:
string make;//making the data members in protected
string model;//making the data members in protected
string year;//making the data members in protected
string odometer_reading;//making the data members in protected
public:
string car_no;//used for serching a particular car
enum type
{
gas=10,diesel=100,electric=1000//enumerated data type
};
public:
void setmake(string str)//member function for setting the protected data member
{
make=str;
}
string getmake()//member function for getting the protected data member
{
return make;
}
void setmodel(string num)//member function for setting the protected data member
{
model=num;
}
string getmodel()//member function for getting the protected data member
{
return model;
}
void setyear(string num)//member function for setting the protected data member
{
year=num;
}
string getyear()//member function for getting the protected data member
{
return year;
}
void setodometer(string num)//member function for setting the protected data member
{
odometer_reading=num;
}
string getodometer()//member function for getting the protected data member
{
return odometer_reading;
}
public:
virtual type getfueltype()=0;//pure virtual function for making the class vehicle abstrcted
};
class gas_car:public vehicle//created a class of name gas_car inherited from vehicle class
{
public:
type getfueltype()//definition of the pure virual function
{
return gas;
}
};
class diesel_car:public vehicle//created a class of name diesel_car inherited from vehicle class
{
public:
type getfueltype()//definition of the pure virtual function
{
return diesel;
}
};
class electric_car:public vehicle//created a class of name electric_car inherited from vehicle class
{
public:
void checkTireRotation()//member function to check the tire rotation of the electric vehicle
{
if(stoi(odometer_reading)>=50000)//check the tirerotation of the vehicle by odometer reading
{
cout<<"////////////WARNING<>//////////////"<<endl;
cout<<" NEED TIRE ROTATION"<<endl;
cout<<"////////////WARNING<>//////////////"<<endl;
}
else
{
cout<<"NO NEED OF TIRE ROTATION"<<endl;
}
}
void checkchargepower()//member function for checking the charge of the electric vehicle
{
int num=stoi(odometer_reading);//check the recharge of the vehicle by odometer reading
if(num>=400)
{
cout<<"////////////WARNING<>//////////////"<<endl;
cout<<"NEEDS RECHARGE"<<endl;
cout<<"////////////WARNING<>//////////////"<<endl;
}
else
{
cout<<"GOOD TO GO"<<endl;
}
}
type getfueltype()//function which returns the type of vehicle
{
return electric;
}
};
class fuel_vehicle:protected vehicle//created a class of name fuel_vehicle inherited from vehicle class
{
public:
template <typename T>//template used
void check_oil(T &obj)//member function for checking the oil for gas,diesel from odometer reading
{
if(stoi(obj.getodometer())>=1000)//check the oil replacement by analysing the odometer reding for gas and diesel
{
cout<<"////////////WARNING<>//////////////"<<endl;
cout<<"PLEASE CHANGE YOUR OIL"<<endl;
cout<<"//////////////////////////"<<endl;
}
else
{
cout<<"YOU ARE GOOD TO GO "<<endl;
}
}
type getfueltype()
{
}
};
gas_car g1[3];
diesel_car d1[3];
electric_car e1[3];
fuel_vehicle fv;
int display_gas_car(string pass)
//function for displaying gas_car which is to be serched
//return type:int
//parameters:string data
{
int g=0;
for(int i=0;i<3;i++)
{
while((pass.compare(g1[g].car_no))==0)//string comparison using compare()function
{
cout<<g1[g].getmake()<<endl;
cout<<g1[g].getmodel()<<endl;
cout<<g1[g].getodometer()<<endl;
cout<<g1[g].getyear()<<endl;
cout<<g1[g].car_no;
cout<<" "<<endl;
cout<<" "<<endl;
data1="NOT APPLICABLE";
data2="APPICABLE";
data3="NOT APPLICABLE";
index3=g;
return 1;
}
g++;
}
return 0;
}
int display_diesel_car(string pass)
//function for displaying diesel_car which is to be serched
//return type:int
//parameters:string data
{
int d=0;
for(int i=0;i<3;i++)
{
while((pass.compare(d1[d].car_no))==0)//string comparison using compare()function
{
cout<<d1[d].getmake()<<endl;
cout<<d1[d].getmodel()<<endl;
cout<<d1[d].getodometer()<<endl;
cout<<d1[d].getyear()<<endl;
cout<<d1[d].car_no;
cout<<" "<<endl;
cout<<" "<<endl;
data1="NOT APPLICABLE";
data2="APPICABLE";
data3="NOT APPLICABLE";
index2=d;
return 1;
}
d++;
}
return 0;
}
int display_electric_car(string pass)
//function for displaying electric_car which is to be serched
//return type:int
//parameters:string data
{
int e=0;
for(int i=0;i<3;i++)
{
while((pass.compare(e1[e].car_no))==0)//string comparison using compare()function
{
cout<<e1[e].getmake()<<endl;
cout<<e1[e].getmodel()<<endl;
cout<<e1[e].getodometer()<<endl;
cout<<e1[e].getyear()<<endl;
cout<<e1[e].car_no;
cout<<" "<<endl;
cout<<" "<<endl;
data1="APPICABLE";
data2="NOT APPLICABLE";
data3="APPICABLE";
index1=e;
return 1;
}
e++;
}
return 0;
}
void getcar_info()
//to select the car through car_number search
//return:void
//parmeters:no parameters
{
int num,r;
string temp,result;
cout<<"ENTER THE TYPE\n1)GAS\n2)ELECTRIC\n3)DIESEL"<<endl;//display the choice
cin>>num;
switch(num)
{
case 1:cout<<"ENETRE THE CAR NUMBER"<<endl;
cin>>temp;
r=display_gas_car(temp);//function call to display the searched car
result=(r==1)?"found":"not found";
cout<<result<<endl;
break;
case 2:cout<<"ENETRE THE CAR NUMBER"<<endl;
cin>>temp;
r=display_electric_car(temp);//function call to display the searched car
result=(r==1)?"found":"not found";
cout<<result<<endl;
break;
case 3:cout<<"ENETRE THE CAR NUMBER"<<endl;
cin>>temp;
r=display_diesel_car(temp);//function call to display the searched car
result=(r==1)?"found":"not found";
cout<<result<<endl;
break;
default:cout<<"WRONG INPUT"<<endl;//otherwise throw wrong
break;
}
}
void default_data()
//function for displaying the stored car
//return:void
//parameters:no parameters
{///////for initializing gas_car///
g1[i].setmake("MARUTHI");
g1[i].setmodel("2015");
g1[i].setodometer("30000");
g1[i].setyear("2015");
g1[i].car_no="KL07R2319";
i++;
///////for initializing diesel_car///
d1[j].setmake("INDICA");
d1[j].setmodel("2015");
d1[j].setodometer("40000");
d1[j].setyear("2015");
d1[j].car_no="KL07R3024";
j++;
///////for initializing electric_car///
e1[k].setmake("OLA");
e1[k].setmodel("2015");
e1[k].setodometer("50000");
e1[k].setyear("2015");
e1[k].car_no="KL07R2619";
k++;
}
template<typename T>//template
void getnewmake(T &obj)
//function to get new make from the user
//return :void
//parametrs: any object
{
string make;
while(1)
{
cout<<"ENTER THE MAKE"<<endl;
cin>>make;
if(make.size()<2)//checking the input is blank or zero
{
cout<<"THE INPUT IS BLANK"<<endl;
}
else//otherwise store the result and display the sucess status
{
obj.setmake(make);
cout<<"DATA STORED"<<endl;
break;
}
}
}
template<typename T>
void getnewmodel(T &obj)
//function to get new model from the user
//return :void
//parametrs: any object
{
string num;
while(1)
{
cout<<"ENTER THE MODEL"<<endl;
cin>>num;
if(num.size()<2)//checking the input is blank or zero
{
cout<<"THE INPUT IS BLANK"<<endl;
}
else//otherwise store the result and display the sucess status
{
obj.setmodel(num);
cout<<"DATA STORED"<<endl;
break;
}
}
}
template<typename T>
void getnewyear(T &obj)
//function to get new year from the user
//return :void
//parametrs: any object
{
string num;
while(1)
{
cout<<"ENTER THE YEAR"<<endl;
cin>>num;
if(num.size()!=4)//checking the user enterd a 4-digit number
{
cout<<"THE INPUT IS INVALID"<<endl;
}
else//otherwise yes the store the 4-digit number
{
obj.setyear(num);
cout<<"DATA STORED"<<endl;
break;
}
}
}
template<typename T>
void getnewodometer(T &obj)
//function to get new odometer from the user
//return :void
//parametrs: any object
{
string num;
int flag=0;
while(1)
{
flag=0;
cout<<"ENTER THE ODOMETER"<<endl;
cin>>num;
for(int i=0;i<5;i++)
{
if(isalpha(num[i]))//checking that the user entered a number not alpphabets
{
flag=1;//if yes flag
}
}
if(flag==0)
{
obj.setodometer(num);
cout<<"DATA STORED"<<endl;
break;
}
else
{
cout<<"INVALID DATA ENTER AGAIN"<<endl;
}
}
cout<<"ENTER THE CAR NUMBER"<<endl;
cin>>obj.car_no;
}
template <typename T>
void addvehicle(T &obj)
//function to add vehicle to the list
//return::void
//parameters::any object through template functionality
{
getnewmake<T>(obj);
getnewmodel<T>(obj);
getnewodometer<T>(obj);
getnewyear<T>(obj);
}
void listvehicle()
//function to display all the vehicles in the list include gas,electric,diesel
{
int g=0,d=0,e=0;
int a=1,b=1,c=1;
cout<<"list"<<endl;
while(g1[g].getmake()!="\0")//checking the array of objects until it is empty
{
cout<<"RECORD NO--G"<<a<<endl;
cout<<g1[g].getmake()<<endl;
cout<<g1[g].getmodel()<<endl;
cout<<g1[g].getodometer()<<endl;
cout<<g1[g].getyear()<<endl;
cout<<g1[g].car_no;
cout<<" "<<endl;
cout<<" "<<endl;
g++;
a++;
}
while(d1[d].getmake()!="\0")//checking the array of objects until it is empty
{
cout<<"RECORD NO--D"<<b<<endl;
cout<<d1[d].getmake()<<endl;
cout<<d1[d].getmodel()<<endl;
cout<<d1[d].getodometer()<<endl;
cout<<d1[d].getyear()<<endl;
cout<<d1[d].car_no;
cout<<" "<<endl;
cout<<" "<<endl;
d++;
b++;
}
while(e1[e].getmake()!="\0")//checking the array of objects until it is empty
{
cout<<"RECORD NO--E"<<c<<endl;
cout<<e1[e].getmake()<<endl;
cout<<e1[e].getmodel()<<endl;
cout<<e1[e].getodometer()<<endl;
cout<<e1[e].getyear()<<endl;
cout<<e1[e].car_no;
cout<<" "<<endl;
cout<<" "<<endl;
e++;
c++;
}
}
void updatevehicle()
//function to update a current vehicle from the list
//return ::void
//parameters::no parametrs
{
int num,i;
string str;
cout<<"ENTER WHICH TYPE"<<endl;
cout<<"1)ELECTRIC\n2)GAS\n3)DIESEL\n"<<endl;//user interface
cin>>num;
switch(num)
{
case 1:cout<<"WHICH RECORD"<<endl;//to select a particular list
cin>>num;
if(num-=1<k)//to make the index to start from zero and also to check the last index value reserved
{
getnewmake<electric_car>(e1[num]);
getnewmodel<electric_car>(e1[num]);
getnewodometer<electric_car>(e1[num]);
getnewyear<electric_car>(e1[num]);
}
else
{
cout<<"TRY AGAIN"<<endl;//if it doesnt match the ask to try again
cout<<"YOUR TOTAL RECORD IS ONLY "<<k<<endl;//for showing the total record available in a particular car
}
break;
case 2:cout<<"WHICH RECORD"<<endl;//to select a particular list
cin>>num;
if(num-=1<k)//to make the index to start from zero and also to check the last index value reserved
{
getnewmake<gas_car>(g1[num]);
getnewmodel<gas_car>(g1[num]);
getnewodometer<gas_car>(g1[num]);
getnewyear<gas_car>(g1[num]);
}
else
{
cout<<"TRY AGAIN"<<endl;//if it doesnt match the ask to try again
cout<<"YOUR TOTAL RECORD IS ONLY "<<i<<endl;//for showing the total record available in a particular car
}
break;
case 3:cout<<"WHICH RECORD"<<endl;//to select a particular list
cin>>num;
if(num-=1<k)//to make the index to start from zero and also to check the last index value reserved
{
getnewmake<diesel_car>(d1[num]);
getnewmodel<diesel_car>(d1[num]);
getnewodometer<diesel_car>(d1[num]);
getnewyear<diesel_car>(d1[num]);
}
else
{
cout<<"TRY AGAIN"<<endl;//if it doesnt match the ask to try again
cout<<"YOUR TOTAL RECORD IS ONLY "<<j<<endl;//for showing the total record available in a particular car
}
break;
default:cout<<"WRONG ENTRY"<<endl;//otherwise enter wrong entry
break;
}
}
void removevehicle()
//function to remove a particular data from the list
//return::void
//parameters::no parameters
{
int num;
string str="NULL";
cout<<"ENTER WHICH TYPE"<<endl;
cout<<"1)ELECTRIC\n2)GAS\n3)DIESEL\n"<<endl;//user interface
cin>>num;
switch(num)
{
case 1:cout<<"WHICH RECORD"<<endl;//record selection to remove car
cin>>num;
if(num<=k)//to check the record exeeds the last index
{
e1[num-1].setmake(str);
e1[num-1].setmodel(str);
e1[num-1].setodometer(str);
e1[num-1].setyear(str);
e1[num-1].car_no=str;
}
else
{
cout<<"TRY AGAIN"<<endl;//if exeeds the show try again
cout<<"YOUR TOTAL RECORD IS ONLY "<<k<<endl;//and list the number of records you have
}
break;
case 2:cout<<"WHICH RECORD"<<endl;//record selection to remove car
cin>>num;
if(num<=k)//to check the record exeeds the last index
{
g1[num-1].setmake(str);
g1[num-1].setmodel(str);
g1[num-1].setodometer(str);
g1[num-1].setyear(str);
g1[num-1].car_no=str;
}
else
{
cout<<"TRY AGAIN"<<endl;//if exeeds the show try again
cout<<"YOUR TOTAL RECORD IS ONLY "<<i<<endl;//and list the number of records you have
}
break;
case 3:cout<<"WHICH RECORD"<<endl;//record selection to remove car
cin>>num;
if(num<=k)//to check the record exeeds the last index
{
d1[num-1].setmake(str);
d1[num-1].setmodel(str);
d1[num-1].setodometer(str);
d1[num-1].setyear(str);
d1[num-1].car_no=str;
}
else
{
cout<<"TRY AGAIN"<<endl;//if exeeds the show try again
cout<<"YOUR TOTAL RECORD IS ONLY "<<j<<endl;//and list the number of records you have
}
break;
default:cout<<"WRONG ENTRY"<<endl;//else print wrong entry
break;
}
}
void tirerotation(int num )
//function to check for tirerotaion for electrical vehicle based on odometer reading
//return::void
//parametrs::int
{
e1[num].checkTireRotation();//checking for that particular index which is selected through get_carinfo function
}
void recharge(int num)
//function to check for recharge for electrical vehicle based on odometer reading
//return::void
//parametrs::int
{
e1[num].checkchargepower();//checking for that particular index which is selected through get_carinfo function
}
void select_car()
//function to select car to add to the list
//return::void
//parameters::no parameters
{
int ch;
cout<<"ENTER YOUR TYPE"<<endl;//user interface
cout<<"ELECTRIC"<<endl;
cout<<"GAS"<<endl;
cout<<"DIESEL"<<endl;
cin>>ch;
switch(ch)
{
case 1:addvehicle<electric_car>( e1[k]);//function call to add the details of the electric car
k++;
break;
case 2:addvehicle<gas_car>(g1[i]);//function call to add the details of the gas car
i++;
break;
case 3:addvehicle<diesel_car>(d1[j]);//function call to add the details of the diesel car
j++;
break;
default:cout<<"ERONG INPUT"<<endl;//by default show wrong input
break;
}
}
int main()
{
int ch;
default_data();//to load with default value
while(1)//for infinitly displaying the menu
{
cout<<"MENU"<<endl;//user interface
cout<< " 0. QUIT.\n";
cout<< " 1. LIST INVENTARY.\n";
cout<< " 2. ADD VEHICLE.\n";
cout<< " 3. GET CAR INFO\n";
cout<< " 4. UPDATE VEHICLE\n";
cout<< " 5. REMOVE VEHICLE\n";
cout<< " 6. TIRE ROTATION ("<<data1<<")"<<endl;
cout<< " 7. OIL CHANGE ("<<data2<<")"<<endl;
cout<< " 8. RECHARGE ("<<data3<<")"<<endl;
cin>>ch;
switch(ch)
{
case 0:exit(0);
case 1:listvehicle();//function call for listing the vehicle
break;
case 2:select_car();//function for adding the vehicle by selecting a car
break;
case 3:getcar_info();//function for getting the car details by car_number serach
break;
case 4:updatevehicle();//for updating an existing vehicle
break;
case 5:removevehicle();//for removing an existing vehicle
break;
case 6:if(index1!=-1)//checking that the user selected any car and that must be electric
{
tirerotation(index1);
}
else
{
cout<<"not applicable"<<endl;
data1="NOT APPLICABLE";//service status for that particular vehicle selected
data2="NOT APPLICABLE";//service status for that particular vehicle selected
data3="NOT APPLICABLE";//service status for that particular vehicle selected
}
break;
case 7:if(index2!=-1)//checking the vehicle is gas or diesel to show perform an oil check
{
fv.check_oil(d1[index2]);
index2=-1;
}
else if(index3!=-1)
{
fv.check_oil(g1[index3]);
index3=-1;
}
else
{
cout<<"NOT APPLICABLE"<<endl;
data1="NOT APPLICABLE";//service status for that particular vehicle selected
data2="NOT APPLICABLE";//service status for that particular vehicle selected
data3="NOT APPLICABLE";//service status for that particular vehicle selected
}
break;
case 8:if(index1!=-1)//checking that the user selected any car and that must be electric
{
recharge(index1);
index1=-1;
}
else
{
cout<<"not applicable"<<endl;
data1="NOT APPLICABLE";//service status for that particular vehicle selected
data2="NOT APPLICABLE";//service status for that particular vehicle selected
data3="NOT APPLICABLE";//service status for that particular vehicle selected
}
break;
default:cout<<"WRONG ONPUT"<<endl;
break;
}
}
}
.c file on online gdb -- https://onlinegdb.com/fCmdmsUu2
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.