C++ Project – Parking Lot Management System
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
//Parking Lot Management System
#include <iostream>
using namespace std;
class ParkingLot
{
private:
int twoWheelerCount;
int fourWheelerCount;
const int maxTwoWheelers;
const int maxFourWheelers;
public:
// Constructor to initialize
ParkingLot(int max2W, int max4W) // 5 3
: maxTwoWheelers(max2W), maxFourWheelers(max4W) {
twoWheelerCount = 0;
fourWheelerCount = 0;
}
void parkVehicle(int type) //2
{
if (type == 2) {
if (twoWheelerCount < maxTwoWheelers) {
twoWheelerCount++;
cout << " 2-wheeler parked successfully.\n";
} else {
cout << " No space for 2-wheelers.\n";
}
} else if (type == 4) {
if (fourWheelerCount < maxFourWheelers) {
fourWheelerCount++;
cout << " 4-wheeler parked successfully.\n";
} else {
cout << " No space for 4-wheelers.\n";
}
} else {
cout << " Invalid vehicle type.\n";
}
}
void removeVehicle(int type) {
if (type == 2) {
if (twoWheelerCount > 0) {
twoWheelerCount--;
cout << " 2-wheeler exited successfully.\n";
} else {
cout << " No 2-wheeler is parked.\n";
}
} else if (type == 4) {
if (fourWheelerCount > 0) {
fourWheelerCount--;
cout << " 4-wheeler exited successfully.\n";
} else {
cout << " No 4-wheeler is parked.\n";
}
} else {
cout << " Invalid vehicle type.\n";
}
}
void showStatus() {
cout << "\n Parking Lot Status:";
cout << "\n---------------------------";
cout << "\n2-Wheelers Parked: " << twoWheelerCount << "/" << maxTwoWheelers;
cout << "\n4-Wheelers Parked: " << fourWheelerCount << "/" << maxFourWheelers;
cout << "\nTotal Vehicles: " << (twoWheelerCount + fourWheelerCount);
cout << "\n---------------------------\n";
}
};
int main() {
system("cls");
int b,c;
cout<<"\n Enter capacity of Bikes: ";
cin>>b;
cout<<"\n Enter capacity of Cars: ";
cin>>c;
ParkingLot lot(b, c); // capacity: b bikes, c cars
int choice, type;
do {
cout << "\n====== Parking Lot Menu ======";
cout << "\n1. Park Vehicle";
cout << "\n2. Remove Vehicle";
cout << "\n3. Show Parking Status";
cout << "\n4. Exit";
cout << "\nEnter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "\nEnter Vehicle Type (2 for Bike, 4 for Car): ";
cin >> type;
lot.parkVehicle(type);
break;
case 2:
cout << "\nEnter Vehicle Type to Remove (2 for Bike, 4 for Car): ";
cin >> type;
lot.removeVehicle(type);
break;
case 3:
lot.showStatus();
break;
case 4:
cout << "\nThank you! Exiting...\n";
break;
default:
cout << " Invalid choice. Try again.\n";
}
} while (choice != 4);
return 0;
} Did we exceed your expectations?
If Yes, share your valuable feedback on Google

