Project 3
#include<iostream>
#include<string>
using namespace std;
enum Type {
GAS,
DIESEL,
ELECTRIC
};
class Vehicle{
protected:
string make, model;
int year;
float odometer;
public:
void setMake() {
cout << "Enter the make of the vehicle: ";
cin >> make;
}
void putMake() const {
cout << "\t" << make << endl;
}
void setModel() {
cout << "Enter the model of the vehicle: ";
cin >> model;
}
void putModel() const {
cout << "\t" << model << endl;
}
void setYear() {
cout << "Enter the year of the vehicle: ";
cin >> year;
}
void putYear() const {
cout << "\t" << year << endl;
}
void setOdometer() {
cout << "Enter odometer reading: ";
cin >> odometer;
}
void putOdometer() const {
cout << "\t" << odometer << endl;
}
};
class GasCar : public Vehicle {
public:
GasCar(string make, string model, int year, float odometer) : Vehicle() {
this->make = make;
this->model = model;
this->year = year;
this->odometer = odometer;
}
void getCarInformation() const {
cout << "Make: " << make << endl;
cout << "Model: " << model << endl;
cout << "Year: " << year << endl;
cout << "Odometer Reading: " << odometer << endl;
}
Type getType() const {
return GAS;
}
string getFuelType() const {
return "Petrol";
}
void checkTireRotation() const {
if (odometer > 50000)
cout << "Tyre rotation to be done." << endl;
else
cout << "Less than 50000 kms. Tyre rotation can be done in next visit." << endl;
}
};
class DieselCar : public Vehicle {
public:
DieselCar(string make, string model, int year, float odometer) : Vehicle() {
this->make = make;
this->model = model;
this->year = year;
this->odometer = odometer;
}
void getCarInformation() const {
cout << "Make: " << make << endl;
cout << "Model: " << model << endl;
cout << "Year: " << year << endl;
cout << "Odometer Reading: " << odometer << endl;
}
Type getType() const {
return DIESEL;
}
string getFuelType() const {
return "Diesel";
}
void checkTireRotation() const {
if (odometer > 50000)
cout << "Tyre rotation to be done." << endl;
else
cout << "Less than 50000 kms. Tyre rotation can be done in next visit." << endl;
}
};
class ElectricCar : public Vehicle {
public:
ElectricCar(string make, string model, int year, float odometer) : Vehicle() {
this->make = make;
this->model = model;
this->year = year;
this->odometer = odometer;
}
void getCarInformation() const {
cout << "Make: " << make << endl;
cout << "Model: " << model << endl;
cout << "Year: " << year << endl;
cout << "Odometer Reading: " << odometer << endl;
}
Type getType() const {
return ELECTRIC;
}
string getFuelType() const {
return "Electric";
}
void checkTireRotation() const {
if (odometer > 50000)
cout << "Tyre rotation to be done." << endl;
else
cout << "Less than 50000 kms. Tyre rotation can be done in next visit." << endl;
}
};
void menuDisplay() {
cout << "0. Quit\n";
cout << "1. Display Services\n";
cout << "2. Add Vehicle\n";
}
void displayServices() {
cout<<"Maintenance tasks include activities like oil change"<<endl;
cout<<"Replace oil filter, replace air filter, replace fuel filter"<<endl;
cout<<"Replace spark plugs"<<endl;
cout<<"Replace the cabin"<<endl;
cout<<"A/c filter, check the level"<<endl;
cout<<"Refill clutch fluid or brake fluid"<<endl;
cout<<"Examine belts, wipers, hoses"<<endl;
cout<<"Check the tire conditions"<<endl;
cout<<"Check the charging systems and battery."<<endl;
}
int main() {
int user_choice;
string make, model;
int year;
float odometer;
beginning:
menuDisplay();
cout << "Enter your choice: ";
cin >> user_choice;
switch (user_choice) {
case 0:
cout << "Exiting the program.";
break;
case 1:
displayServices();
goto beginning;
case 2:
int choice;
cout<<"Enter the type of vehicle:"<<endl;
cout<<"1.Petrol"<<endl;
cout<<"2.Diesel"<<endl;
cout<<"3.Electric"<<endl;
cin>>choice;
if(choice==1){
GasCar *myGasCar;
myGasCar = new GasCar(make, model, year, odometer);
myGasCar->setMake();
myGasCar->putMake();
myGasCar->setModel();
myGasCar->putModel();
myGasCar->setYear();
myGasCar->putYear();
myGasCar->setOdometer();
myGasCar->putOdometer();
cout << "Gas Car Information:" << endl;
myGasCar->getCarInformation();
cout << "Fuel Type: " << myGasCar->getFuelType() << endl;
myGasCar->checkTireRotation();
goto beginning;
}
else if(choice==2){
DieselCar *myDieselCar;
myDieselCar = new DieselCar(make, model, year, odometer);
myDieselCar->setMake();
myDieselCar->putMake();
myDieselCar->setModel();
myDieselCar->putModel();
myDieselCar->setYear();
myDieselCar->putYear();
myDieselCar->setOdometer();
myDieselCar->putOdometer();
cout << "Gas Car Information:" << endl;
myDieselCar->getCarInformation();
cout << "Fuel Type: " << myDieselCar->getFuelType() << endl;
myDieselCar->checkTireRotation();
//cout<<"\n"<<endl;
goto beginning;
}
else if(choice==3){
ElectricCar *myElectricCar;
myElectricCar = new ElectricCar(make, model, year, odometer);
myElectricCar->setMake();
myElectricCar->putMake();
myElectricCar->setModel();
myElectricCar->putModel();
myElectricCar->setYear();
myElectricCar->putYear();
myElectricCar->setOdometer();
myElectricCar->putOdometer();
cout << "Gas Car Information:" << endl;
myElectricCar->getCarInformation();
cout << "Fuel Type: " << myElectricCar->getFuelType() << endl;
myElectricCar->checkTireRotation();
//cout<<"\n"<<endl;
goto beginning;
}
else{
cout<<"Give correct option.";
}
default:
cout<<"Enter correct option."<<endl;
goto beginning;
}
}