Challenge

Project 3

Project - 3 : 

Build an c++ object-oriented library which can be used to track automobile maintenance. There can be different car types such as petrol, diesel, gas, electric etc., This library should be able to support at least three of the car types.  Maintenance tasks include activities like oil change or replace oil filter, replace air filter, replace fuel filter, tire rotations, infotainment system debug, replace spark plugs, replace the cabin or a/c filter, check the level and refill clutch fluid or brake fluid, examine belts, wipers, hoses, check the tire conditions, check the charging systems and battery. 
Every vehicle should have the following details:
1. Make
2. Model
3. Year
4. Odometer reading
The library interfaces or the API’s (Application Program Interface) should be capable of adding, updating, listing and removing the entries at runtime. 
Consider there are three classes such as
1. Vehicle 
a. This class includes protected members such as Make, Model, Year and Odometer. These members are initialized using the class constructor.
b. The functions include getter and setter functions of Make(), Model(), Year() and Odometer(). 
c. Maintenance activities that should be done are checkTireRotation(), getCarInformation()
d. Let the three fuel types be 
enum Type{
GAS,
DIESEL,
ELECTRIC
};
e. Let there be a pure virtual method to get the fuel type i.e., 
virtual Type getType() = 0;
2. GasCar
This is inherited from the vehicle class and has functions getType() and getFuelType()
3. DieselCar 
This class is also a subclass of vehicle and the functions include getFuelType() and getType()
4. ElectricCar
This is a subclass of Vehicle class and methods include 
a. checkTireRotation()- based on odometer reading, we decide whether the car needs to rotate tires or not.
b. checkChargerPower- based on odometer reading this advices to recharge power
c. getType() – to get the fuel type
5. FuelVehicle
This is an abstract class that inherits vehicle class. The methods in this class include checkOil() and pure virtual function getFuelType()

Maintenance activities that has to be done are as follows,
a. Check tire rotation: Let the tire cycle be 50,000 km. Calculate the distance the car has run and if this distance run is at 50k km, then advise rotation, else tires are good to go. Also, calculate the remainder of each 50k km, If remainder >=0 then advice to rotate tires.
b. Check Power: Let the distance be 400km, If the distance the car has run is at 400km, then advise battery to be recharged else your vehicle is good to go. 

Now that we have learnt about the classes to be created, we need to write our driver code i.e., main.cpp
1. In the main class, initialize the inventory and ask the user to select whether to add, update, list or delete the Vehicle list.
a. addVehicle() – to add new vehicle to inventory
b. ListVehicle()- to list the vehicles in the inventory
c. UpdateVehicle()- to update the vehicle in the inventory list
d. RemoveVehicle()- to remove the vehicle from the inventory list
e. Tire Rotation() – Check if tires need rotation
f. OilChange()- check if car requires oil change
g. Recharge() – check if vehicle needs recharge
2. Check for the user input, 0-1-2-3-4-5-6-7, Functions will be called based on the input provided by the user. If the input is wrong, ask again.
3. Menu should be as below,
 << "   0. Quit.\n"
 << "   1. List inventory.\n"
 << "   2. Add vehicle.\n"
 << "   3. Update vehicle\n"
 << "   4. Remove vehicle\n"
 << "   5. Tire Rotation\n"
 << "   6. Oil Change\n"
 << "   7. Recharge\n"
4. Retrieve the user input on the vehicle’s make, model, year, type and odometer.
a. getNewMake() – If input is blank, request again
b. getNewModel() – If input is blank, request again
c. getYear() – If input doesn’t have 4 digits, request again
d. getNewOdometer()- Input should be only numericals
e. getNewType() – Input should be within 0-2, else request again
5. Retrieve the selected car from the user input
a. selectCar() – Input should be within the size of vehicle list, else request again
b. getNewOdometerReading() – New odometer reading is used to calculate the oil change, tire rotation, power recharge etc.

Ans:

#include             /* These lines include the necessary header files for input/output stream operations in C++ */

#include                /* These lines include the necessary header files for string manipulation in C++ */

#include               /* The vector header provides the C++ Standard Library container class std vector, which is a dynamic array-like data structure that can grow or shrink in size. It is part of the C++ Standard Template Library and is one of the most commonly used containers in C++ */

#include                  /* The limits header provides access to various limits and properties of fundamental data types in C++. It is part of the C++ Standard Library and is useful when you need to know the minimum and maximum values that can be represented by data types, as well as other characteristics like the number of digits in a floating-point number or the precision of a double */

using namespace std;          /* This line allows us to use standard C++ library elements without explicitly specifying the std namespace */

enum class Type                 /* The enum class representing different types of vehicles, it ensures that the enumerators are scoped within the Type enumeration, preventing any implicit conversions to integer values. To access an enumerator value, We need to use the scope resolution operator Type:: */


{
    GAS,
    DIESEL,
    ELECTRIC
};

class Vehicle                                     /* This line starts the declaration of the constructor Vehicle class with several member variables (protected) and member functions. The Vehicle class is an abstract class with pure virtual functions */


{


    protected:                            /* In C++, protected is an access specifier used within classes to control the visibility of class members to derived classes. It can be accessed by the derived classes, but it remains inaccessible outside the class hierarchy */       

 
    string make;
    string model;
    int year;
    int odometer;

    public:                                    /* This keyword specifies that the members following it are accessible outside the class */


    Vehicle(const string& make, const string& model, int year, int odometer) : make(make), model(model), year(year), odometer(odometer)                    /* constructor definition for the Vehicle class. They are used to initialize the data members of the class with provided values or default values */


    {}

    string getMake() const                          /* member function definition for the getMake() method within the Vehicle class. This method returns the value of the make data member of the class */


    {
        return make;
    }


    string getModel() const                      /* member function definition for the getModel() method within the Vehicle class. This method returns the value of the make data member of the class */


    {
        return model;
    }


    int getYear() const                                    /* member function definition for the getYear() method within the Vehicle class. This method returns the value of the year data member of the class */


    {
        return year;
    }


    int getOdometer() const                /* member function definition for the getOdometer() method within the Vehicle class. This method returns the value of the year data member of the class */


    {
        return odometer;
    }

    void setMake(const string& make)                     /* member function definition for the setMake() method within the Vehicle class. This method is a setter function used to set the value of the make data member of the class to a new value provided as an argument */


    {


        this->make = make;                     /* In C++, this is a pointer that holds the address of the parameter make to the data member make current object */


    }


    void setModel(const string& model)                          /* member function definition for the setModel() method within the Vehicle class. This method is a setter function used to set the value of the make data member of the class to a new value provided as an argument */


    {


        this->model = model;                           /* In C++, this is a pointer that holds the address of the parameter model to the data member model current object */


    }


    void setYear(int year)                                             /* member function definition for the setYear() method within the Vehicle class. This method is a setter function used to set the value of the make data member of the class to a new value provided as an argument */


    {


        this->year = year;                           /* In C++, this is a pointer that holds the address of the parameter year to the data member year current object */


    }


    void setOdometer(int odometer)                          /* member function definition for the setOdometer() method within the Vehicle class. This method is a setter function used to set the value of the make data member of the class to a new value provided as an argument */


    {


        this->odometer = odometer;                            /* In C++, this is a pointer that holds the address of the parameter odometer to the data member odometer current object */


    }

    virtual Type getType() const = 0;                   /* pure virtual function declaration within the Vehicle class */


    virtual void checkTireRotation() const = 0;              /* pure virtual function declaration within the Vehicle class */

virtual void checkDieselChange() const = 0;                  /* pure virtual function declaration within the Vehicle class */


    void getCarInformation() const                              /* member function definition for the getCarInformation() method within the Vehicle class. This method is responsible for displaying information about the vehicle, such as its make, model, year, and odometer reading */

    {


        cout << "Make: " << make>                  << ", Odometer: " << odometer>


    }

    virtual ~Vehicle()                            /* virtual destructor declaration within the Vehicle class. A destructor is a special member function that is automatically called when an object of the class is destroyed  */


    {}
};

class GasCar : public Vehicle                          /* class definition for the constructor GasCar sub-class, which is derived from the Vehicle class. The GasCar inherits all the member variables and member functions from the Vehicle class and can also define its own specific member variables and member functions */


{


    public:                                   /* This keyword specifies that the members following it are accessible outside the class */


    GasCar(const string& make, const string& model, int year, int odometer) : Vehicle(make, model, year, odometer)                                     /* constructor definition for the GasCar class. They are used to initialize the data members of the class with provided values or default values */


    {}

    Type getType() const override                          /* member function definition for the getType() method within the GasCar class. This method is an override of the virtual function getType() declared in the base class Vehicle */


    {
        return Type::GAS;
    }

    void checkTireRotation() const override                         /* member function definition for the checkTireRotation() method within the GasCar class. This method is an override of the virtual function checkTireRotation() declared in the base class Vehicle */


    {
        int tireCycle = 50000;                                    /* 50,000 km tire cycle */
        int distanceRun = getOdometer();
        int remainder = tireCycle - (distanceRun % tireCycle);

        if (remainder <= 0)
        {
            cout << "Tire rotation advised. " << endl>        }
        else
        {
            cout << "Tires are good to go. " << endl>        }
    }

    void checkDieselChange() const override                      /* member function definition for the checkDieselChange() method within the GasCar class. This method is an override of the virtual function checkDieselChange() declared in the base class Vehicle */


    {
        int dieselChangeCycle = 100;                    /* 100 km diesel cycle */
        int distanceRun = getOdometer();
        int remainder = dieselChangeCycle - (distanceRun % dieselChangeCycle);

        if (remainder <= 0)
        {
            cout << "Diesel change advised. " << endl>        }
        else
        {
            cout << "Diesel is still good. " << endl>        }
    }


    void getFuelType() const                            /* member function definition for the getFuelType() method within the GasCar class */

               
    {
        cout << "Fuel Type: Gas " << endl>    }
};

class DieselCar : public Vehicle                     /* class definition for the constructor DieselCar sub-class, which is derived from the Vehicle class. The DieselCar inherits all the member variables and member functions from the Vehicle class and can also define its own specific member variables and member functions */


{


    public:                           /* This keyword specifies that the members following it are accessible outside the class */


    DieselCar(const string& make, const string& model, int year, int odometer) : Vehicle(make, model, year, odometer)                       /* constructor definition for the DieselCar class. They are used to initialize the data members of the class with provided values or default values */


    {}

    Type getType() const override                          /* member function definition for the getType() method within the DieselCar class. This method is an override of the virtual function getType() declared in the base class Vehicle */


    {
        return Type::DIESEL;
    }

    void checkTireRotation() const override                     /* member function definition for the checkTireRotation() method within the DieselCar class. This method is an override of the virtual function checkTireRotation() declared in the base class Vehicle */


    {
        int tireCycle = 50000;                              /* 50,000 km tire cycle */
        int distanceRun = getOdometer();
        int remainder = tireCycle - (distanceRun % tireCycle);

        if (remainder <= 0)
        {
            cout << "Tire rotation advised. " << endl>        }
        else
        {
            cout << "Tires are good to go. " << endl>        }
    }

    void checkDieselChange() const override                   /* member function definition for the checkDieselChange() method within the DieselCar class. This method is an override of the virtual function checkDieselChange() declared in the base class Vehicle */


    {
        int dieselChangeCycle = 150;                         /* 150 km diesel cycle */
        int distanceRun = getOdometer();
        int remainder = dieselChangeCycle - (distanceRun % dieselChangeCycle);

        if (remainder <= 0)
        {
            cout << "Diesel change advised. " << endl>        }
        else
        {
            cout << "Diesel is still good. " << endl>        }
    }

    void getFuelType() const                               /* member function definition for the getFuelType() method within the DieselCar class */


    {
        cout << "Fuel Type: Diesel " << endl>    }
};

class ElectricCar : public Vehicle                /* class definition for the constructor ElectricCar sub-class, which is derived from the Vehicle class. The ElectricCar inherits all the member variables and member functions from the Vehicle class and can also define its own specific member variables and member functions */


{


    public:                                  /* This keyword specifies that the members following it are accessible outside the class */


    ElectricCar(const string& make, const string& model, int year, int odometer) : Vehicle(make, model, year, odometer)                             /* constructor definition for the ElectricCar class. They are used to initialize the data members of the class with provided values or default values */


    {}

    Type getType() const override                         /* member function definition for the getType() method within the ElectricCar class. This method is an override of the virtual function getType() declared in the base class Vehicle */


    {
        return Type::ELECTRIC;
    }

    void checkTireRotation() const override                     /* member function definition for the checkTireRotation() method within the ElectricCar class. This method is an override of the virtual function checkTireRotation() declared in the base class Vehicle */


    {
        int tireCycle = 50000;                                     /* 50,000 km tire cycle */
        int distanceRun = getOdometer();
        int remainder = tireCycle - (distanceRun % tireCycle);

        if (remainder <= 0)
        {
            cout << "Tire rotation advised. " << endl>        }
        else
        {
            cout << "Tires are good to go. " << endl>        }
    }

    void checkDieselChange() const override                     /* member function definition for the checkDieselChange() method within the ElectricCar class. This method is an override of the virtual function checkDieselChange() declared in the base class Vehicle */


    {
        cout << "Electric vehicles do not require diesel changes. " << endl>    }

    void checkChargerPower() const                                 /* member function definition for the checkChargerPower() method within the ElectricCar class. This method is an override of the virtual function checkChargerPower() declared in the base class Vehicle */


    {
        int rechargeDistance = 500;                                /* 500 km recharge distance */

        if (getOdometer() >= rechargeDistance)
        {
            cout << "Recharge your vehicle's battery. " << endl>        }
        else
        {
            cout << "Your vehicle is good to go. " << endl>        }
    }
};

class MaintenanceTracker                                  /* The constructor MaintenanceTracker class manages a vector of pointers to Vehicle objects. It provides methods for adding, listing, updating, and removing vehicles */


{


    private:                                   /* This keyword specifies that the members following it are only accessible within the class itself */


    vector vehicles;                    / declaration of a member variable named vehicles of type vector within the scope of a class */

    public:                                   /* This keyword specifies that the members following it are accessible outside the class */


    const vector& getVehicles() const               / constant member function of the MaintenanceTracker class */


    {
        return vehicles;
    }


    ~MaintenanceTracker()                          /*  The destructor of the MaintenanceTracker class, it is a special member function that is automatically called when an object of the class is destroyed  */


    {
        for (Vehicle* vehicle : vehicles)
        {
            delete vehicle;
        }
    }

    void addVehicle(Vehicle vehicle)                        /* member function of the MaintenanceTracker class */


    {


        vehicles.push_back(vehicle);                         /* using to add a pointer to a Vehicle object to the end of the vehicles vector */


    }

    void listVehicles() const                                    /* member function of the MaintenanceTracker class */


    {
        cout << "Vehicle Inventory: " << endl>        for (size_t i = 0; i < vehicles>        {
            cout << i>            vehicles[i]->getCarInformation();
        }
    }

    void updateVehicle(int index)                  /* member function of the MaintenanceTracker class */


    {


        if (index >= 0 && static_cast(index) < vehicles>


        {
            cout << "Enter updated odometer reading for the vehicle: " << endl>            int newOdometer;                                                     /* print the statement */

            cin >> newOdometer;                                               /* input given */

            vehicles[static_cast(index)]->setOdometer(newOdometer);            /* using to update the odometer reading of a specific vehicle in the vehicles vector with a new value given */


        }
        else
        {
            cout << "Invalid index. " << endl>        }
    }

    void removeVehicle(int index)                  /* member function of the MaintenanceTracker class */


    {


        if (index >= 0 && static_cast(index) < vehicles>


        {


            delete vehicles[static_cast(index)];                      /* using to deallocate memory for a specific vehicle object in the vehicles vector */


            vehicles.erase(vehicles.begin() + static_cast(index));             /* using to remove a specific vehicle pointer from the vehicles vector  */


        }
        else
        {
            cout << "Invalid index. " << endl>        }
    }
};

int main()                                                    /* to print the statements */


{

/*

Algorithm used : 

1. Define the Vehicle base class and its derived classes to represent different types of vehicles with specific functionalities.

2. Create a MaintenanceTracker class to manage the inventory of vehicles using a vector of pointers to the Vehicle base class.

3. Provide a menu-driven interface in the main function to interact with the MaintenanceTracker and perform various operations on the vehicles.

4. Allow to add, update, remove, and view information about vehicles.

5. Use dynamic memory allocation to create and manage vehicle objects in the MaintenanceTracker class.

6. Utilize polymorphism through virtual functions to call specific functions based on the type of vehicle, ensuring correct behavior for each vehicle type.

7. The program will return 0 value after executing the main function.

*/


    MaintenanceTracker maintenanceTracker;                       /* declaring an object named maintenanceTracker of the class MaintenanceTracker */


    int choice;                              /* declaring variables to interact and store information */
    string make;
    string model;
    int year;
    int odometer;

    do                                            /* implementing a loop that displays the main menu and process until the we chooses to exit (choice = 0) */


    {
        cout << "Select an option: " << endl>                  << "0. Quit. " << endl>                  << "1. List inventory. " << endl>                  << "2. Add vehicle. " << endl>                  << "3. Update vehicle. " << endl>                  << "4. Remove vehicle. " << endl>                  << "5. Tire Rotation. " << endl>                  << "6. Diesel Change. " << endl>                  << "7. Recharge. " << endl>                  << "Choice: " << endl>


        cin >> choice;                                                /* inputs given */

        switch (choice)                                       /* This switch statement is a control flow construct in C++ that allows us to select one of many code blocks to be executed based on the value of a single expression. hear we are using the choice variable to determine which block of code to execute */


        {
            case 0:
                cout << "Exit the program!... " << endl>


                break;                               /*  terminate the execution of the switch block */


            case 1:
                maintenanceTracker.listVehicles();                             /* This line is a calling the member function listVehicles() of the MaintenanceTracker class. This function is used to display the information of all the vehicles stored in the vehicles vector within the MaintenanceTracker object */


                break;                                     /*  terminate the execution of the switch block */


            case 2:
                cout << "Enter make: " << endl>

                cin.ignore();                                                    /* using to clear the input buffer of the standard input stream  */

                getline(cin, make);                                                       /* inputs given */

                cout << "Enter model: " << endl>

                getline(cin, model);                                                        /* inputs given */

                cout << "Enter year: " << endl>

                cin >> year;                                                                    /* inputs given */

                cout << "Enter odometer reading: " << endl>

                cin >> odometer;                                                            /* inputs given */

                int fuelTypeChoice;                       /* declaring fuelTypeChoice variable to interact and store information */


                do                                            /* implementing a loop that displays fuel type */

                {
                    cout << "Select fuel type: " << endl>                              << "0. Gas " << endl>                              << "1. Diesel " << endl>                              << "2. Electric " << endl>                              << "Choice: " << endl>

                    cin >> fuelTypeChoice;                                         /* inputs given */

                }


                while (fuelTypeChoice < 0> 2);                    /* loop construct that continues to prompt  for the input given until a valid value for fuelTypeChoice is provided */

                Vehicle newVehicle;                                       /  declaring a pointer variable named newVehicle to store the memory address of dynamically allocated objects  */


                switch (static_cast(fuelTypeChoice))                /* using the static_cast operator to convert the fuelTypeChoice variable from an integer type to an enumeration type Type. This allows the program to perform a switch based on the enumerated values instead of using the raw integers */


                {


                    case Type::GAS:                                    /*  using in a switch statement to handle a specific value of the enumeration class Type */


                        newVehicle = new GasCar(make, model, year, odometer);                                /* dynamically allocates memory to create a new object of the class GasCar and assigns its address to the pointer variable newVehicle */


                        break;                            /*  terminate the execution of the switch block */


                    case Type::DIESEL:                              /*  using in a switch statement to handle a specific value of the enumeration class Type */


                        newVehicle = new DieselCar(make, model, year, odometer);                           /* dynamically allocates memory to create a new object of the class DieselCar and assigns its address to the pointer variable newVehicle */


                        break;                          /*  terminate the execution of the switch block */


                    case Type::ELECTRIC:                            /*  using in a switch statement to handle a specific value of the enumeration class Type */


                        newVehicle = new ElectricCar(make, model, year, odometer);                          /* dynamically allocates memory to create a new object of the class ElectricCar and assigns its address to the pointer variable newVehicle */


                        break;                   /*  terminate the execution of the switch block */


                    default:
                        cout << "Invalid fuel type selection. " << endl>                        continue;                                  /* This statement allows the loop to proceed with the next iteration without executing the remaining statements inside the loop for the current iteration */


                }

                maintenanceTracker.addVehicle(newVehicle);                             /* using to add a dynamically allocated Vehicle object to the MaintenanceTracker container */


                cout << "Vehicle added to the inventory. " << endl>


                break;                            /*  terminate the execution of the switch block */


            case 3:
            {
                maintenanceTracker.listVehicles();                                /* This line is a calling the member function listVehicles() of the MaintenanceTracker class. This function is used to display the information of all the vehicles stored in the vehicles vector within the MaintenanceTracker object */


                cout << "Select the vehicle to update: " << endl>


                int index;                                                       /* using to store the data */


                cin >> index;                                                          /* inputs given */


                maintenanceTracker.updateVehicle(index - 1);           /* This member function is used to update the odometer reading of a specific vehicle in the vehicles vector based as per input given */


                break;                              /*  terminate the execution of the switch block */


            }


            case 4:
            {
                maintenanceTracker.listVehicles();                         /* This line is a calling the member function listVehicles() of the MaintenanceTracker class. This function is used to display the information of all the vehicles stored in the vehicles vector within the MaintenanceTracker object */


                cout << "Select the vehicle to remove: " << endl>

                int index;                                                     /* using to store the data */

                cin >> index;                                                    /* inputs given */


                maintenanceTracker.removeVehicle(index - 1);                     /* This member function is used to remove a specific vehicle from the vehicles vector based on the input given */

                cout << "Vehicle removed from the inventory. " << endl>


                break;                                   /*  terminate the execution of the switch block */


            }


            case 5:
            {
                maintenanceTracker.listVehicles();                      /* This line is a calling the member function listVehicles() of the MaintenanceTracker class. This function is used to display the information of all the vehicles stored in the vehicles vector within the MaintenanceTracker object */


                cout << "Select the vehicle to check tire rotation: " << endl>


                int index;                                                    /* using to store the data */


                cin >> index;                                             /* inputs given */


                const vector& vehicleList = maintenanceTracker.getVehicles();                  /* creating a constant reference to the vehicles vector within the MaintenanceTracker object named maintenanceTracker */


                if (index >= 1 && static_cast(index) <= vehicleList.size())          /* This  condition checks if the entered index is within a valid range to access an element in the vehicleList vector */


                {


                    vehicleList[static_cast(index) - 1]->checkTireRotation();           /* using to invoke the selected vehicle in the vehicleList vector */


                }
                else
                {
                    cout << "Invalid vehicle selection. " << endl>                }
                break;                                    /*  terminate the execution of the switch block */


            }


            case 6:
            {
                maintenanceTracker.listVehicles();                             /* This line is a calling the member function listVehicles() of the MaintenanceTracker class. This function is used to display the information of all the vehicles stored in the vehicles vector within the MaintenanceTracker object */


                cout << "Select the vehicle to check diesel change: " << endl>


                int index;                                                     /* using to store the data */


                cin >> index;                                           /* inputs given */


                const vector& vehicleList = maintenanceTracker.getVehicles();                /* creating a constant reference to the vehicles vector within the MaintenanceTracker object named maintenanceTracker */

                if (index >= 1 && static_cast(index) <= vehicleList.size())        /* This  condition checks if the entered index is within a valid range to access an element in the vehicleList vector */


                {


                    vehicleList[static_cast(index) - 1]->checkDieselChange();                                    /* using to invoke the selected vehicle in the vehicleList vector */


                }
                else
                {

                    cout << "Invalid vehicle selection. " << endl>

                }

                break;                         /*  terminate the execution of the switch block */


            }


            case 7:
            {
                maintenanceTracker.listVehicles();                             /* This line is a calling the member function listVehicles() of the MaintenanceTracker class. This function is used to display the information of all the vehicles stored in the vehicles vector within the MaintenanceTracker object */


                cout << "Select the electric vehicle to check recharge: " << endl>


                int index;                                               /* using to store the data */


                cin >> index;                                      /* inputs given */

                const vector& vehicleList = maintenanceTracker.getVehicles();              /* creating a constant reference to the vehicles vector within the MaintenanceTracker object named maintenanceTracker */


                if (index >= 1 && static_cast(index) <= vehicleList.size())              /* This  condition checks if the entered index is within a valid range to access an element in the vehicleList vector */


                {


                    ElectricCar* electricCar = dynamic_cast(vehicleList[static_cast(index) - 1]);                                 /* using dynamic_cast to attempt to convert a pointer to the base class Vehicle to a pointer to the derived class ElectricCar */


                    if (electricCar)                               /* This  condition checks if the entered index is within a valid range to access an element in the vehicleList vector */


                    {


                        electricCar->checkChargerPower();                                     /* using to invoke specifically on an object of the ElectricCar class */


                    }
                    else
                    {


                        cout << "Selected vehicle is not an electric vehicle. " << endl>


                    }
                }
                else
                {
                    cout << "Invalid vehicle selection. " << endl>

                }
                break;                            /*  terminate the execution of the switch block */

            }


            default:
                cout << "Invalid choice. Please try again. " << endl>


                break;                          /*  terminate the execution of the switch block */


        }

    } while (choice != 0);                  /* This creates a loop that repeatedly executes a block of code as long as the value of the variable choice is not equal to 0 */

    return 0;                                      /* After executing this main function this function will return 0 value */


}

input used :

1. Enter choice : 2         ( Added 3 vehicles make, model, year and odometer reading ).

2. Enter choice : 1         ( check the list of 3 vehicles ).

3. Enter choice : [3,1], [3,2], [3,3]   ( update odometer readings of 3 vehicles if needed ).

4. Enter choice : 1         ( check the updated list of vehicles ).

5. Enter choice : [5,1], [5,2], [5,3]    ( check the tire rotation for the 3 vehicles ).

6. Enter choice : [6,1], [6,2], [6,3]    ( check the diesel for the diesel and gas vehicles only ).

7. Enter choice : [7,3]      ( check the battery recharge for the electric vehicles only ).

8. Enter choice : [3,3]         ( update odometer reading of electric vehicle if needed ).

9. Enter choice : 1         ( check the updated list of 3 vehicles ).

10. Enter choice : [7,3]     ( check the battery recharge for the electric vehicles only ).

11. Enter choice : 0     ( exit the program ).

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.