Design Parking Lot System
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-03-11
Problem Statement
Design a Parking Lot System that manages parking spaces for different types of vehicles. The focus is on object-oriented design, modularity, and handling parking operations efficiently.
✅ Functional Requirements
1.Parking Slots & Floors
•Multiple floors, each with multiple parking slots.
•Slots can be categorized by vehicle type (e.g., motorcycle, car, truck).
•Track availability of slots per floor and overall.
2.Vehicle Management
•Store vehicle details: vehicleNumber, vehicleType, ownerInfo.
•Assign vehicle to an appropriate slot.
•Release slot when vehicle leaves.
3.Ticketing & Billing
•Issue a parking ticket when a vehicle enters.
•Track entry time and exit time for billing.
•Calculate parking fee based on duration and vehicle type.
4.Optional Features
•Reserved or handicapped slots.
•Real-time availability display.
•Notifications for exceeding parking duration.
🔐 Constraints & Assumptions
•Parking lot can have multiple floors and variable slot sizes.
•Assume unique vehicle numbers.
•Focus is on LLD and parking operations, not payment gateway integration.
🧱 Key Components & Classes
1.Vehicle Class
1
2class Vehicle {
3private:
4 string vehicleNumber;
5 string vehicleType; // e.g., Car, Motorcycle, Truck
6 string ownerInfo;
7public:
8 string getVehicleNumber();
9 string getVehicleType();
10};1.ParkingSlot Class
1
2class ParkingSlot {
3private:
4 int slotId;
5 string slotType; // vehicle type it supports
6 bool isOccupied;
7 Vehicle* parkedVehicle;
8public:
9 bool assignVehicle(Vehicle* vehicle);
10 void removeVehicle();
11 bool isAvailable();
12};1.Floor Class
1
2class Floor {
3private:
4 int floorNumber;
5 vector<ParkingSlot*> slots;
6public:
7 ParkingSlot* getAvailableSlot(string vehicleType);
8 void addSlot(ParkingSlot* slot);
9};1.ParkingLot Class
1
2class ParkingLot {
3private:
4 vector<Floor*> floors;
5public:
6 ParkingSlot* parkVehicle(Vehicle* vehicle);
7 void releaseVehicle(Vehicle* vehicle);
8 void displayAvailability();
9};1.Ticket Class
1
2class Ticket {
3private:
4 string ticketId;
5 Vehicle* vehicle;
6 DateTime entryTime;
7 DateTime exitTime;
8public:
9 void generateTicket(Vehicle* vehicle);
10 double calculateFee();
11};🔄 Example Workflow
1.Vehicle enters → ParkingLot.parkVehicle(vehicle) → assigns an available slot.
2.Ticket is generated with entry time.
3.Vehicle exits → ParkingLot.releaseVehicle(vehicle) → slot marked available.
4.Parking fee calculated using ticket entry and exit time.
🧪 Expected Deliverables
•Class diagram showing Vehicle, ParkingSlot, Floor, ParkingLot, and Ticket.
•Implementation of parking, slot assignment, release, and ticketing.
•Test cases:
•Park different vehicle types
•Release vehicle and update availability
•Fee calculation
•Handle full parking lot scenarios
💡 Discussion Points
•Slot allocation strategy: first available, nearest slot, or optimized for floor capacity.
•Handling concurrent parking requests (thread-safe operations).
•Optional: integrating sensors or automated entry/exit gates.
•Extensibility for multiple parking lots under same system.