Challenge

Project 3

#include //input output stream

#include // we used string here so string header file

using namespace std;

class Vehicle//class name vehicle

{

protected:

    string make;

    string model;

    int odo;

    int year;

public:

    void setMake(string z) { make = z; }//functions of setmake,setmodel,setodo,setyear

    void setModel(string z) { model = z; }

    void setOdo(int z) { odo = z; }

    void setYear(int z) { year = z; }

    string getMake()  { return make; }//getmake string and return make

    string getModel()  { return model; }//getmodel and return model

    int getOdo() { return odo; }//getting odometer

    int getYear()  { return year; }//getting year

    void list() //func list

    {

        cout << "Make: " << getMake>

        cout << "Model: " << getModel>

        cout << "Odometer: " << getOdo>

        cout << "Year: " << getYear>

    }

    void add()  //func. add

    {

        string mak, mode;

        int od, ye;

        cout << "Enter the make, model, odometer, year" << endl>

        cin >> mak >> mode >> od >> ye;//taking readings from console

        setMake(mak);//calling setmake,setmodel,setodo,setyear

        setModel(mode);

        setOdo(od);

        setYear(ye);

    }

    void update()//function name update

    {

        int n;

        cout << "Give the choice" << endl>

        cout << "1. Make 2. Model 3. Odometer 4. Year" << endl>

        cin >> n;//reading the choice from the console

        switch (n)//switch stmnt

        {

        case 1://switching to the particular stmnt and making update on it..

        {

            string mak;

            cout << "Enter new make: ";

            cin >> mak;

            setMake(mak);//calling setMake

        }

        break;

        case 2:

        {

            string mode;

            cout << "Enter new model: ";

            cin >> mode;

            setModel(mode);//calling set mode

        }

        break;

        case 3:

        {

            int od;

            cout << "Enter new odometer reading: ";

            cin >> od;

            setOdo(od);//calling setOdo

        }

        break;

        case 4:

        {

            int ye;

            cout << "Enter new year: ";

            cin >> ye;

            setYear(ye);//calling setYear

        }

        break;

        default://if the person enters default choice then it will print the below stmnt

            cout << "Invalid choice" << endl>

        }

    }

    void Remove()//func remove

    {

        make = "NULL";//for remove all the operations become null and zero

        model = "NULL";

        odo = 0;

        year = 0;

    }

};//end of class Vehicle

void checkTireRotation(int odometer)//function of check tire rotation respected to odometer

{

    if (odometer >= 50000)//if odometer is greater or equal to 50000 print the below stmnt

    {

        cout << "Time to rotate tires on your gas car." << endl>

    }

    else//if odometer is lesser than 50000 it will print below stmnt

    {

        cout << "Tires are good to go." << endl>

    }

}

void changeOil(int oilLevel)//function of change oil

{

    cout << "Checking for oil change..." << endl>

    if (oilLevel >= 1000)//if oil level is greater or equal to 1000 then print below stmnt

    {

        cout << "No oil change needed." << endl>

    }

    else//if it is lesse than 1000 print the below stmnt

    {

        cout << "Car needs an oil change." << endl>

    }

}

void recharge(int KM)//function recharge

{

    cout << "Checking for battery charging..." << endl>

    if (KM >= 400)//if km is greater than 400 then it should be recharged

    {

        cout << "Battery needs to be recharged." << endl>

    }

    else

    {

        cout << "Car is good to go." << endl>

    }

}

int main()//main function

{

    Vehicle v[10];

    int var = 0;

    while (true)

    {

        cout << "Enter the choice:" << endl>

        cout << "0. Quit." << endl>

        cout << "1. List inventory." << endl>

        cout << "2. Add vehicle." << endl>

        cout << "3. Update vehicle." << endl>

        cout << "4. Remove vehicle." << endl>

        cout << "5. Check Tire Rotation." << endl>

        cout << "6. Change Oil." << endl>

        cout << "7. Recharge." << endl>

        int ch;

        cin >> ch;//reading the choice from the console

        switch (ch)//switch the respected choice simuktaneously making respected operations on it

        {

        case 0:

            exit(0);

            break;

        case 1:

            for (int i = 0; i < var>

                v[i].list();//calling list func..

            break;

        case 2:

            if (var < 10>

            {

                v[var].add();//calling add function

                var++;

            }

            break;

        case 3:

        {

            int in;

            cout << "Enter the index to update: ";

            cin >> in;

            if (in >= 0 && in < var>

                v[in].update();//calling update func..

            else

                cout << "Invalid index." << endl>

        }

        break;

        case 4:

        {

            int in;

            cout << "Enter the index to remove: ";

            cin >> in;

            if (in >= 0 && in < var>

            {

                v[in].Remove();//calling remove func.

                cout << "Vehicle removed." << endl>

            }

            else

                cout << "Invalid index." << endl>

        }

        break;

        case 5:

            cout << "Enter the odometer reading: ";

            int odometer;

            cin >> odometer;

            checkTireRotation(odometer);//calling odometer function with respectedodometer reading entered in the console

            break;

        case 6:

            cout << "Enter the oil level (in ml): ";

            int oilLevel;

            cin >> oilLevel;

            changeOil(oilLevel);//calling changeOil function with respected oil level reading entered in the console

            break;

        case 7:

            cout << "Enter the number of kilometers: ";

            int KM;

            cin >> KM;

            recharge(KM);//calling recharge function with respected kilometers reading entered in the console

            break;

        default://if the choice entered from the person is default then print below stmnt

            cout << "Invalid choice." << endl>

        }

    }

    return 0;//return stmnt

}

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.