Project
Project
Project
Object Oriented
Programming
(PROJECT)
Submitted to Respected Ma’am: Nosheen Manzoor
#include <iostream>
#include <string>
class Car
{
protected:
string brand;
string model;
public:
string getBrand()
{
return brand;
}
string getModel()
{
return model;
}
virtual ~Car() {}
};
public:
ElectricCar(const string& brand, const string& model, double batteryCapacity)
: Car(brand, model), batteryCapacity(batteryCapacity) {}
Car::display();
cout << "Battery Capacity: " << batteryCapacity << " kWh" << endl;
OBJECT ORIENTED PROGRAMMING
}
~ElectricCar() {}
};
public:
GasolineCar(const string& brand, const string& model, double mileage)
: Car(brand, model), mileage(mileage) {}
~GasolineCar() {}
};
class CarLot
{
private:
Car** cars;
int numCars;
int capacity;
public:
CarLot(int capacity)
: numCars(0), capacity(capacity) {
cars = new Car*[capacity];
}
}
OBJECT ORIENTED PROGRAMMING
void displayAllCars() const {
for (int i = 0; i < numCars; i++) {
cars[i]->display();
cout<<"------------------------"<<endl;
}
}
}
~CarLot() {
for (int i = 0; i < numCars; i++) {
delete cars[i];
}
delete[] cars;
}
};
class CarRental {
private:
string renterName;
Car* rentedCar;
public:
CarRental(const string& renterName, Car* rentedCar)
: renterName(renterName), rentedCar(rentedCar) {}
return rentedCar;
}
OBJECT ORIENTED PROGRAMMING
int main() {
CarLot carLot(4);
carLot.addCar(&ec1);
carLot.addCar(&ec2);
carLot.addCar(&gc1);
carLot.addCar(&gc2);
cout << "All Cars in the Car Lot: " << endl;
carLot.displayAllCars();
string brand="Tesla";
string model="Model S";
Car* foundCar=carLot.findCar(brand, model);
if (foundCar)
{
cout<<"Found Car: "<<endl;
foundCar->display();
}
else
{
cout<<"Car not found."<<endl;
}