Project 3
Project 3
Aim: create the C++ program for car maintenance and able to add, Update, delete and list operation of car data as per requirement.
Description:
In this project we have to develop the Object oriented library for Automobile maintenance. In this project there are four type of cars supported by the this library. 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. There are four details make, model, year and odometer. The first function is vehicle, under this make, model, year and odometer are the functions. Check tire rotation and get car information are the maintenance activities. We create the enum user define data, under this gas, electric and diesel are the car type. Next we create the Gas car which inherited from the vehicle. Next we create the diesel type which is the subclass of the vehicle class and it includes gettype () and getfuiltype () functions. The fuel car is also subclass of the vehicle. In this tire rotation, charge power and get type are the functions. Fuel vehicle is the abstract class of the vehicle and inherits check oil and get fuel type functions.
We create the main class where we can add, list, delete and update the vehicle list. Under this class addvehicle, listvehicle, updatevehicle, removevehicle, tirerotation, oilchane and recharge are the functions. User able to select any function form the above by indexing it a 0 to 7.user can select the car by getcar() function and newodometer() also.
C++ program:
// c program for car maintanence
#include <iostream> //library files
#include <vector>
using namespace std;
enum class Type { //user define class
GAS,
DIESEL,
ELECTRIC
};
class Vehicle { //vehicle class
protected:
string make;
string model;
int year;
int odometer;
public:
Vehicle(const string& make, const string& model, int year, int odometer)
: make(make), model(model), year(year), odometer(odometer) {}
string getMake() const { return make; }
string getModel() const { return model; }
int getYear() const { return year; }
int getOdometer() const { return odometer; }
virtual Type getFuelType() = 0;
virtual void performMaintenanceActivities() = 0;
};
class GasCar : public Vehicle {
public:
GasCar(const string& make, const string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
Type getFuelType() override { return Type::GAS; }
void performMaintenanceActivities() override {
// Perform gas car specific maintenance activities
}
};
class DieselCar : public Vehicle {
public:
DieselCar(const string& make, const string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
Type getFuelType() override { return Type::DIESEL; }
void performMaintenanceActivities() override {
// Perform diesel car specific maintenance activities
}
};
class ElectricCar : public Vehicle {
public:
ElectricCar(const string& make, const string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
Type getFuelType() override { return Type::ELECTRIC; }
void performMaintenanceActivities() override {
// Perform electric car specific maintenance activities
}
};
class Library {
vector<Vehicle*> vehicles;
public:
void addVehicle(Vehicle* vehicle) {
vehicles.push_back(vehicle);
}
void listVehicles() {
cout << "Inventory:" << endl;
for (const auto& vehicle : vehicles) {
cout << "Make: " << vehicle->getMake() << ", Model: " << vehicle->getModel()
<< ", Year: " << vehicle->getYear() << ", Odometer: " << vehicle->getOdometer()
<< endl;
}
}
void removeVehicle(int index) {
if (index >= 0 && index < vehicles.size()) {
delete vehicles[index];
vehicles.erase(vehicles.begin() + index);
cout << "Vehicle removed from inventory." << endl;
} else {
cout << "Invalid index. No vehicle found." << endl;
}
}
void performMaintenanceActivities(int index) {
if (index >= 0 && index < vehicles.size()) {
vehicles[index]->performMaintenanceActivities();
cout << "Maintenance activities performed." << endl;
} else {
cout << "Invalid index. No vehicle found." << endl;
}
}
};
int main() {
Library library; //library index
int choice;
do {
cout << "Menu:\n"
<< " 0. Quit.\n"
<< " 1. List inventory.\n"
<< " 2. Add vehicle.\n"
<< " 3. Remove vehicle.\n"
<< " 4. Perform maintenance activities.\n"
<< "Enter your choice: ";
cin >> choice;
switch (choice) {
case 0:
cout << "Quitting the program." << endl;
break;
case 1:
library.listVehicles();
break;
case 2: {
cout << "Enter vehicle details:" << endl;
string make, model;
int year, odometer;
cout << "Make: ";
cin >> make;
cout << "Model: ";
cin >> model;
cout << "Year: ";
cin >> year;
cout << "Odometer: ";
cin >> odometer;
int fuelTypeChoice;
cout << "Fuel type:\n"
<< " 0. Gas\n"
<< " 1. Diesel\n"
<< " 2. Electric\n"
<< "Enter fuel type choice: ";
cin >> fuelTypeChoice;
Vehicle* vehicle = nullptr;
switch (fuelTypeChoice) {
case 0:
vehicle = new GasCar(make, model, year, odometer);
break;
case 1:
vehicle = new DieselCar(make, model, year, odometer);
break;
case 2:
vehicle = new ElectricCar(make, model, year, odometer);
break;
default:
cout << "Invalid fuel type choice." << endl;
break;
}
if (vehicle != nullptr) {
library.addVehicle(vehicle);
cout << "Vehicle added to inventory." << endl;
}
break;
}
case 3: {
int index;
cout << "Enter the index of the vehicle to remove: ";
cin >> index;
library.removeVehicle(index);
break;
}
case 4: {
int index;
cout << "Enter the index of the vehicle to perform maintenance activities: ";
cin >> index;
library.performMaintenanceActivities(index);
break;
}
default:
cout << "Invalid choice. Please try again." << endl;
break;
}
} while (choice != 0);
return 0;
}
Output:
Menu:
- Quit.
- List inventory.
- Add vehicle.
- Remove vehicle.
- Perform maintenance activities.
Enter your choice: 2
Enter vehicle details:
Make: tata
Model: nisan
Year: 2023
Odometer: 500
Fuel type:
- Gas
- Diesel
- Electric
Enter fuel type choice: 2
Vehicle added to inventory.
Menu:
- Quit.
- List inventory.
- Add vehicle.
- Remove vehicle.
- Perform maintenance activities.
Enter your choice: 1
Inventory:
Make: tata, Model: nisan, Year: 2023, Odometer: 500
Menu:
- Quit.
- List inventory.
- Add vehicle.
- Remove vehicle.
- Perform maintenance activities.
Enter your choice: 2
Enter vehicle details:
Make: bajaj
Model: tvs
Year: 2023
Odometer: 1000
Fuel type:
- Gas
- Diesel
- Electric
Enter fuel type choice: 5
Invalid fuel type choice.
Menu:
- Quit.
- List inventory.
- Add vehicle.
- Remove vehicle.
- Perform maintenance activities.
Enter your choice: 0
Quitting the program.
screen short of program and output:

Result:
In this way, we have created the c++ program for car maintenance. also create the feature of add, update, list and delete for car types and their main maintenance work.