Challenge

Project 3

//The Program is as follows:-

#include <iostream>

#include <string>

#include <vector>

enum Type {

GAS,

DIESEL,

ELECTRIC

};

class Vehicle {

protected:

std::string make;

std::string model;

int year;

int odometer;

public:

Vehicle(std::string make_, std::string model_, int year_, int odometer_) : make(make_), model(model_), year(year_), odometer(odometer_) {}

std::string getMake() const { return make; }

std::string getModel() const { return model; }

int getYear() const { return year; }

int getOdometer() const { return odometer; }

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

virtual Type getType() = 0;

virtual void checkTireRotation() {

int distance = odometer % 50000;

if (distance >= 0) {

std::cout << "Tire rotation advised." << std::endl;

}

else {

std::cout << "Tires are good to go." << std::endl;

}

}

virtual void checkPower() {

int distance = odometer % 400;

if (distance == 0) {

std::cout << "Battery recharge advised." << std::endl;

}

else {

std::cout << "Your vehicle is good to go." << std::endl;

}

}

virtual void getCarInformation() const {

std::cout << "Make: " << make << ", Model: " << model << ", Year: " << year << ", Odometer: " << odometer << std::endl;

}

};

class GasCar : public Vehicle {

public:

GasCar(std::string make_, std::string model_, int year_, int odometer_) : Vehicle(make_, model_, year_, odometer_) {}

Type getType() { return Type::GAS; }

void getFuelType() {

std::cout << "Fuel Type: Gas" << std::endl;

}

};

class DieselCar : public Vehicle {

public:

DieselCar(std::string make_, std::string model_, int year_, int odometer_) : Vehicle(make_, model_, year_, odometer_) {}

Type getType() { return Type::DIESEL; }

void getFuelType() {

std::cout << "Fuel Type: Diesel" << std::endl;

}

};

class ElectricCar : public Vehicle {

public:

ElectricCar(std::string make_, std::string model_, int year_, int odometer_) : Vehicle(make_, model_, year_, odometer_) {}

Type getType() { return Type::ELECTRIC; }

void checkTireRotation() {

int distance = odometer % 40000;

if (distance >= 0) {

std::cout << "Tire rotation advised." << std::endl;

}

else {

std::cout << "Tires are good to go." << std::endl;

}

}

void checkChargerPower() {

int distance = odometer % 300;

if (distance == 0) {

std::cout << "Charger power recharge advised." << std::endl;

}

else {

std::cout << "Your vehicle is good to go." << std::endl;

}

}

void getFuelType() {

std::cout << "Fuel Type: Electric" << std::endl;

}

};

class FuelVehicle : public Vehicle {

public:

};

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.