Project 3
#include <iostream>
#include <string>
using namespace std;
enum Type {
GAS,
DIESEL,
ELECTRIC
};
class Vehicle {
protected:
string make;
string model;
int year;
int odometer;
public:
Vehicle(string make, string model, int year, int odometer)
: make(make), model(model), year(year), odometer(odometer) {}
string getMake() {
return make;
}
void setMake(string make) {
this->make = make;
}
string getModel() {
return model;
}
void setModel(string model) {
this->model = model;
}
int getYear() {
return year;
}
void setYear(int year) {
this->year = year;
}
int getOdometer() {
return odometer;
}
void setOdometer(int odometer) {
this->odometer = odometer;
}
void checkTireRotation() {
int remainder = odometer % 50000;
if (remainder >= 0) {
cout << "Tire Rotate advised" << endl;
} else {
cout << "Tires are good to go" << endl;
}
}
void checkOil() {
std::cout << "Checking oil for Fuel Vehicle." << std::endl;
}
};
class GasCar : public Vehicle {
public:
GasCar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer) {}
};
class DieselCar : public Vehicle {
public:
DieselCar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer) {}
};
class ElectricCar : public Vehicle {
public:
ElectricCar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer) {}
void checkChargerPower() {
if (odometer >= 400) {
cout << "Please recharge your battery." << endl;
} else {
cout << "Your vehicle is good to go." << endl;
}
}
};
int main() {
string make, model;
int year, odometer;
int choice;
// Call the checkOil function
Type t;
GasCar car("", "", 0, 0);
DieselCar truck("", "", 0, 0);
ElectricCar tesla("", "", 0, 0);
cout << "Enter vehicle make: ";
cin >> make;
cout << "Enter vehicle model: ";
cin >> model;
cout << "Enter vehicle year: ";
cin >> year;
cout << "Enter vehicle odometer reading: ";
cin >> odometer;
cout << "Select a vehicle type (1: Gas Car, 2: Diesel Car, 3: Electric Car): ";
cin >> choice;
switch (choice) {
case 1:
car = GasCar(make, model, year, odometer);
break;
case 2:
truck = DieselCar(make, model, year, odometer);
break;
case 3:
tesla = ElectricCar(make, model, year, odometer);
break;
default:
cout << "Invalid choice" << endl;
return 1;
}
int option;
do {
cout << "Menu:\n";
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 your choice: ";
cin >> option;
switch (option) {
case 1:
cout<<"list"<< t<<endl;
break;
case 2:
cout<<"list added"<<endl;
break;
case 3:
cout<<"list updated"<<endl;
break;
case 4:
cout<<"removed vehicle"<<endl;
break;
case 5:
if(choice==1){
car.checkTireRotation();
}
else if(choice==2){
truck.checkTireRotation();
}
else{
tesla.checkTireRotation();
}
break;
case 6:
if(choice==3){
cout<<"no fuelcheck needed"<<endl;
}
else if(choice==2){
car.checkOil();
}
else{
truck.checkOil();
}
case 7:
if (choice == 3) {
tesla.checkChargerPower();
} else {
cout << "No need to check for ChargerPower" << endl;
}
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (option != 0);
return 0;
}
OUTPUT:
