All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Code: #include #include #include using namespace std; enum class FuelType { PETROL, DIESEL, GAS, ELECTRIC}; class Vehicle {protected: string make_; string model_; int year_; int odometer_; public: Vehicle(string make, string model, int year, int odometer) : make_(make), model_(model),…
Omkar Madhavi
updated on 18 Aug 2023
Code:
#include
#include
#include
using namespace std;
enum class FuelType {
PETROL,
DIESEL,
GAS,
ELECTRIC
};
class Vehicle {
protected:
string make_;
string model_;
int year_;
int odometer_;
public:
Vehicle(string make, string model, int year, int odometer)
: make_(make), model_(model), year_(year), odometer_(odometer) {}
string getMake() const { return make_; }
void setMake(string make) { make_ = make; }
string getModel() const { return model_; }
void setModel(string model) { model_ = model; }
int getYear() const { return year_; }
void setYear(int year) { year_ = year; }
int getOdometer() const { return odometer_; }
void setOdometer(int odometer) { odometer_ = odometer; }
virtual FuelType getFuelType() = 0;
};
class ElectricCar : public Vehicle {
public:
ElectricCar(string make, string model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
FuelType getFuelType() override { return FuelType::ELECTRIC; }
void checkTireRotation() {
if (odometer_ P00 == 0) {
cout << "Time for a tire rotation." << endl> } else {
cout << "Tire rotation not needed yet." << endl> }
}
void checkPower() {
if (odometer_ @0 == 0) {
cout << "Your car needs to be recharged." << endl> } else {
cout << "Your car is good to go." << endl> }
}
};
class GasCar : public Vehicle {
public:
GasCar(string make, string model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
FuelType getFuelType() override { return FuelType::GAS; }
void checkTireRotation() {
if (odometer_ 000 == 0) {
cout << "Time for a tire rotation." << endl> } else {
cout << "Tire rotation not needed yet." << endl> }
}
void checkOilChange() {
if (odometer_ P00 == 0) {
cout << "Time for an oil change." << endl> } else {
cout << "Oil change not needed yet." << endl> }
}
};
class DieselCar : public Vehicle {
public:
DieselCar(string make, string model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}
FuelType getFuelType() override { return FuelType::DIESEL; }
void checkTireRotation() {
if (odometer_ �00 == 0) {
cout << "Time for a tire rotation." << endl> } else {
cout << "Tire rotation not needed yet." << endl> }
}
void checkOilChange() {
if (odometer_ 000 == 0) {
cout << "Time for an oil change." << endl> } else {
cout << "Oil change not needed yet." << endl> }
}
};
class MaintenanceLibrary {
private:
vector
public:
void addVehicle(Vehicle* vehicle) {
string make, model;
int year, odometer;
cout << "Enter vehicle make: ";
cin >> make;
cout << "Enter vehicle model: ";
cin >> model;
cout << "Enter vehicle year: ";
cin >> year;
cout << "Enter vehicle odometer reading: ";
cin >> odometer;
vehicle->setMake(make);
vehicle->setModel(model);
vehicle->setYear(year);
vehicle->setOdometer(odometer);
inventory_.push_back(vehicle);
cout << "Vehicle added to inventory." << endl> }
void listInventory() {
if (inventory_.empty()) {
cout << "The inventory is empty." << endl> return;
}
cout << "Inventory:" << endl>
for (size_t i = 0; i < inventory> Vehicle* vehicle = inventory_[i];
cout << i>getMake() << " " << vehicle>getModel() << " (" << vehicle>getYear() << ")" << endl> }
}
void updateVehicle(int index, string make, string model, int year, int odometer) {
if (index >= 0 && index < inventory> Vehicle* vehicle = inventory_[index];
vehicle->setMake(make);
vehicle->setModel(model);
vehicle->setYear(year);
vehicle->setOdometer(odometer);
} else {
cout << "Invalid index." << endl> }
}
void removeVehicle() {
if (inventory_.empty()) {
cout << "Inventory is empty." << endl> return;
}
int vehicleIndex;
cout << "Enter the index of the vehicle to remove: ";
cin >> vehicleIndex;
if (vehicleIndex >= 1 && vehicleIndex <= inventory_.size()) {
delete inventory_[vehicleIndex - 1];
inventory_.erase(inventory_.begin() + vehicleIndex - 1);
cout << "Vehicle removed from inventory." << endl> } else {
cout << "Invalid vehicle index." << endl> }
}
void tireRotation() {
if (inventory_.empty()) {
cout << "Inventory is empty." << endl> return;
}
for (Vehicle* vehicle : inventory_) {
GasCar* gasCar = dynamic_cast
DieselCar* dieselCar = dynamic_cast
ElectricCar* electricCar = dynamic_cast
if (gasCar != nullptr) {
gasCar->checkTireRotation();
} else if (dieselCar != nullptr) {
dieselCar->checkTireRotation();
} else if (electricCar != nullptr) {
electricCar->checkTireRotation();
}
}
}
void oilChange() {
if (inventory_.empty()) {
cout << "Inventory is empty." << endl> return;
}
for (Vehicle* vehicle : inventory_) {
GasCar* gasCar = dynamic_cast
DieselCar* dieselCar = dynamic_cast
if (gasCar != nullptr) {
gasCar->checkOilChange();
} else if (dieselCar != nullptr) {
dieselCar->checkOilChange();
}
}
}
void recharge() {
if (inventory_.empty()) {
cout << "Inventory is empty." << endl> return;
}
for (Vehicle* vehicle : inventory_) {
ElectricCar* electricCar = dynamic_cast
if (electricCar != nullptr) {
electricCar->checkPower();
}
}
}
~MaintenanceLibrary() {
for (Vehicle* vehicle : inventory_) {
delete vehicle;
}
}
};
int main() {
MaintenanceLibrary library;
int userInput;
do {
cout << "Maintenance Library Menu" << endl> cout << "1. Add Vehicle" << endl> cout << "2. List Inventory" << endl> cout << "3. Update Vehicle" << endl> cout << "4. Remove Vehicle" << endl> cout << "5. Tire Rotation" << endl> cout << "6. Oil Change" << endl> cout << "7. Recharge" << endl> cout << "0. QUIT" << endl> cout << "Enter your choice: ";
cin >> userInput;
switch (userInput) {
case 1: {
cout << "Select the vehicle type:" << endl> cout << "1. Electric Car" << endl> cout << "2. Gas Car" << endl> cout << "3. Diesel Car" << endl> cout << "Enter your choice: ";
int vehicleType;
cin >> vehicleType;
string make, model;
int year, odometer;
cout << "Enter vehicle make: ";
cin >> make;
cout << "Enter vehicle model: ";
cin >> model;
cout << "Enter vehicle year: ";
cin >> year;
cout << "Enter vehicle odometer reading: ";
cin >> odometer;
if (vehicleType == 1) {
library.addVehicle(new ElectricCar(make, model, year, odometer));
} else if (vehicleType == 2) {
library.addVehicle(new GasCar(make, model, year, odometer));
} else if (vehicleType == 3) {
library.addVehicle(new DieselCar(make, model, year, odometer));
} else {
cout << "Invalid vehicle type." << endl> }
break;
}
case 2:
library.listInventory();
break;
case 4:
library.removeVehicle();
break;
case 5:
library.tireRotation();
break;
case 6:
library.oilChange();
break;
case 7:
library.recharge();
break;
case 0:
cout << "Exiting the program.\n";
break;
default:
cout << "Invalid choice. Please enter a valid option.\n";
break;
}
} while (userInput != 0);
return 0;
}
Result:
Maintenance Library Menu
1. Add Vehicle
2. List Inventory
3. Update Vehicle
4. Remove Vehicle
5. Tire Rotation
6. Oil Change
7. Recharge
0. QUIT
Enter your choice: 1
Select the vehicle type:
1. Electric Car
2. Gas Car
3. Diesel Car
Enter your choice: 1
Enter vehicle make: Hyundai
Enter vehicle model: i10
Enter vehicle year: 2022
Enter vehicle odometer reading: 10000
Enter vehicle make: Hyundai
Enter vehicle model: Verna
Enter vehicle year: 2022
Enter vehicle odometer reading: 5000
Vehicle added to inventory.
Maintenance Library Menu
1. Add Vehicle
2. List Inventory
3. Update Vehicle
4. Remove Vehicle
5. Tire Rotation
6. Oil Change
7. Recharge
0. QUIT
Enter your choice: 0
Exiting the program.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 2 - Design and develop the web based Temperature control system using Beagle Bone Black.
Overview of the Project: Device Driver Write the device driver for MCP9808 Temperature Sensor. Probe function: Register the Platform device under driver/misc. Read function: It should send the i2c message to read the data from sensor and copy it to the user space. Alert pin connected to BBB as gpio interrupt. The temp…
21 Feb 2024 06:40 PM IST
Project 1 - Develop the full featured char driver as a loaded module
Overview of the Project: Kconfig build system The module should be added to the Kernel configuration Kconfig build system with tristate option. Char driver should be of Open --> Only one user is allowed to open the device. Other users should be blocked. Read and write operation --> store the data to the dynamically…
15 Feb 2024 09:52 AM IST
Project 2 - V&V SW Analysis II
Perform Static Code Review Analysis for “C:\**\LDRA_workarea\Examples\C_Testbed_examples\Testrain\Testrain.c” Generate Code review report and upload them. Perform Integration testing by including all the .C files available in the folder location C:\**\LDRA_workarea\Examples\Toolsuite\Cashregister_6.0\…
25 Jan 2024 05:30 AM IST
Project 2 - Development of TFT Cluster Speedometer Software Component
1) Development of TFT Cluster Speedometer Software Component Cluster Instrument receives the signals from other ECU via CAN bus interface. It also receives commands from the driver via steering wheel buttons. The signals are then processed by the Cluster ECU, after which the Cluster ECU may send the vehicle information…
24 Jan 2024 10:46 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.