Project 2
//C++ program for an Object-Oriented Library to track Automobile Maintenance
#include <iostream>
#include <string>
//Maintenance class
class Maintenance {
protected:
std::string carType; //petrol, diesel, gas, electric
std::string maintenanceTask; //oil change, 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
public:
//constructor
Maintenance(std::string carType, std::string maintenanceTask)
: carType(carType), maintenanceTask(maintenanceTask) {
}
//functions
std::string getCarType() {
return carType;
}
std::string getMaintenanceTask() {
return maintenanceTask;
}
};
//MaintenanceTracker class
class MaintenanceTracker {
private:
Maintenance** maintenanceList;
int numMaintenance;
public:
//constructor
MaintenanceTracker()
: maintenanceList(nullptr), numMaintenance(0) {
}
//functions
void addMaintenance(std::string carType, std::string maintenanceTask) {
Maintenance** temp = new Maintenance*[numMaintenance+1];
for (int i = 0; i < numMaintenance; i++) {
temp[i] = maintenanceList[i];
}
temp[numMaintenance] = new Maintenance(carType, maintenanceTask);
numMaintenance++;
delete[] maintenanceList;
maintenanceList = temp;
}
void getMaintenanceTasks() {
std::cout << "Maintenance Tasks:" << std::endl;
for (int i = 0; i < numMaintenance; i++) {
std::cout << maintenanceList[i]->getCarType() << " - " << maintenanceList[i]->getMaintenanceTask() << std::endl;
}
}
};
int main() {
MaintenanceTracker mt;
mt.addMaintenance("Petrol", "Oil Change");
mt.addMaintenance("Diesel", "Replace Oil Filter");
mt.addMaintenance("Gas", "Replace Air Filter");
mt.getMaintenanceTasks();
return 0;
}