Project 3
Program:
#include
using namespace std;
#include
#include
//Vehicle Class
class Vehicle {
protected:
string cartype;//Type of vehicle
string make; //make
string model; // model
int year; // year
string Newmake; //make
string Newmodel; // model
string Newcartype;
public:
int Odometer_reading; // miles on car
int NewOdometer_reading;
//virtual Type fun() = 0;
// int getType(){return Type;}
//mutator and accessor functions
void setcartype(string);//setter
void setMake(string);
void setModel(string);
void setYear(int);
void setOdometer_reading(int);
void setNewcartype(string);
void setNewMake(string);
void setNewModel(string);
void setNewOdometer_reading(int);
void check_TyreCharge();
void TireRotation();
void TireRotationrequired();
void checkChargerPower();
string getcartype();//getter
string getMake();
string getModel();
int getYear();
int getOdometer_reading();
string getNewcartype();
string getNewMake();
string getNewModel();
int getNewOdometer_reading();
void addvehicle();
void ListVehicle();
void removeVehicle();
void OilChange();
void UpdateVehicle();
void userInput();
void Recharge();
void selectcar();
// virtual Type getType()=0;
};
void Vehicle::setcartype(string cartype) {
this->cartype = cartype;
}
void Vehicle::setMake(string make) {
this->make = make;
}
void Vehicle::setModel(string model) {
this->model = model;
}
void Vehicle::setYear(int year) {
this->year = year;
}
void Vehicle::setOdometer_reading(int Odometer_reading) {
this->Odometer_reading = Odometer_reading ;
}
void Vehicle::setNewcartype(string Newcartype) {
this->Newcartype = Newcartype;
}
void Vehicle::setNewMake(string Newmake) {
this->Newmake = Newmake;
}
void Vehicle::setNewModel(string Newmodel) {
this->Newmodel = Newmodel;
}
void Vehicle::setNewOdometer_reading(int NewOdometer_reading) {
this->NewOdometer_reading = NewOdometer_reading ;
}
string Vehicle::getcartype() {
return cartype;
}
string Vehicle::getMake() {
return make;
}
string Vehicle::getModel() {
return model;
}
int Vehicle::getYear() {
return year;
}
int Vehicle::getOdometer_reading() {
return Odometer_reading;
}
string Vehicle::getNewcartype() {
return Newcartype;
}
string Vehicle::getNewMake() {
return Newmake;
}
string Vehicle::getNewModel() {
return Newmodel;
}
int Vehicle::getNewOdometer_reading() {
return NewOdometer_reading;
}
void Vehicle ::TireRotationrequired()
{
cout<<"Rotation for Tyre Required"< } void Vehicle :: checkChargerPower() { cout<<"Recharge Required"< } void Vehicle:: check_TyreCharge() { if (Vehicle::Odometer_reading>400 && Vehicle::Odometer_reading<50000>
{ checkChargerPower(); } else if (Vehicle::Odometer_reading>50000) { TireRotationrequired(); checkChargerPower(); } else { cout<<"No Tyre Rotation and Recharge Required"< } } void Vehicle:: UpdateVehicle(){ // Creating a list list // Add elements to the List demoList.push_back("Masaratti"); demoList.push_back("Mustang"); demoList.push_back("porche"); demoList.push_back("volkswogan"); demoList.push_back("Benz"); // List before removing elements cout << "Lists of the vehicles after updating: "< for (auto itr = demoList.begin(); itr != demoList.end(); itr++) { cout << *itr << " "< } cout<<"Vehicle List has been updated to Inventory Successfully!!! "< } void Vehicle:: addvehicle(){ string name; cout<<"Enter the vehicle to be added"< cin>>name; } void Vehicle:: ListVehicle(){ // Creating a list list // Add elements to the List demoList.push_back("Masaratti"); demoList.push_back("Mustang"); demoList.push_back("porche"); demoList.push_back("volkswogan"); // List before removing elements cout << "Lists of the vehicles : "< for (auto itr = demoList.begin(); itr != demoList.end(); itr++) { cout << *itr << " "< } } void Vehicle ::removeVehicle(){ list // Add elements to the List demoList.push_back("Benz"); demoList.push_back("Masaratti"); demoList.push_back("Mustang"); demoList.push_back("porche"); demoList.push_back("volkswogan"); // List before removing elements for (auto itr = demoList.begin(); itr != demoList.end(); itr++) { } demoList.remove("Benz"); // List after removing elements cout << "\nList after removing a vehicle : "; for (auto itr = demoList.begin(); itr != demoList.end(); itr++) { cout << *itr << " "< } } void Vehicle:: OilChange(){ if(Vehicle::cartype != "Electric"){ cout<<"Oil change has been done "< } else{ cout<<"This option is not for your vehicle type ....."< } } void Vehicle ::TireRotation() { cout<<"Rotation of Tyre is done "< } void Vehicle :: Recharge() { cout<<"Recharging..."< cout<<"Recharge Successfull !!!"< } void Vehicle :: selectcar(){ ListVehicle(); string car; cin>>car; } void Vehicle:: userInput(){ cout<< "0. Quit.\n"< cout<< "1. List inventory.\n"< cout<< "2. Add vehicle.\n"< cout<< "3. Update vehicle\n"< cout<< "4. Remove vehicle\n"< cout<< "5. Tire Rotation\n"< cout<< "6. Oil Change\n"< cout<< "7. Recharge\n"< //cout<<"Enter the Number"< int num; for(int i=0;i<8>
cout<<"Enter the Number"< cin>>num; if(num == 0){ cout << "Exited Successfully "< break; } else{ switch (num) { case 1: ListVehicle(); break; case 2: addvehicle(); break; case 3: UpdateVehicle(); break; case 4: removeVehicle(); break; case 5: TireRotation(); break; case 6: OilChange(); break; case 7: Recharge(); break; default : continue; } } } } enum Type{ GAS, DIESEL, ELECTRIC }; /*string userInput; cout << "What is your fueltype : "; cin >> userInput; Type userThrow = static_cast int main(){ Type fuel = ELECTRIC; cout<<"Fuel type 1=Gas ,2=Diesel ,3= Electric : "< //cin>>fuel; Vehicle obj; obj.setcartype("electric"); obj.setMake("T∧T∧"); obj.setModel("Nexon"); obj.setYear(2020); obj.setOdometer_reading(50001); obj.check_TyreCharge(); cout<<"Car Type :"< cout<<"Car Make :"< cout<<"Car Model :"< cout<<"Year :"< cout<<"Distance Travelled :"< obj.userInput(); obj.setNewcartype("petrol"); obj.setNewMake("T∧T∧"); obj.setNewModel("Jaguar"); obj.setYear(2019); obj.setNewOdometer_reading(10000); cout<<"New Car Type :"< cout<<"New Car Make :"< cout<<"New Car Model :"< cout<<"Year :"< cout<<"New Car Distance Travelled :"< obj.selectcar(); obj.setNewOdometer_reading(1000); cout<<"New Car Distance Travelled :"< return 0; } Output: Fuel type 1=Gas ,2=Diesel ,3= Electric : 3 Rotation for Tyre Required Recharge Required Car Type :electriccar Car Make :T∧T∧ Car Model :Nexon Year :2020 Distance Travelled :50001 Km 0. Quit. 1. List inventory. 2. Add vehicle. 3. Update vehicle 4. Remove vehicle 5. Tire Rotation 6. Oil Change 7. Recharge Enter the Number 1 Lists of the vehicles : Masaratti Mustang porche volkswogan Enter the Number 2 Enter the vehicle to be added 3 Enter the Number 4 List after removing a vehicle : Masaratti Mustang porche volkswogan Enter the Number 5 Rotation of Tyre is done Enter the Number 6 Oil change has been done Enter the Number 7 Recharging... Recharge Successfull !!! Enter the Number 0 Exited Successfully New Car Type :petrolcar New Car Make :T∧T∧ New Car Model :Jaguar Year :2019 New Car Distance Travelled :10000 Km Lists of the vehicles : Masaratti Mustang porche volkswogan