Project 3
#include
#include
enum Type {
GAS,
DIESEL,
ELECTRIC
};
class Vehicle {
protected:
std::string make;
std::string model;
int year;
int odometer;
public:
Vehicle(const std::string& make, const std::string& model, int year, int odometer)
: make(make), model(model), year(year), odometer(odometer) {}
// Getter and setter functions
std::string getMake() const { return make; }
std::string getModel() const { return model; }
int getYear() const { return year; }
int getOdometer() const { return odometer; }
void setMake(const std::string& newMake) { make = newMake; }
void setModel(const std::string& newModel) { model = newModel; }
void setYear(int newYear) { year = newYear; }
void setOdometer(int newOdometer) { odometer = newOdometer; }
// Maintenance activities
virtual void checkTireRotation() const = 0;
virtual void checkChargerPower() const = 0;
// Get car information
virtual Type getType() const = 0;
};
class GasCar : public Vehicle {
public:
GasCar(const std::string& make, const std::string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
Type getType() const override { return GAS; }
void checkTireRotation() const override {
int remainder = odometer P000;
if (remainder >= 0)
std::cout << "Gas car's tires are good to go." << std> else
std::cout << "Gas car needs tire rotation." << std> }
void checkChargerPower() const override {
std::cout << "Gas car's power is good to go." << std> }
};
class DieselCar : public Vehicle {
public:
DieselCar(const std::string& make, const std::string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
Type getType() const override { return DIESEL; }
void checkTireRotation() const override {
int remainder = odometer P000;
if (remainder >= 0)
std::cout << "Diesel car's tires are good to go." << std> else
std::cout << "Diesel car needs tire rotation." << std> }
void checkChargerPower() const override {
std::cout << "Diesel car's power is good to go." << std> }
};
class ElectricCar : public Vehicle {
public:
ElectricCar(const std::string& make, const std::string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
Type getType() const override { return ELECTRIC; }
void checkTireRotation() const override {
int remainder = odometer P000;
if (remainder >= 0)
std::cout << "Electric car's tires are good to go." << std> else
std::cout << "Electric car needs tire rotation." << std> }
void checkChargerPower() const override {
if (odometer >= 400)
std::cout << "Electric car needs a recharge." << std> else
std::cout << "Electric car's power is good to go." << std> }
};
class MaintenanceSystem {
private:
std::vector
public:
void addVehicle(Vehicle* vehicle) {
vehicles.push_back(vehicle);
}
void listVehicles() const {
for (size_t i = 0; i < vehicles> std::cout << "Vehicle " << i> std::cout << "Make: " << vehicles>getMake() << std> std::cout << "Model: " << vehicles>getModel() << std> std::cout << "Year: " << vehicles>getYear() << std> std::cout << "Odometer: " << vehicles>getOdometer() << std> std::cout << "Fuel Type: " << vehicles>getType() << std> vehicles[i]->checkTireRotation();
vehicles[i]->checkChargerPower();
std::cout << "-------------------------" << std> }
}
void updateVehicle(int index, const std::string& make, const std::string& model, int year, int odometer) {
if (index >= 0 && index < vehicles> vehicles[index]->setMake(make);
vehicles[index]->setModel(model);
vehicles[index]->setYear(year);
vehicles[index]->setOdometer(odometer);
}
}
void removeVehicle(int index) {
if (index >= 0 && index < vehicles> delete vehicles[index];
vehicles.erase(vehicles.begin() + index);
}
}
~MaintenanceSystem() {
for (auto vehicle : vehicles) {
delete vehicle;
}
}
};
int main() {
MaintenanceSystem maintenanceSystem;
while (true) {
std::cout << "Menu:" << std> std::cout << "0. Quit" << std> std::cout << "1. List inventory" << std> std::cout << "2. Add vehicle" << std> std::cout << "3. Update vehicle" << std> std::cout << "4. Remove vehicle" << std> std::cout << "5. Tire Rotation" << std> std::cout << "6. Oil Change" << std> std::cout << "7. Recharge" << std>
int choice;
std::cin >> choice;
if (choice == 0) {
break;
} else if (choice == 1) {
maintenanceSystem.listVehicles();
} else if (choice == 2) {
std::string make, model;
int year, odometer, type;
std::cout << "Enter make: ";
std::cin >> make;
std::cout << "Enter model: ";
std::cin >> model;
std::cout << "Enter year: ";
std::cin >> year;
std::cout << "Enter odometer: ";
std::cin >> odometer;
std::cout << "Enter type (0 for GAS, 1 for DIESEL, 2 for ELECTRIC): ";
std::cin >> type;
Vehicle* newVehicle = nullptr;
switch (type) {
case 0:
newVehicle = new GasCar(make, model, year, odometer);
break;
case 1:
newVehicle = new DieselCar(make, model, year, odometer);
break;
case 2:
newVehicle = new ElectricCar(make, model, year, odometer);
break;
default:
std::cout << "Invalid type." << std> break;
}
if (newVehicle) {
maintenanceSystem.addVehicle(newVehicle);
std::cout << "Vehicle added successfully." << std> }
} else if (choice == 3) {
int index;
std::string make, model;
int year, odometer;
std::cout << "Enter the index of the vehicle to update: ";
std::cin >> index;
std::cout << "Enter new make: ";
std::cin >> make;
std::cout << "Enter new model: ";
std::cin >> model;
std::cout << "Enter new year: ";
std::cin >> year;
std::cout << "Enter new odometer: ";
std::cin >> odometer;
maintenanceSystem.updateVehicle(index, make, model, year, odometer);
std::cout << "Vehicle updated successfully." << std> } else if (choice == 4) {
int index;
std::cout << "Enter the index of the vehicle to remove: ";
std::cin >> index;
maintenanceSystem.removeVehicle(index);
std::cout << "Vehicle removed successfully." << std> } else {
std::cout << "Invalid choice. Please try again." << std> }
}
return 0;
}

