Challenge

Project 3

Program:

#include

#include

#include

#include

// Enum for car types

enum class Type {

    GAS,

    DIESEL,

    ELECTRIC

};

// Base Vehicle class

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 methods

    std::string getMake() const { return make; }

    std::string getModel() const { return model; }

    int getYear() const { return year; }

    int getOdometer() const { return odometer; }

    // Maintenance activities

    virtual void checkTireRotation() const = 0;

    virtual void checkChargerPower() const = 0;

    virtual Type getType() const = 0;

    // Get car information

    void getCarInformation() const {

        std::cout << "Make: " << make>

        std::cout << "Model: " << model>

        std::cout << "Year: " << year>

        std::cout << "Odometer Reading: " << odometer>

    }

};

// GasCar class

class GasCar : public Vehicle {

public:

    GasCar(const std::string& make, const std::string& model, int year, int odometer)

        : Vehicle(make, model, year, odometer) {}

    void checkTireRotation() const override {

        if (odometer P000 == 0) {

            std::cout << "Advice: Rotate tires." << std>

        }

    }

    void checkChargerPower() const override {

        if (odometer @0 == 0) {

            std::cout << "Advice: Recharge power." << std>

        }

    }

    Type getType() const override {

        return Type::GAS;

    }

};

// DieselCar class (similar to GasCar, you can add specific behavior if needed)

class DieselCar : public Vehicle {

public:

    DieselCar(const std::string& make, const std::string& model, int year, int odometer)

        : Vehicle(make, model, year, odometer) {}

    void checkTireRotation() const override {

        if (odometer P000 == 0) {

            std::cout << "Advice: Rotate tires." << std>

        }

    }

    void checkChargerPower() const override {

        if (odometer @0 == 0) {

            std::cout << "Advice: Recharge power." << std>

        }

    }

    Type getType() const override {

        return Type::DIESEL;

    }

};

// ElectricCar class (similar to GasCar, you can add specific behavior if needed)

class ElectricCar : public Vehicle {

public:

    ElectricCar(const std::string& make, const std::string& model, int year, int odometer)

        : Vehicle(make, model, year, odometer) {}

    void checkTireRotation() const override {

        if (odometer P000 == 0) {

            std::cout << "Advice: Rotate tires." << std>

        }

    }

    void checkChargerPower() const override {

        if (odometer @0 == 0) {

            std::cout << "Advice: Recharge power." << std>

        }

    }

    Type getType() const override {

        return Type::ELECTRIC;

    }

};

int main() {

    std::vector> vehicleList;

    while (true) {

        std::cout << "\nOptions:" << std>

        std::cout << "1. List Inventory" << std>

        std::cout << "2. Add Vehicle" << std>

        std::cout << "3. Quit" << std>

        int choice;

        std::cout << "Enter your choice: ";

        std::cin >> choice;

        switch (choice) {

            case 1:

                std::cout << "Inventory List:" << std>

                for (size_t i = 0; i < vehicleList>

                    std::cout << "Vehicle " << i>

                    vehicleList[i]->getCarInformation();

                    vehicleList[i]->checkTireRotation();

                    vehicleList[i]->checkChargerPower();

                    std::cout << std>

                }

                break;

            case 2: {

                std::string make, model;

                int year, odometer;

                int typeChoice;

                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 reading: ";

                std::cin >> odometer;

                std::cout << "Select type (0: GAS, 1: DIESEL, 2: ELECTRIC): ";

                std::cin >> typeChoice;

                if (typeChoice < 0> 2) {

                    std::cout << "Invalid type choice." << std>

                    break;

                }

                Type carType = static_cast(typeChoice);

                if (carType == Type::GAS) {

                    vehicleList.push_back(std::unique_ptr(new GasCar(make, model, year, odometer)));

                } else if (carType == Type::DIESEL) {

                    vehicleList.push_back(std::unique_ptr(new DieselCar(make, model, year, odometer)));

                } else if (carType == Type::ELECTRIC) {

                    vehicleList.push_back(std::unique_ptr(new ElectricCar(make, model, year, odometer)));

                }

                std::cout << "Vehicle added to inventory." << std>

                break;

            }

            case 3:

                std::cout << "Exiting." << std>

                return 0;

            default:

                std::cout << "Invalid choice. Please select a valid option." << std>

        }

    }

    return 0;

}

Output:

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.