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:
-
Make
-
Model
-
Year
-
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
-
Vehicle
-
This class includes protected members such as Make, Model, Year and Odometer. These members are initialized using the class constructor.
-
The functions include getter and setter functions of Make(), Model(), Year() and Odometer().
-
Maintenance activities that should be done are checkTireRotation(), getCarInformation()
-
Let the three fuel types be
enum Type{
GAS,
DIESEL,
ELECTRIC
};
-
Let there be a pure virtual method to get the fuel type i.e.,
-
virtual Type getType() = 0;
-
GasCar
-
This is inherited from the vehicle class and has functions getType() and getFuelType()
-
DieselCar
-
This class is also a subclass of vehicle and the functions include getFuelType() and getType()
-
ElectricCar
-
This is a subclass of Vehicle class and methods include
-
checkTireRotation()- based on odometer reading, we decide whether the car needs to rotate tires or not.
-
checkChargerPower- based on odometer reading this advices to recharge power
-
getType() – to get the fuel type
-
FuelVehicle
-
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,
-
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.
-
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
-
In the main class, initialize the inventory and ask the user to select whether to add, update, list or delete the Vehicle list.
-
addVehicle() – to add new vehicle to inventory
-
ListVehicle()- to list the vehicles in the inventory
-
UpdateVehicle()- to update the vehicle in the inventory list
-
RemoveVehicle()- to remove the vehicle from the inventory list
-
Tire Rotation() – Check if tires need rotation
-
OilChange()- check if car requires oil change
-
Recharge() – check if vehicle needs recharge
-
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.
-
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" |
|
-
Retrieve the user input on the vehicle’s make, model, year, type and odometer.
-
getNewMake() – If input is blank, request again
-
getNewModel() – If input is blank, request again
-
getYear() – If input doesn’t have 4 digits, request again
-
getNewOdometer()- Input should be only numericals
-
getNewType() – Input should be within 0-2, else request again
-
Retrieve the selected car from the user input
-
selectCar() – Input should be within the size of vehicle list, else request again
-
getNewOdometerReading() – New odometer reading is used to calculate the oil change, tire rotation, power recharge etc.
#include
using namespace std;
enum Type
{
GAS,
DIESEL,
ELECTRIC
};
class vehicle
{
protected:
string make_vehicle, model;
int year,odometer;
int Type;
public:
vehicle()
{
cout<<"Enter the vehicle type\n0 for GAS\n1 for DIESEL\n2 for ELECTRIC\n"<
cin>>Type;
switch(Type){
case GAS :
cout<<"Gas vehicle "<
break;
case DIESEL :
cout<<"Diesel vehicle "<
break;
case ELECTRIC :
cout<<"Electric vehicle "<
break;
}
cout<<"\nEnter make of the vehicle"<
cin>>make_vehicle;
cout<<"Enter the vehicle model : "<< endl>
cin>>model;
while ((year<1950>2023)) //year shoule be enter between 1950-2023
{
cout<<"Enter the vehicle manufaturing year (1950-2023) : "<< endl>
cin>>year;
}
while ((odometer < 1> 500000)) //below 500000
{
cout<<"Enter the odometer reading (below 500000) : "<< endl>
cin>>odometer;
}
}
};
class service : public vehicle
{
protected:
int tire_remaining, battery_remaing;
public:
service()
{
tire_remaining = 50000 - odometer;
battery_remaing = 400 - odometer;
}
void checkTireRotation()
{
cout << "Tire rotation information: " << endl>
if(odometer >50000)
cout<< "The tires need to be changed as their lifetime is over"<
else
cout<< "Tire should be change after "<
}
void check_charger_power()
{
cout << "Battery information: " << endl>
if (Type==2)
{
if(odometer > 400)
cout<< "The battery need to be charge, battery is too low"<
else
cout<< "Check the battery level after "<
}
else
cout<<"This is not Electric vehicle"<
}
void check_oil()
{
cout << "Vehicle oil information: " << endl>
if (odometer >= 10000)
{
cout << "The oil needs to be changed." << endl>
}
else
{
cout << "The oil is in good condition. After 10000kms, it will need to be changed." << endl>
}
}
};
class Vehicle_info : public vehicle
{
protected:
int customer_vehicle_type;
public:
void get_vehicle_info() //function for printing vehicle info
{
cout << "Vehicle information: "<
switch (Type)
{
case GAS:
cout << "This vehicle runs on liquefied gas." << endl>
break;
case DIESEL:
cout << "This vehicle runs on diesel ." << endl>
break;
case ELECTRIC:
cout << "This vehicle runs on rechargeable battery." << endl>
break;
default:
cout << "Invalid vehicle type selected." << endl>
break;
}
}
};
int main()
{
service s; //object created
Vehicle_info vi;
int choice;
while((choice<6>6)){
cout << "\nEnter the choice of service (1 to 4): "<
cout << "\n1. vehicle information\n2. Tire Rotation\n3. check oil condition\n4. check charge power\n5.Quit"<
cin >> choice;
switch (choice)
{
case 1:
vi.get_vehicle_info();
break;
case 2:
s.checkTireRotation();
break;
case 3:
s.check_oil();
break;
case 4:
s.check_charger_power();
break;
case 5:
cout<<"Exit the program"<
exit(0);
}
}
return 0;
}
