Challenge

Project 3

PROJECT 3:

#include 
#include 

// Define an enumeration for vehicle types
enum Type
{
    GAS,
    DIESEL,
    ELECTRIC
};

// Create a base class for vehicles
class Vehicle
{
protected:
    std::string make;
    std::string model;
    int year;
    float odometer;

public:
    // Define a virtual destructor to allow proper cleanup of derived classes
    virtual ~Vehicle() {}

    // Constructor to initialize common vehicle attributes
    Vehicle(const std::string& make, const std::string& model, int year, float odometer)
        : make(make), model(model), year(year), odometer(odometer) {}

    // Define pure virtual functions to be implemented by derived classes
    virtual Type getType() = 0;
    virtual void performMaintenance() = 0;

    // Function to display vehicle information
    void getCarInformation()
    {
        std::cout << "Make: " << make xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed>(odometer) % rotationThreshold;

        if (remainder >= 0)
        {
            std::cout << "Tire rotation is advised." << std xss=removed>(odometer) >= oilChangeThreshold)
        {
            std::cout << "Oil change is advised." << std xss=removed>(odometer) >= rechargeThreshold)
        {
            std::cout << "Battery recharge is advised." << std> 100000)
            std::cout << "Please replace brake pads" << std> 200000)
            std::cout << "Please replace battery" << std> 100000)
            std::cout << "Please replace brake pads" << std> 200000)
            std::cout << "Please replace battery" << std> 100000)
            std::cout << "Please replace brake pads" << std> 200000)
            std::cout << "Please replace battery" << std> inventory;

    while (true)
    {
        std::cout << "Menu:" << std>> choice;

        switch (choice)
        {
            case 0:
                std::cout << "Exiting the program..." << std>getCarInformation();
                }
                break;
            case 2:
            {
                std::string make, model;
                int year;
                float 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;

                Vehicle* newVehicle = nullptr; // Use nullptr for modern C++
                switch (typeChoice)
                {
                    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 selection." << std>> index;

                if (index >= 0 && index < inventory>> newMake;

                    std::cout << "Enter new model: ";
                    std::cin >> newModel;

                    std::cout << "Enter new year: ";
                    std::cin >> newYear;

                    std::cout << "Enter new odometer reading: ";
                    std::cin >> newOdometer;

                    inventory[index]->updateVehicle(newMake, newModel, newYear, newOdometer);
                    std::cout << "Vehicle information updated." << std>> index;

                if (index >= 0 && index < inventory>> index;

                if (index >= 0 && index < inventory>performMaintenance();
                }
                else
                {
                    std::cout << "Invalid index." << std>

Screenshots of Output from Online GDB:

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.