Requirements

The parking lot caters to different vehicles. It has multiple spots available based on size of the vehicle(bike , car , semi trcuk etc. The main functionalities will include:

  1. Parking spot assignment
  2. Multiple floor support
  3. Spot availability
  4. User or Admin
  5. Ticketing
  6. Paymet




Define Core Objects






Analyze Relationships





Establish Hierarchy

Design inheritance trees where applicable to promote code reuse and polymorphism. This step involves identifying common attributes and behaviors that can be abstracted into parent classes...






Design Patterns

Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...






Code:


#include <iostream> #include <vector> #include <string> using namespace std; class Vehicle { public: string licensePlate; string size; Vehicle(string plate, string sz) : licensePlate(plate), size(sz) {} }; class ParkingSpot { public: string size; string identifier; int floorNumber; // Added floor number to each spot bool isOccupied; Vehicle* v; // Pointer to a vehicle ParkingSpot(string sz, string id, int floor) : size(sz), identifier(id), floorNumber(floor), isOccupied(false), v(nullptr) {} // Assign a vehicle to the parking spot void assignVehicle(Vehicle* vehicle) { if (!isOccupied &amp;&amp; vehicle-&gt;size == size) { v = vehicle; isOccupied = true; } } // Remove the vehicle from the parking spot void removeVehicle() { if (isOccupied) { v = nullptr; isOccupied = false; } } }; class ParkingFloor { public: int floorNumber; vector<ParkingSpot> spots; // Vector to store parking spots on this floor ParkingFloor(int floorNum, int totalSpots) : floorNumber(floorNum) { // Initialize parking spots for this floor with different identifiers for (int i = 0; i &lt; totalSpots; i++) { spots.push_back(ParkingSpot(&quot;small&quot;, &quot;S&quot; + to_string(i), floorNum)); // Example: small-sized spots } } // Find an available spot for the vehicle on this floor ParkingSpot* findAvailableSpot(Vehicle* v) { for (auto&amp; spot : spots) { if (spot.size == v-&gt;size &amp;&amp; !spot.isOccupied) { return &amp;spot; } } return nullptr; // No available spot found } }; class ParkingLot { public: vector<ParkingFloor> floors; // Vector to store multiple floors int totalFloors; int spotsPerFloor; ParkingLot(int totalFloors, int spotsPerFloor) : totalFloors(totalFloors), spotsPerFloor(spotsPerFloor) { // Initialize the parking lot with floors and spots for (int i = 0; i &lt; totalFloors; i++) { floors.push_back(ParkingFloor(i, spotsPerFloor)); // Create floors } } // Assign a parking spot to the vehicle across multiple floors void assignSpot(Vehicle* v) { for (auto&amp; floor : floors) { ParkingSpot* availableSpot = floor.findAvailableSpot(v); if (availableSpot != nullptr) { availableSpot-&gt;assignVehicle(v); cout &lt;&lt; &quot;Assigned vehicle &quot; &lt;&lt; v-&gt;licensePlate &lt;&lt; &quot; to spot &quot; &lt;&lt; availableSpot-&gt;identifier &lt;&lt; &quot; on floor &quot; &lt;&lt; availableSpot-&gt;floorNumber &lt;&lt; endl; return; } } cout &lt;&lt; &quot;No available spot for vehicle &quot; &lt;&lt; v-&gt;licensePlate &lt;&lt; endl; } // Release the parking spot occupied by the vehicle void releaseSpot(Vehicle* v) { for (auto&amp; floor : floors) { for (auto&amp; spot : floor.spots) { if (spot.v == v &amp;&amp; spot.isOccupied) { spot.removeVehicle(); cout &lt;&lt; &quot;Released spot &quot; &lt;&lt; spot.identifier &lt;&lt; &quot; on floor &quot; &lt;&lt; spot.floorNumber &lt;&lt; endl; return; } } } cout &lt;&lt; &quot;Vehicle &quot; &lt;&lt; v-&gt;licensePlate &lt;&lt; &quot; not found in the parking lot.&quot; &lt;&lt; endl; } }; int main() { // Create a parking lot with 3 floors, each with 5 spots ParkingLot lot(3, 5); // Create some vehicles Vehicle car1(&quot;ABC123&quot;, &quot;small&quot;); Vehicle car2(&quot;XYZ789&quot;, &quot;small&quot;); // Assign spots to vehicles lot.assignSpot(&amp;car1); lot.assignSpot(&amp;car2); // Release a spot lot.releaseSpot(&amp;car1); return 0; }




Adhere to SOLID Guidelines

Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...






Consider Scalability and Flexibility

Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...






Create/Explain your diagram(s)

Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...






Future improvements

Critically examine your design for any flaws or areas for future improvement...