Challenge

Project 3

kindly refer to ABINAYA INBAMANI MADAM

PROJECT-3 ANS-

#include <iostream>
#include <vector>

enum class Type {
GAS,
DIESEL,
ELECTRIC
};

class Vehicle {
protected:
std::string make;
std::string model;
int year;
int odometer;

public:
Vehicle(const std::string& make, const std::string& model, int year, int odometer)
: make(make), model(model), year(year), odometer(odometer) {}

std::string getMake() const { return make; }
std::string getModel() const { return model; }
int getYear() const { return year; }
int getOdometer() const { return odometer; }

virtual Type getType() = 0;
virtual void checkTireRotation() = 0;
virtual void checkChargerPower() = 0;
virtual void getCarInformation() = 0;
};

class GasCar : public Vehicle {
public:
GasCar(const std::string& make, const std::string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}

Type getType() override { return Type::GAS; }
void checkTireRotation() override { /* Implementation for tire rotation check */ }
void checkChargerPower() override {}
void getCarInformation() override {
std::cout << "Gas Car Information: " << make << ", " << model << ", " << year << std::endl;
}
};

class DieselCar : public Vehicle {
public:
DieselCar(const std::string& make, const std::string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}

Type getType() override { return Type::DIESEL; }
void checkTireRotation() override { /* Implementation for tire rotation check */ }
void checkChargerPower() override {}
void getCarInformation() override {
std::cout << "Diesel Car Information: " << make << ", " << model << ", " << year << std::endl;
}
};

class ElectricCar : public Vehicle {
public:
ElectricCar(const std::string& make, const std::string& model, int year, int odometer)
: Vehicle(make, model, year, odometer) {}

Type getType() override { return Type::ELECTRIC; }
void checkTireRotation() override {
if (odometer >= 50000 && odometer % 50000 == 0) {
std::cout << "Electric Car needs tire rotation." << std::endl;
} else {
std::cout << "Electric Car tires are good to go." << std::endl;
}
}
void checkChargerPower() override {
if (odometer >= 400 && odometer % 400 == 0) {
std::cout << "Electric Car needs battery recharge." << std::endl;
} else {
std::cout << "Electric Car battery is good." << std::endl;
}
}
void getCarInformation() override {
std::cout << "Electric Car Information: " << make << ", " << model << ", " << year << std::endl;
}
};

class Inventory {
private:
std::vector<Vehicle*> vehicles;

public:
~Inventory() {
for (Vehicle* vehicle : vehicles) {
delete vehicle;
}
}

void addVehicle(Vehicle* vehicle) {
vehicles.push_back(vehicle);
}

void listVehicles() {
for (Vehicle* vehicle : vehicles) {
vehicle->getCarInformation();
}
}

// Implement other methods like updateVehicle, removeVehicle, etc.
};

int main() {
Inventory inventory;

while (true) {
std::cout << "Menu:" << std::endl;
std::cout << "0. Quit" << std::endl;
std::cout << "1. List inventory" << std::endl;
std::cout << "2. Add vehicle" << std::endl;
std::cout << "3. Update vehicle" << std::endl;
std::cout << "4. Remove vehicle" << std::endl;
std::cout << "5. Tire Rotation" << std::endl;
std::cout << "6. Oil Change" << std::endl;
std::cout << "7. Recharge" << std::endl;

int choice;
std::cout << "Enter your choice: ";
std::cin >> choice;

// Implement switch case to call corresponding methods based on user's choice
// You'll need to handle inputs, create objects, and manage the inventory accordingly.
}

return 0;
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.