Challenge

Project 3

/*

Author : Kishore N

Date: 17-01-25

*/

// program

#include <iostream>

#include <string>

#include <vector>

using namespace std;

// Enum for car types

enum Type {

GAS,

DIESEL,

ELECTRIC

};

class Vehicle {

protected:

string make;

string model;

int year;

int odometer;

public:

Vehicle(string mk, string mdl, int yr, int odo)

: make(mk), model(mdl), year(yr), odometer(odo) {}

// Getters

string getMake() { return make; }

string getModel() { return model; }

int getYear() { return year; }

int getOdometer() { return odometer; }

// Setters

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

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

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

void setOdometer(int odo) { odometer = odo; }

virtual Type getType() = 0;

void checkTireRotation() {

if (odometer >= 50000) {

cout << "Advise tire rotation.\n";

} else {

cout << "Tires are good to go.\n";

}

}

void getCarInformation() {

cout << "Make: " << make << ", Model: " << model

<< ", Year: " << year << ", Odometer: " << odometer << "\n";

}

};

class FuelVehicle : public Vehicle {

public:

FuelVehicle(string mk, string mdl, int yr, int odo)

: Vehicle(mk, mdl, yr, odo) {}

virtual void checkOil() {

if (odometer >= 10000) {

cout << "Advise oil change.\n";

} else {

cout << "Oil is good to go.\n";

}

}

virtual string getFuelType() = 0;

};

class GasCar : public FuelVehicle {

public:

GasCar(string mk, string mdl, int yr, int odo)

: FuelVehicle(mk, mdl, yr, odo) {}

Type getType() override {

return GAS;

}

string getFuelType() override {

return "Gas";

}

};

class DieselCar : public FuelVehicle {

public:

DieselCar(string mk, string mdl, int yr, int odo)

: FuelVehicle(mk, mdl, yr, odo) {}

Type getType() override {

return DIESEL;

}

string getFuelType() override {

return "Diesel";

}

};

class ElectricCar : public Vehicle {

public:

ElectricCar(string mk, string mdl, int yr, int odo)

: Vehicle(mk, mdl, yr, odo) {}

Type getType() override {

return ELECTRIC;

}

void checkChargerPower() {

if (odometer >= 400) {

cout << "Advise to recharge battery.\n";

} else {

cout << "Battery is good to go.\n";

}

}

string getFuelType() {

return "Electric";

}

};

int main() {

vector<Vehicle*> inventory;

while (true) {

int option;

cout << "Menu:\n";

cout << "0. Quit.\n";

cout << "1. List inventory.\n";

cout << "2. Add vehicle.\n";

cout << "3. Update vehicle.\n";

cout << "4. Remove vehicle.\n";

cout << "5. Tire Rotation.\n";

cout << "6. Oil Change.\n";

cout << "7. Recharge.\n";

cin >> option;

if (option == 0) break;

switch(option) {

case 1:

// List all vehicles

break;

case 2:

// Add new vehicle

break;

case 3:

// Update existing vehicle

break;

case 4:

// Remove vehicle

break;

case 5:

// Check tire rotation

break;

case 6:

// Check oil change

break;

case 7:

// Check recharge

break;

default:

cout << "Invalid option. Please try again.\n";

break;

}

}

// Free up memory

for(auto& vehicle : inventory) {

delete vehicle;

}

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.