Challenge

Project 3

Code

#include <iostream>
#include <stdlib.h>
#include <string.h>

using namespace std;

enum Type 
{
GAS, DIESEL, ELECTRIC
};

class Vehicle
{
	
	protected:
		string make,model;
		int year;
		long int odometer;
		
	public:
		Vehicle(string _make = "", string _model="",int _year=0, int _odo=0)
		{
			make = _make;
			model = _model;
			year = _year;
			odometer = _odo;
		}
		

        string getMake()
		{
			return make;
		}
		
		
		string getModel()
		{
			return model;
		}
		
		
		int getYear()
		{
			return year;
		}
		
		long int getOdo()
		{
			return odometer;
			
		}
		
		void setModel(string val)
		{
			model = val;
		}
		
		void setMake(string val)
		{
			make = val;
		}
		
		void setYear(int val)
		{
			year = val;
		}
		
		void setOdo(int val)
		{
			odometer = val;
		}
		
		virtual void TireRotation() 
		{
            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 Recharge() 
        {
            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 TireRotation() 
    {
        int distance = odometer % 50000;
        if (distance >= 0) 
        {
            std::cout << "\nTire rotation advised." << std::endl;
        }
        else
        {
            std::cout << "\nTires are good to go." << std::endl;
        }
    }

    void Recharge()
    {
        int distance = odometer % 400;
        if (distance == 0) 
        {
            std::cout << "\nCharger power recharge advised." << std::endl;
        }
        else
        {
            std::cout << "\nYour vehicle is good to go." << std::endl;
        }
    }

    void getFuelType() 
    {
        std::cout << "Fuel Type: Electric" << std::endl;
    }
};

void listVehicles()
{
    std::string list[10];
    list[0]="Maruti";
    list[1]="Hyundai";
    list[2]="Honda";
    list[3]="TATA";
    list[4]="Volkswagen";
    list[5]="Toyota";
    for(int i=0;i<5;i++)
    {
    std::cout<<list[i]<<std::endl;
    }
    
    exit (0);
}

void addVehicle()
{
    
}

void updateVehicle()
{
    
}

void removeVehicle()
{
    
}

void TireRotation()
{
    long int odo;
    std::cout<<"Enter the odometer value: "<<std::endl;
    cin>>odo;
    Vehicle V1;
    V1.setOdo(odo);
    V1.getOdo();
    V1.TireRotation();
    exit (0);
}

void oilChange()
{
    
}

void Recharge()
{
    long int odo;
    std::cout<<"Enter the odometer value: "<<std::endl;
    cin>>odo;
    Vehicle V1;
    V1.setOdo(odo);
    V1.getOdo();
    V1.Recharge();
    exit (0);
}




int main()
{
    int selection;
    
    std::cout<<"Choose from the Menu\n1.\tList of Vehicles\n2.\tAdd Vehicle\n3.\tUpdate Vehicle\n4.\tRemove Vehicle\n5.\tCheck Tyre Rotation\n6.\tOil Change\n7.\tCheck Charge\n"<<std::endl;
    
    std::cin>>selection;
    
    while(selection!=0)
    {
		
		
		switch(selection)
		{
			case 1: listVehicles();
					break;
			case 2: addVehicle();
					break;
			case 3: updateVehicle();
					break;
			case 4: removeVehicle();
					break;
			case 5: TireRotation();
					break;
			case 6: oilChange();
					break;
			case 7: Recharge();
					break;
			default: std::cout<<"Invalid selection: "<<selection;
		}
	}

}

Output

Checking Tyre Rotation

Checking Charge

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.