Challenge

Project 3

#include <iostream>
#include <string>

using namespace std;

class Vehicle {
protected:
  string make;
  string model;
  int year;
  int odometer;

public:
  Vehicle(string make, string model, int year, int odometer) {
    this->make = make;
    this->model = model;
    this->year = year;
    this->odometer = odometer;
  }

  string getMake() { return make; }

  string getModel() { return model; }

  int getYear() { return year; }

  int getOdometer() { return odometer; }

  void setOdometer(int odometer) { this->odometer = odometer; }

  virtual void checkTireRotation() = 0;

  virtual void getCarInformation() = 0;
};

enum Type {
  GAS,
  DIESEL,
  ELECTRIC
};

class GasCar : public Vehicle {
public:
  GasCar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer) {}

  void checkTireRotation() override {
    if (odometer % 50000 == 0) {
      cout << "Tire rotation is required." << endl;
    } else {
      cout << "Tire rotation is not required." << endl;
    }
  }

  void getCarInformation() override {
    cout << "Make: " << make << endl;
    cout << "Model: " << model << endl;
    cout << "Year: " << year << endl;
    cout << "Odometer: " << odometer << endl;
    cout << "Fuel type: Gas" << endl;
  }
};

class DieselCar : public Vehicle {
public:
  DieselCar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer) {}

  void checkTireRotation() override {
    if (odometer % 50000 == 0) {
      cout << "Tire rotation is required." << endl;
    } else {
      cout << "Tire rotation is not required." << endl;
    }
  }

  void getCarInformation() override {
    cout << "Make: " << make << endl;
    cout << "Model: " << model << endl;
    cout << "Year: " << year << endl;
    cout << "Odometer: " << odometer << endl;
    cout << "Fuel type: Diesel" << endl;
  }
};

class ElectricCar : public Vehicle {
public:
  ElectricCar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer) {}

  void checkTireRotation() override {
    if (odometer % 400000 == 0) {
      cout << "Tire rotation is required." << endl;
    } else {
      cout << "Tire rotation is not required." << endl;
    }
  }

  void getCarInformation() override {
    cout << "Make: " << make << endl;
    cout << "Model: " << model << endl;
    cout << "Year: " << year << endl;
    cout << "Odometer: " << odometer << endl;
    cout << "Fuel type: Electric" << endl;
  }
};

int main() {
  Vehicle* inventory[10];
  int num_vehicles = 0;

  while (true) {
    cout << "Please select an option:" << 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. Tire Rotation." << endl;
    cout << "   6. Oil Change." << endl;
    cout << "   7. Recharge." << endl;
}
}
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.