Project 3
Aim of the project:
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.
Program:
// Header files
#include <iostream>
#include <string>
using namespace std;
//Assign max vehicles
const int MAX_VEHICLES = 100;
// Assign the class
class Vehicle
{
protected:
string make;
string model;
int year;
long int odometer;
static Vehicle v[MAX_VEHICLES];
static int vehCount;
public:
Vehicle(string _make = "", string _model = "", int _year = 0, long int _odometer = 0)
{
make = _make;
model = _model;
year = _year;
odometer = _odometer;
}
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(long int val) {
odometer = val;
}
void checkTireRotation() {
int remainder = odometer - 50000;
if (remainder > 0)
cout << "Please replace tires. Tires in good condition. Remaining: " << (0 - remainder) << endl;
else
cout << "Tire rotation not required. Tires in good condition." << endl;
}
string getNewModel() {
string model;
cout << "Enter model: ";
cin >> model;
return model;
}
long int getNewOdometer() {
long int odo;
cout << "Enter odometer reading: ";
cin >> odo;
return odo;
}
int getNewType() {
int type = -1;
do {
cout << "Enter 0: Gas\n1. Disel\n2. Electric: ";
cin >> type;
} while (type < 0 || type > 2);
return type;
}
int getNewYear() {
int year;
cout <<"Enter year of manufactur: ";
cin >> year;
return year;
}
string getNewMake() {
string make;
cout <<"Enter the make: ";
cin >> make;
return make;
}
void addVehicle() {
if (vehCount >= MAX_VEHICLES) {
cout << "Inventory is full. Cannot add more vehicles." << endl;
return;
}
int type = getNewType();
string make = getNewMake();
string model = getNewModel();
long int odo = getNewOdometer();
int year = getNewYear();
v[vehCount].setMake(make);
v[vehCount].setModel(model);
v[vehCount].setOdo(odo);
v[vehCount].setYear(year);
vehCount++;
cout << "Added vehicle" << endl;
}
void updateVehicle() {
string make;
cout << "Enter the make of the vehicle you need to update: ";
cin >> make;
bool found = false;
for (int i = 0; i < vehCount; i++) {
if (v[i].getMake() == make) {
found = true;
int selection;
cout << "Enter the parameter to be updated:\n1. Year\n2. Odometer reading: ";
cin >> selection;
if (selection == 1) {
int newYear;
cout << "Enter new manufacturing year: ";
cin >> newYear;
v[i].setYear(newYear);
} else if (selection == 2) {
long int newOdo;
cout << "Enter new odometer reading: ";
cin >> newOdo;
v[i].setOdo(newOdo);
} else {
cout << "Invalid selection" << endl;
}
break;
}
}
if (!found)
cout << "Car make not found" << endl;
}
void removeVehicle() {
string make;
cout << "Enter the make of the vehicle you need to remove: ";
cin >> make;
bool found = false;
for (int i = 0; i < vehCount; i++) {
if (v[i].getMake() == make) {
found = true;
for (int j = i; j < vehCount - 1; j++) {
v[j] = v[j + 1];
}
vehCount--;
cout << "Vehicle removed" << endl;
break;
}
}
if (!found)
cout << "Car make not found" << endl;
}
void listVehicles() {
if (vehCount == 0) {
cout << "No vehicles in inventory" << endl;
return;
}
cout << "Inventory:" << endl;
cout << "Make\tModel\tOdometer\tYear" << endl;
for (int i = 0; i < vehCount; i++) {
cout << v[i].getMake() << "\t" << v[i].getModel() << "\t" << v[i].getOdo() << "\t" << v[i].getYear() << endl;
}
}
void oilChange() {
string make;
cout << "Enter the make of the vehicle you need to check oil: ";
cin >> make;
bool found = false;
for (int i = 0; i < vehCount; i++) {
if (v[i].getMake() == make) {
found = true;
cout << "Oil change not required" << endl;
break;
}
}
if (!found)
cout << "Car make not found" << endl;
}
void checkCharge() {
string make;
cout << "Enter the make of the vehicle you need to check battery: ";
cin >> make;
bool found = false;
for (int i = 0; i < vehCount; i++) {
if (v[i].getMake() == make) {
found = true;
cout << "Batteries are good to go" << endl;
break;
}
}
if (!found)
cout << "Car make not found" << endl;
}
};
Vehicle Vehicle::v[MAX_VEHICLES];
int Vehicle::vehCount = 0;
int main() {
Vehicle vehicle;
char choice;
do {
cout << "Choose the required option:\n";
cout << "0. Quit\n";
cout << "1. List inventory\n";
cout << "2. Add vehicle\n";
cout << "3. Update vehicle\n";
cout << "4. Remove vehicle\n";
cout << "5. Check tire rotation\n";
cout << "6. Check oil\n";
cout << "7. Check battery\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case '0':
cout << "Quitting the program...\n";
break;
case '1':
vehicle.listVehicles();
break;
case '2':
vehicle.addVehicle();
break;
case '3':
vehicle.updateVehicle();
break;
case '4':
vehicle.removeVehicle();
break;
case '5':
vehicle.checkTireRotation();
break;
case '6':
vehicle.oilChange();
break;
case '7':
vehicle.checkCharge();
break;
default:
cout << "Invalid choice. Please try again.\n";
break;
}
cout << endl;
} while (choice != '0');
return 0;
}
Result:
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 2
Enter 0: Gas
1. Disel
2. Electric: 0
Enter the make: TATA
Enter model: TESTING
Enter odometer reading: 3000
Enter year of manufactur: 2022
Added vehicle
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 2
Enter 0: Gas
1. Disel
2. Electric: 1
Enter the make: HUNDAI
Enter model: HYBRID
Enter odometer reading: 20000
Enter year of manufactur: 2020
Added vehicle
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 1
Inventory:
Make Model Odometer Year
TATA TESTING 3000 2022
HUNDAI HYBRID 20000 2020
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 3
Enter the make of the vehicle you need to update: TATA
Enter the parameter to be updated:
1. Year
2. Odometer reading: 2
Enter new odometer reading: 25000
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 1
Inventory:
Make Model Odometer Year
TATA TESTING 25000 2022
HUNDAI HYBRID 20000 2020
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 1
Inventory:
Make Model Odometer Year
TATA TESTING 25000 2022
HUNDAI HYBRID 20000 2020
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 4
Enter the make of the vehicle you need to remove: TATA
Vehicle removed
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 1
Inventory:
Make Model Odometer Year
HUNDAI HYBRID 20000 2020
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 1
Inventory:
Make Model Odometer Year
HUNDAI HYBRID 20000 2020
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 5
Tire rotation not required. Tires in good condition.
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice:
7
Enter the make of the vehicle you need to check battery: HUNDAI
Batteries are good to go
Choose the required option:
0. Quit
1. List inventory
2. Add vehicle
3. Update vehicle
4. Remove vehicle
5. Check tire rotation
6. Check oil
7. Check battery
Enter your choice: 0
Quitting the program...