Project 3
/*
* Project3.cpp
*
* Created on: 07-Sep-2023
* Author: RAJASEKAR R
* Description: Build an object-oriented library which can be used to track automobile maintenance.
*/
// preprocessor defined
#include // include library for standard input/output function
#include // for dynamic arrays.
#include
using namespace std;
// enumerated type for vehicle fuel type is defined
enum Type{
// elements
GAS,
DIESEL,
ELECTRIC
};
// Base class defined
class Vehicle
{
protected:// access specifier
//class members
string make;
string model;
int year;
long int odometer;
public: // access specifier
// constructor for the class and the members are initialize
Vehicle(string s, string r, int k, long int odo_n):make(s),model(r),year(k),odometer(odo_n){}
// set functions for make, model, year, odometer
void set_Make(string s)
{
make = s;
}
void set_Model(string r)
{
model = r;
}
void set_Year(int k)
{
year = k;
}
void set_Odometer(long int odo_n)
{
odometer = odo_n;
}
// get function for make, model, year, odometer
string get_Make()
const
{
return make;
}
string get_Model()
const
{
return model;
}
int get_Year()
const
{
return year;
}
long int get_Odometer()
const
{
return odometer;
}
// pure virtual function for vechicle type, check_tire_rotation,oil_change, check_power
virtual Type getType() = 0;
virtual void check_Tire_Rotation() = 0;
virtual void oil_Change() = 0;
virtual void check_Power() = 0;
virtual void get_Car_Information() = 0;
// virtual destructor for the vehicle class
virtual ~Vehicle() {}
};
// derived class from the base class
class GasCar:public Vehicle
{
public: // access specifier
// constructor for the class and the members are initialize
GasCar(string s, string r, int k, int odo_n):Vehicle(s,r,k,odo_n){}
// function for return the fuel type
Type getType()
{
return GAS;
}
// function that check the tire of the vehicle
void check_Tire_Rotation()
{
int distance = odometer P000;
if(distance >= 0)
{
cout<<"Advise to tire rotate"<
}
else
{
cout<<"Tires are good to Run"<
}
}
// function for used to get information
void get_Car_Information()
{
cout<<"------VEHICLE DETAILS------"<
cout<<"\nMAKE:"<
}
// function that check the oil_change
void oil_Change()
{
int oill = odometer 00;
if(oill < 10>
{
cout<<"OIL NEED TO CHANGE"<
}
else
{
cout<<"VEHICLE TO GO"<
}
}
// function that check the power
void check_Power()
{
int distance = odometer @0;
if(distance == 0)
{
cout<<"Advise to re-charge the battery"<
}
else
{
cout<<"Vehicle is good to go"<
}
}
};
// derived class from the base class
class DieselCar:public Vehicle
{
public: // access specifier
// constructor for the class and the members are initialize
DieselCar(string s, string r, int k, int odo_n):Vehicle(s,r,k,odo_n){}
// function for return the fuel type
Type getType()
{
return DIESEL;
}
// function that check the tire of the vehicle
void check_Tire_Rotation()
{
int distance = odometer P000;
if(distance >= 0)
{
cout<<"Advise to tire rotate"<
}
else
{
cout<<"Tires are good to Run"<
}
}
// function for used to get information
void get_Car_Information()
{
cout<<"------VEHICLE DETAILS------"<
cout<<"\nMAKE:"<
}
// function that check the oil_change
void oil_Change()
{
int oill = odometer 00;
if(oill < 10>
{
cout<<"OIL NEED TO CHANGE"<
}
else
{
cout<<"VEHICLE TO GO"<
}
}
// function that check the power
void check_Power()
{
int distance = odometer @0;
if(distance == 0)
{
cout<<"Advise to re-charge the battery"<
}
else
{
cout<<"Vehicle is good to go"<
}
}
};
// derived class from the base class
class ElectricCar:public Vehicle
{
public: // public specifier
ElectricCar(string s, string r, int k, int odo_n):Vehicle(s,r,k,odo_n){}
// function for return the fuel type
Type getType()
{
return ELECTRIC;
}
// function that check the tire of the vehicle
void check_Tire_Rotation()
{
int distance = odometer P000;
if(distance >= 0)
{
cout<<"Advise to tire rotate"<
}
else
{
cout<<"Tires are good to Run"<
}
}
// function that check the power
void check_Power()
{
int distance = odometer 00;
if(distance == 0)
{
cout<<"Advise to re-charge the battery"<
}
else
{
cout<<"Vehicle is good to go"<
}
}
// function that check the oil_change
void oil_Change()
{
int oill = odometer 00;
if(oill < 10>
{
cout<<"OIL NEED TO CHANGE"<
}
else
{
cout<<"VEHICLE TO GO"<
}
}
// function for used to get information
void get_Car_Information()
{
cout<<"------VEHICLE DETAILS------"<
cout<<"\nMAKE:"<
}
};
// Function creates a new vehicle object based on user input and returns a pointer to that object.
Vehicle *add_Vehicle()
{
// Declare variables for user input
string make;
string model;
int year;
long int odometer;
int choice;
// menu for user to select a vehicle type
cout<<"---VEHICLE MENU---"
<<"\n1.GAS"
<<"\n2.DIESEL"
<<"\n3.ELECTRIC"
<<"\nENTER THE TYPE:"<
cin>>choice;
// use while loops user input for make,model,year,odometer
// enter make until a non empty string is entered.
while(1)
{
cout<<"ENTER THE MAKE:"<
cin>>make;
if(!make.empty())
{
break;
}
}
// enter model until a non empty string is entered.
while(1)
{
cout<<"ENTER THE MODEL:"<
cin>>model;
if(!model.empty())
{
break;
}
}
// enter year until a non empty integer is entered.
while(1)
{
cout<<"ENTER THE MAKE_YEAR:"<
cin>>year;
if(year != EOF)
{
break;
}
}
// enter odometer until a non empty integer is entered.
while(1)
{
cout<<"ENTER THE READINNG OF THE ODOMETER:"<
cin>>odometer;
if(odometer != EOF)
{
break;
}
}
// user choice and input
switch(choice)
{
case 1:
{
return new GasCar(make,model,year,odometer);
break;
}
case 2:
{
return new DieselCar(make,model,year,odometer);
break;
}
case 3:
{
return new ElectricCar(make,model,year,odometer);
break;
}
default:
{
cout<<"INVALID INPUT!!!.."<
exit (0);
}
}
}
void list_Vehicle(vector list)
{
// check the list is empty
if(list.empty())
{
cout<<"LIST IS EMPTY"<
}
else
{
cout<<"LIST"<
int j = list.size();
// iteration for displaying the details
for(int i =0; i < j>
cout<<"VEHICLE DETAILS:"<
list[i]->get_Car_Information();
list[i]->check_Tire_Rotation();
}
}
}
void delete_Vehicle(vector list)
{
// check the list is empty
if(list.empty())
{
cout<<"LIST IS EMPTY"<
}
else
{
int choice;
while(1)
{
// get the input from the user for delete the list
cout<<"\nTOTAL LIST:"<
cin>>choice;
if(choice >= 1 && choice <= list.size())
{
// delete the vehicle from the memory and vector list.
delete list[choice - 1];
list.erase(list.begin() + choice -1);
cout<<"LIST DELETE:"<
}
}
}
}
// main function to initiate the program.
int main()
{
// vector pointer declared for the vehicle object.
vectorstore;
// local variable
int choice_;
// for clering the console buffer
fflush(stdout);
while(1)
{
// menuy for get the input from the user
cout<<"---MENU---"
<<"\n0.QUIT"
<<"\n1.LIST INVENTORY"
<<"\n2.ADD VEHICLE"
<<"\n3.UPDATE VEHICLE"
<<"\n4.REMOVE VEHICLE"
<<"\n5.TIRE ROTATION"
<<"\n6.OIL CHANGE"
<<"\n7.RECHARGE"
<<"\nENTER YOUR CHOICE:"<
// user input
cin>>choice_;
//using switch perform the operation by get the innput from the user.
switch(choice_)
{
case 0:
{
cout<<"QUIT....THANKYOU"<
break ;
}
case 1:
{
//for printing the list.
for(Vehicle *Vehicle: store)
{
Vehicle->get_Car_Information();
}
break;
}
case 2:
{
// function for add vehicle
Vehicle *Vehicle = add_Vehicle();
store.push_back(Vehicle);
break;
}
case 3:
{
int no; int ch;
cout<<"ENTER THE LIST NUMBER YOU WANT TO UPDATE:"<
cin>>no;
no -= 1;
if((no >= 0)&&(no < store>
{
Vehicle *Vehicle = store[no];
string make;
string model;
int year;
long int odometer;
while(1)
{
cout<<"ENTER THE MAKE:"<
cin>>make;
Vehicle->set_Make(make);
if(!make.empty())
{
break;
}
}
while(1)
{
cout<<"ENTER THE MODEL:"<
cin>>model;
Vehicle->set_Model(model);
if(!model.empty())
{
break;
}
}
while(1)
{
cout<<"ENTER THE YEAR:"<
cin>>year;
Vehicle->set_Year(year);
if(year != 0)
{
break;
}
}
while(1)
{
cout<<"ENTER THE READING:"<
cin>>odometer;
Vehicle->set_Odometer(odometer);
if(odometer != 0)
{
break;
}
}
}
else
{
cout<<"INVALID OPTION"<
}
break;
}
case 4:
{
int no;
cout<<"LIST TOTAL NUMBERS:"<
<<"\nENTER THE LIST NUMBER YOU WANT TO DELETE OR REMOVE FROM THE LIST:"<
cin>>no;
no -= 1;
if((no >= 0)&&(no < store>
{
delete store[no];
store.erase(store.begin() + no);
}
else
{
cout<<"INVALID OPTION !!.."<
}
break;
}
case 5:
{
int no;
cout<<"LIST TOTAL NUMBERS:"<
<<"\nENTER THE LIST NUMBER YOU WANT TO CHECK:"<
cin>>no;
no -= 1;
if((no >= 0)&&(no < store>
{
store[no]->check_Tire_Rotation();
}
else
{
cout<<"INVALID OPTION !!.."<
}
break;
}
case 6:
{
int no;
cout<<"LIST TOTAL NUMBERS:"<
<<"\nENTER THE LIST NUMBER YOU WANT TO CHECK:"<
cin>>no;
no -= 1;
if((no >= 0)&&(no < store>
{
store[no]->oil_Change();
}
else
{
cout<<"INVALID OPTION !!.."<
}
break;
}
case 7:
{
int no;
cout<<"LIST TOTAL NUMBERS:"<
<<"\nENTER THE LIST NUMBER YOU WANT TO CHECK:"<
cin>>no;
no -= 1;
if((no >= 0)&&(no < store>
{
store[no]->check_Power();
}
else
{
cout<<"INVALID OPTION !!.."<
}
break;
}
}
}
return 0;
}
OUTPUT:
1.MENU DISPLAY:

2. ADD VEHICLE:



3.LIST INVENTORY:

4. UPDATE VEHICLE:


5.REMOVE VEHICLE:


6.TIRE ROTATION:

7.OIL CHANGE:
8. RECHARGE: