Challenge

Project 3

#include <iostream>

#include<string>

using namespace std;

class Vehicle{

protected:

string Make;

string Model;

int Year;

int Odometer_Reading;

public:

//initialize constructor

Vehicle(string Make, string Model, int Year, int Odometer_Reading){

this->Make=Make;

this->Model=Model;

this->Year=Year;

this->Odometer_Reading=Odometer_Reading;

}

void quit(){

cout<<"quit"<<endl;

}

void addVehicle(){

cout<<"addvehicle"<<endl;

cout<<"New make:"<<Make<<endl;

cout<<"New model:"<<Model<<endl;

cout<<"Manufacturing Year:"<<Year<<endl;

cout<<"Odometer Reading:"<<Odometer_Reading<<endl;

}

void ListVehicle(){

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

cout<<"List make:"<<Make<<endl;

cout<<"List model:"<<Model<<endl;

cout<<"List Manufacturing Year:"<<Year<<endl;

cout<<"List Odometer Reading:"<<Odometer_Reading<<endl;

}

void UpdateVehicle(){

cout<<"Update the vehicle"<<endl;

cout<<"Update make:"<<Make<<endl;

cout<<"Update model:"<<Model<<endl;

cout<<"Update Manufacturing Year:"<<Year<<endl;

cout<<"Update Odometer Reading:"<<Odometer_Reading<<endl;

}

void RemoveVehicle(){

cout<<"Remove the vehicle"<<endl;

cout<<"Remove make:"<<Make<<endl;

cout<<"Remove model:"<<Model<<endl;

cout<<"Remove Manufacturing Year:"<<Year<<endl;

cout<<"Remove Odometer Reading:"<<Odometer_Reading<<endl;

}

};

class GasCar: public Vehicle{

public:

GasCar( string Make,string Model, int Year, int Odometer_Reading)

:Vehicle(Make, Model, Year, Odometer_Reading){

}

void getFuelType(){

cout<<"Gas"<<endl;

}

};

class DieselCar : public Vehicle{

public:

DieselCar( string Make,string Model, int Year, int Odometer_Reading):

Vehicle(Make, Model, Year, Odometer_Reading){

}

void getFuelType() { cout<<"Diesel"<<endl;}

};

class ElectricCar: public Vehicle{

public:

ElectricCar( string Make,string Model, int Year, int Odometer_Reading):

Vehicle(Make, Model, Year, Odometer_Reading){}

void getFuelType() {

cout<<"Electricity"<<endl;

}

};

int main()

{

ElectricCar electriccar("Toyota","Corolla",2021,15000);

int index;

cin>>index;

if (index==0){

electriccar.quit();

}

else if (index==1){

electriccar.addVehicle();

}

else if (index==2){

electriccar.ListVehicle();

}

else if (index==3){

electriccar.UpdateVehicle();

}

else if (index==4){

electriccar.RemoveVehicle();

}

electriccar.getFuelType();

return 0;

}

code link: https://www.onlinegdb.com/edit/MXuR3T1ho

output:

logic) Vehicle class is a base class, and types of vehicle such as diesel car, electric car are inheritance class. initialize constructor in base class vehicle class. and create a function to add , remove and update vehicle list etc. from base class. In main function initialize an object electriccar of derived class ElectricCar and take the input as an index of which function to be called and get the output.

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.