Challenge

Project 3

PROJECT-3 :

Build an object-oriented library which can be used to track automobile maintenance. There can be different car types such as petrol, diesel, gas, electric etc., This library should be able to support at least three of the car types.

Maintenance tasks include activities like oil change or replace oil filter, replace air filter, replace fuel filter, tire rotations, infotainment system debug, replace spark plugs, replace the cabin or a/c filter, check the level and refill clutch fluid or brake fluid, examine belts, wipers, hoses, check the tire conditions, check the charging systems and battery.

Every vehicle should have the following details:

  1. Make

  2. Model

  3. Year

  4. Odometer reading

The library interfaces or the API’s (Application Program Interface) should be capable of adding, updating, listing and removing the entries at runtime.

Consider there are three classes such as

  1. Vehicle

    1. This class includes protected members such as Make, Model, Year and Odometer. These members are initialized using the class constructor.

    2. The functions include getter and setter functions of Make(), Model(), Year() and Odometer().

    3. Maintenance activities that should be done are checkTireRotation(), getCarInformation()

    4. Let the three fuel types be

enum Type{

GAS,

DIESEL,

ELECTRIC

};

  1. Let there be a pure virtual method to get the fuel type i.e.,

    1. virtual Type getType() = 0;

  1. GasCar

    1. This is inherited from the vehicle class and has functions getType() and getFuelType()

  2. DieselCar

    1. This class is also a subclass of vehicle and the functions include getFuelType() and getType()

  3. ElectricCar

    1. This is a subclass of Vehicle class and methods include

      1. checkTireRotation()- based on odometer reading, we decide whether the car needs to rotate tires or not.

      2. checkChargerPower- based on odometer reading this advices to recharge power

      3. getType() – to get the fuel type

  4. FuelVehicle

    1. This is an abstract class that inherits vehicle class. The methods in this class include checkOil() and pure virtual function getFuelType()

Maintenance activities that has to be done are as follows,

  1. Check tire rotation: Let the tire cycle be 50,000 km. Calculate the distance the car has run and if this distance run is at 50k km, then advise rotation, else tires are good to go. Also, calculate the remainder of each 50k km, If remainder >=0 then advice to rotate tires.

  2. Check Power: Let the distance be 400km, If the distance the car has run is at 400km, then advise battery to be recharged else your vehicle is good to go.

Now that we have learnt about the classes to be created, we need to write our driver code i.e., main.cpp

  1. In the main class, initialize the inventory and ask the user to select whether to add, update, list or delete the Vehicle list.

    1. addVehicle() – to add new vehicle to inventory

    2. ListVehicle()- to list the vehicles in the inventory

    3. UpdateVehicle()- to update the vehicle in the inventory list

    4. RemoveVehicle()- to remove the vehicle from the inventory list

    5. Tire Rotation() – Check if tires need rotation

    6. OilChange()- check if car requires oil change

    7. Recharge() – check if vehicle needs recharge

  2. Check for the user input, 0-1-2-3-4-5-6-7, Functions will be called based on the input provided by the user. If the input is wrong, ask again.

  3. Menu should be as below,

<< " 0. Quit.\n"

<< " 1. List inventory.\n"

<< " 2. Add vehicle.\n"

<< " 3. Update vehicle\n"

<< " 4. Remove vehicle\n"

<< " 5. Tire Rotation\n"

<< " 6. Oil Change\n"

<< " 7. Recharge\n"

  1. Retrieve the user input on the vehicle’s make, model, year, type and odometer.

    1. getNewMake() – If input is blank, request again

    2. getNewModel() – If input is blank, request again

    3. getYear() – If input doesn’t have 4 digits, request again

    4. getNewOdometer()- Input should be only numericals

    5. getNewType() – Input should be within 0-2, else request again

  2. Retrieve the selected car from the user input

    1. selectCar() – Input should be within the size of vehicle list, else request a

 * question_1.cpp
 *
 *  Created on: 11-Apr-2023
 *      Author: Subhajit
 */
#include
#include

using namespace std;
class Vehicle // Take base class as Vehicle
{
	protected:
	string Make1,Make2,Make3,Model1,Model2,Model3; // Take protected class Members
	int year, odometer,remainder;

public:
	enum Type{GAS,DIESEL,ELECTRIC};


Vehicle(string &a,string &b,string&c,string&d,string&e,string&f,int i, int j):Make1(a),Make2(b),Make3(c),Model1(d),Model2(e),Model3(f),year(i),odometer(j)
	{

	}                                                                                                    // Do the member initialisation by parametirized constructor

 string newgetMake(); // Taking the necessary Functions, for the class.

	 void setMake();

	 string newgetModel();

	 void setModel();

	 void newgetyear();

	 void setyear();

	 int newgetodometer();

	 void setodometer();

};
class Gascar // Different classes
	{
public:
	void getType();
	void getFueltype();
};

class DieselCar // Different classes
{
public:
	void getType();
	void getFueltype();
};
class ElectricCar // Different classes
{
public:
	void checkTireRotation();
	void checkChargePower();
	void getType();
};
class FuelVehicle // Different classes
{public:
	void checkOil();
	void getfuelType();
};

void Vehicle::setMake() // Taking the Base class Function
{

	cout<<"Retriving your Car Maker Data....."<<endl;


}
string Vehicle::newgetMake() // Taking the Base class Function
	{
		cout<<"The maker of the car is"<<endl<<"1."<<Make1<<endl<<"2. "<<Make2<<" 3."<<Make3<<endl;
	}


  void Vehicle::setModel() // Taking the Base class Function
	{

		cout<<"Retriving your Car Model Data....."<<endl;

	}
	string Vehicle:: newgetModel() // Taking the Base class Function
	{
    cout<<"The Model is"<<" "<<"1."<<Model1<<" "<<" 2."<<Model2<<"  "<<"3."<<Model3<<endl;
	}
	void Vehicle::setyear() // Taking the Base class Function
	{
	cout<<"Retriving your Car's Manufacturing Year"<<endl;


	}
	void Vehicle::newgetyear() // Taking the Base class Function
	{
		cout<<"The year of the car is"<<year<<endl;
	}
	void Vehicle::setodometer() // Taking the Base class Function
		{
         cout<<"Retriving your car's odometer Reading......"<<endl;
		}
	int Vehicle::newgetodometer() // Taking the Base class Function
	{
		return odometer;
	}



		void Gascar::getType() // Derived class object
		{
			cout<<"Retriving your car Type..."<<endl;
		}

		void Gascar::getFueltype() // Derived class object
		{
		string f={"LPG"};
        cout<<"The Fuel Type is"<<" "<<f<<endl;
		}
		void DieselCar::getType() // Derived class object
		{

		}

		void DieselCar::getFueltype() // Derived class object
		{
			string D={"Diesel"};
			cout<<"your car type is"<<"  "<<D<<endl;
		}
		void ElectricCar::checkTireRotation() // Derived class object
		{
			    int c,d ;
            cout<<"Retriving Data from your Vehicle...."<<endl<<"You have Traveled.."<<endl;
            cin>>d;
            if(d>=50000)
			cout<<"Change tire"<<endl;
			else
	        cout<<"you are good to go"<<endl;
		}

		void ElectricCar::checkChargePower() // Derived class object
		{
			int d;
			cout<<"Enter the distance your car travel"<<endl;
			cin>>d;
			if(d>=400)
			{
				cout<<"Battery need to be Recharge"<<endl;

			}
			else
				cout<<"You are ready to go";
		}
		void ElectricCar::getType() // Derived class object
		{
			string s={"Electric_Vehicle"};
			cout<<"Retriving your car Fuel Type"<<endl;


			cout<<"Your car's fuel type is"<<s<<endl;
		}
        void FuelVehicle::checkOil() // Derived class object
        {
        	int oillimit;
        	cout<<"Retriving data of your car's oil limit"<<endl;
        	cin>>oillimit;
        	cout<<"your car has"<<oillimit<<"% oil left"<<endl;
        }
        void FuelVehicle::getfuelType() // Derived class object
        {
        	string F;
        	cout<<"Retriving your Car's Fuel Type Data";
        	cin>>F;
        	cout<<"The Fuel type of Car is "<<F<<endl;
        }

		class Maintanance // Main class
		{
		public:
			int distance,battery; // Take public members of main class
			string inventory={"Tata Hyundai Toyota"};
			void Quit() // Function for Quitting the List.
			{
				cout<<"Thanks for Visiting us";

			}
			void List_inventory() // Inventory for show the Inventory
			{

				cout<<"Welcome to your inventory"<<endl;
				cout<<"The vehicle lists in your inventory is:"<<inventory<<endl;

			}
			void Add_Vehicle() // Function for add the vehicle
			{
		       string vehicle4,Make4,Model4;
		       int year4;
				cout<<"Enter the Vehicle you want to add"<<endl;

				cin>>vehicle4;
				cout<<"Enter the Makers of the Car"<<endl;
				cin>>Make4;
				cout<<"Enter the Model of the Car"<<endl;
				cin>>Model4;
				cout<<"Enter the year of Manufacturing"<<endl;
				cin>>year4;
				inventory=inventory+" "+vehicle4;
				cout<<"you have successfully updated your inventory"<<endl;
				cout<<"New Car Adeed:"<<" "<<vehicle4<<endl<<" Make of the Car"<<" "<<Make4<<endl<<" Model of the Car"<<" "<<Model4<<endl<<"Year of Manufacturing"<<" "<<year4<<endl;
			}
		    void Update_Vehicle() // Update the Vehicle list

		    {
		    	cout<<"your updated vehicle is :"<<inventory<<endl;

		    }
		    void Remove_Vehicle() // Remove Vehicle list
		    {
		    	 string word;
		    	 cout<<"The Enter the Car you want to delete"<<endl;
		    	cin>>word;
		    	int pos=inventory.find(word);
		    	if(pos!=string::npos)
		    	{
		    		inventory.erase(pos,word.length()+1);
		    		cout<<"The updated inventory"<<" "<<inventory<<endl;
		    	}
		    	else
		    		cout<<"The vehicle is not found"<<endl;
		    }
		    void Tire_Rotation() //  Check Tire Rotation
		    {
		    	int distance,d;
		    	cout<<"Enter the distance";
		    	cin>>distance;
		        if(distance>=50000)

		    	cout<<"Change tire"<<endl;
		    	else
		    		cout<<"you are good to go"<<endl;

		    }
		    void Oil_change() // Function for  check whether oil  need to change
		    {
		    	int oil;
		    	cout<<"Enter the oil limit of the vehicle";
		    	cin>>oil;
		    	if(oil<20)
		    		cout<<"oil needs to be changed"<<endl;
		    	else
		    		cout<<"you are good to go"<<endl;
		    }
		    void Recharge() // Function for  check whether Recharge to be done
		    {
		    	int battery;
		    	cout<<"Enter the battery value"<<endl;
		    	cin>>battery;
		    	if(battery<20)
		    		cout<<"battery need to be recharge"<<endl;
		    	else
		    		cout<<"You are ready to go"<<endl;
		    }
		};

		int main() // main function
		{
           int n,year,odometer;

       	string Make1,Make2,Make3,Model1,Model2,Model3;
        cout<<"Retrive the data from user"<<endl;
        cout<<"We are Retriving Data for the Make, Model,Year of manufacturing Datas"<<endl;
        cout<<"Enter the Makes of 3 Vehicles"<<endl;
        cin>>Make1>>Make2>>Make3;
        cout<<"Enter the Model of 3 Vehicles"<<endl;
        cin>>Model1>>Model2>>Model3;
        cout<<"Enter the Manufacturing Year";
        cin>>year;
        cout<<"Enter odometer Reading"<<endl;
        cin>>odometer;
        Vehicle V(Make1,Make2,Make3,Model1,Model2,Model3,year,odometer); // Passing the arguments through parametirized constructor
       	Gascar G; // Objects of different classes
       	DieselCar D;
        ElectricCar E;
        FuelVehicle F;

		Maintanance M ;

			cout<<"The Menu is follows"<<endl;
			cout<<"0.Quit"<<endl<<"1.List inventory"<<endl<<"2.Add Vehicle"<<"3.Update Vehicle"<<endl<<"4.Remove Vehicle"<<endl<<"5.Tire Rotation"<<endl<<"6.Oil Change"<<endl<<"7.Recharge"<<endl;
			cout<<"Enter the choice you want"<<endl;
			cin>>n;

			switch(n) // Starting of switch case

			{
			case 0:
			cout<<"You have chosen option 0"<<endl;
			M.Quit();
			//break;
			case 1:
			cout<<"you have chosen 1"<<endl;

			M.List_inventory(); // calling the function
			 V.setMake();
			 V.newgetMake();
			 V. setModel();
			 V.newgetModel();
			 V.setyear();
			 V.newgetyear();

			//break;
			case 2:
			cout<<"you have chosen option 2"<<endl;
			M.Add_Vehicle();

			//break;
			case 3:
			cout<<"you have chosen option 3"<<endl;
			M.Update_Vehicle();

			//break;
			case 4:
			cout<<"you have chosen option 4"<<endl;
			M.Remove_Vehicle();
			//break;
			case 5:
			cout<<"You have chosen option 5"<<endl;
			 V.setodometer();
			 V.newgetodometer();
			M.Tire_Rotation();
			//break;
			case 6:
			cout<<"you have chosen for oil change"<<endl;
			M.Oil_change();
			//break;
			case 7:
			cout<<"you have chosen option 7"<<endl;
			M.Recharge();
			break;
			}

			int i;
			cout<<"Enter the Type of Vehicle you want the details"<<endl; // Selection of the different types of vehicles
			cout<<"1. Gas Type "<<endl<<"2. Diesel Type"<<endl<<"3. Electric Type"<<endl<<"4. Fuel Type"<<endl;
			cin>>i;
			switch(i)
			{
			case 1:
		    G.getType();
		    G.getFueltype();
		    break;
			case 2:
	    	 D.getType();
			 D.getFueltype();
			 break;
			case 3:
			 E.getType();
			 E.checkTireRotation();
			 E.checkChargePower();

			 break;
			case 4:
			F.checkOil();
	  	    F.getfuelType();
           break;
			}


			return 0;

		}


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.