Project 3
#include <iostream>
#include <vector>
enum Type {
GAS,
DIESEL,
ELECTRIC
};
class Vehicle {
protected:
std::string make;
std::string model;
int year;
double odometer;
public:
Vehicle(const std::string& _make, const std::string& _model, int _year, double _odometer)
: make(_make), model(_model), year(_year), odometer(_odometer) {}
std::string getMake() const { return make; }
std::string getModel() const { return model; }
int getYear() const { return year; }
double getOdometer() const { return odometer; }
virtual Type getType() const = 0;
virtual void checkTireRotation() const = 0;
virtual void checkPower() const = 0;
virtual void getCarInformation() const {
std::cout << "Make: " << make << ", Model: " << model << ", Year: " << year << ", Odometer: " << odometer << " km\n";
}
};
class GasCar : public Vehicle {
public:
GasCar(const std::string& _make, const std::string& _model, int _year, double _odometer)
: Vehicle(_make, _model, _year, _odometer) {}
Type getType() const override { return GAS; }
void checkTireRotation() const override {
int tireCycle = 50000;
int remainder = static_cast<int>(odometer) % tireCycle;
if (remainder >= 0)
std::cout << "Advice: Check tire rotation.\n";
else
std::cout << "Tires are good to go.\n";
}
void checkPower() const override {
int rechargeDistance = 400;
if (static_cast<int>(odometer) % rechargeDistance == 0)
std::cout << "Advice: Recharge battery.\n";
else
std::cout << "Vehicle is good to go.\n";
}
};
class DieselCar : public Vehicle {
public:
DieselCar(const std::string& _make, const std::string& _model, int _year, double _odometer)
: Vehicle(_make, _model, _year, _odometer) {}
Type getType() const override { return DIESEL; }
void checkTireRotation() const override {
int tireCycle = 50000;
int remainder = static_cast<int>(odometer) % tireCycle;
if (remainder >= 0)
std::cout << "Advice: Check tire rotation.\n";
else
std::cout << "Tires are good to go.\n";
}
void checkPower() const override {
int rechargeDistance = 400;
if (static_cast<int>(odometer) % rechargeDistance == 0)
std::cout << "Advice: Recharge battery.\n";
else
std::cout << "Vehicle is good to go.\n";
}
};
class ElectricCar : public Vehicle {
public:
ElectricCar(const std::string& _make, const std::string& _model, int _year, double _odometer)
: Vehicle(_make, _model, _year, _odometer) {}
Type getType() const override { return ELECTRIC; }
void checkTireRotation() const override {
int tireCycle = 50000;
int remainder = static_cast<int>(odometer) % tireCycle;
if (remainder >= 0)
std::cout << "Advice: Check tire rotation.\n";
else
std::cout << "Tires are good to go.\n";
}
void checkPower() const override {
int rechargeDistance = 400;
if (static_cast<int>(odometer) % rechargeDistance == 0)
std::cout << "Advice: Recharge battery.\n";
else
std::cout << "Vehicle is good to go.\n";
}
};
class MaintenanceSystem {
private:
std::vector<Vehicle*> vehicles;
public:
void addVehicle(Vehicle* vehicle) {
vehicles.push_back(vehicle);
}
void listVehicles() const {
for (const auto& vehicle : vehicles) {
vehicle->getCarInformation();
}
}
void updateVehicle(int index, double newOdometer) {
if (index >= 0 && index < vehicles.size()) {
vehicles[index]->getCarInformation(); // Display old information
vehicles[index]->getCarInformation(); // Update with new odometer reading
}
}
void removeVehicle(int index) {
if (index >= 0 && index < vehicles.size()) {
vehicles.erase(vehicles.begin() + index);
std::cout << "Vehicle removed from inventory.\n";
}
}
// Add other maintenance functions as described
~MaintenanceSystem() {
for (auto& vehicle : vehicles) {
delete vehicle;
}
}
};
int main() {
MaintenanceSystem garage;
// Implement user interaction based on the menu provided
return 0;
}
output:
