Challenge

Project 3

#include

#include

using namespace std;

class Vehicle

{

    protected:

    string make;

    string model;

    int odo;

    int year;

public:

void setMake(string z) { make = z; }

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

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

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

string getMake() { return make; }

string getModel() { return model; }

int getOdo() { return odo; }

int getYear() { return year; }

void list()

{

cout<<"Make:"<

cout<<"Model:"<

cout<<"Odometer:"<

cout<<"Year:"<

}

void add()

{

string mak, mode;

int od, ye;

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

cin>>mak>>mode>>od>>ye;

setMake(mak);

setModel(mode);

setOdo(od);

setYear(ye);

}

void update()

{

int n;

cout<<"Give the choice:"<

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

cin>>n;

switch (n)

{

case 1:

{

string mak;

cout<<"Enter new make:";

cin>>mak;

setMake(mak);

}

break;

case 2:

{

string mode;

cout<<"Enter new model:";

cin>>mode;

setModel(mode);

}

break;

case 3:

{

int od;

cout<<"Enter new odometer reading:";

cin>>od;

setOdo(od);

}

break;

case 4:

{

int ye;

cout<<"Enter new year:";

cin>>ye;

setYear(ye);

}

break;

default:

cout<<"Invalid choice"<

}

}

void Remove()

{

make = "NULL";

model = "NULL";

odo = 0;

year = 0;

}

};

void checkTireRotation(int odometer)

{

if (odometer>= 50000)

{

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

}

else

{

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

}

}

void changeOil(int oilLevel)

{

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

if (oilLevel >= 1000)

{

cout<<"No oil change needed."<

}

else

{

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

}

}

void recharge(int KM)

{

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

if (KM >= 400)

{

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

}

else

{

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

}

}

int main()

{

Vehicle v[10];

int var = 0;

while (true)

{

cout <<"Enter the choice:"<

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

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

cout <<"2. Add vehicle."<

cout <<"3. Update vehicle."<

cout <<"4. Remove vehicle."<

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

cout <<"6. Change Oil."<

cout <<"7. Recharge."<

int ch;

cin>>ch;

switch (ch)

{

case 0:

exit(0);

break;

case 1:

for (int i = 0;i

v[i].list();

break;

case 2:

if (var< 10>

{

v[var].add();

var++;

}

break;

case 3:

{

int in;

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

cin>>in;

if (in>= 0 && in

v[in].update();

else

cout<<"Invalid index."<

}

break;

case 4:

{

int in;

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

cin >>in;

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

{

v[in].Remove();

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

}

else

cout<<"Invalid index."<

}

break;

case 5:

cout<<"Enter the odometer reading:";

int odometer;

cin >> odometer;

checkTireRotation(odometer);

break;

case 6:

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

int oilLevel;

cin >> oilLevel;

changeOil(oilLevel);

break;

case 7:

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

int KM;

cin >> KM;

recharge(KM);

break;

default:

cout<<"Invalid choice."<

}

}

return 0;

}

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.