1. Parking Lot System
Description
Design a system to manage a parking lot that supports multiple vehicle types and parking spot sizes. Each vehicle type occupies a different space size, and the lot must track available and occupied spots.
Class Design
Class: Vehicle (Abstract)
| Attribute | Type | Description |
|---|---|---|
plateNumber |
std::string |
Unique vehicle ID |
size |
VehicleSize |
Enum: SMALL, MEDIUM, LARGE |
Methods:
getPlateNumber() constβstd::stringgetSize() constβVehicleSize
Derived Classes:
Bike,Car,Truckβ each defines its size in the constructor.
Class: ParkingSpot
| Attribute | Type | Description |
|---|---|---|
size |
VehicleSize |
Max vehicle size it can hold |
vehicle |
Vehicle* |
Pointer to current parked vehicle |
Methods:
bool canFit(const Vehicle& v)β checks if a vehicle can fitbool park(Vehicle& v)β parks vehicle if possiblevoid removeVehicle()β frees the spotbool isOccupied() const
Class: ParkingLot
| Attribute | Type | Description |
|---|---|---|
spots |
std::vector<ParkingSpot> |
All parking spots in the lot |
Methods:
bool parkVehicle(Vehicle& v)β attempts to find and assign a spotvoid removeVehicle(const std::string& plate)β removes by plateint availableSpots() constβ returns count of free spots
Design Notes
- Inheritance for vehicle hierarchy (
Vehicle β Car/Bike/Truck) - Composition:
ParkingLothas manyParkingSpots - Encapsulation hides state and validation logic in each class
2. Online Shopping Cart System
Description
Model an online shopping cart where customers add items, view totals, and choose payment methods.
Class Design
Class: Product
| Attribute | Type | Description |
|---|---|---|
id |
int |
Product identifier |
name |
std::string |
Product name |
price |
double |
Unit price |
Methods:
getId() constgetName() constgetPrice() const
Class: CartItem
| Attribute | Type | Description |
|---|---|---|
product |
Product |
Product in the cart |
quantity |
int |
Quantity selected |
Methods:
getSubtotal() constβprice * quantityincreaseQuantity(int)decreaseQuantity(int)
Class: ShoppingCart
| Attribute | Type | Description |
|---|---|---|
items |
std::vector<CartItem> |
List of cart items |
Methods:
void addItem(const Product&, int quantity)void removeItem(int productId)double calculateTotal() constvoid clearCart()
Abstract Class: PaymentProcessor
| Method | Return | Description |
|---|---|---|
virtual void pay(double amount) = 0 |
β | Abstract payment interface |
Derived Classes:
CreditCardPaymentPayPalPaymentGiftCardPayment(optional)
Each implements pay(double amount) differently.
Design Notes
- Uses composition (
ShoppingCartβCartItems) - Uses polymorphism for different payment strategies
- Easily extensible with new payment types or discount logic
3. Library Management System
Description
Manage books, members, and borrowing transactions in a small library.
Class Design
Class: Book
| Attribute | Type | Description |
|---|---|---|
id |
int |
Book ID |
title |
std::string |
Title |
author |
std::string |
Author name |
isAvailable |
bool |
Availability flag |
Methods:
getTitle() constgetAuthor() constbool available() constvoid setAvailable(bool)
Class: Member
| Attribute | Type | Description |
|---|---|---|
name |
std::string |
Memberβs name |
borrowedBooks |
std::vector<Book*> |
List of borrowed books |
Methods:
bool borrow(Book&)void returnBook(Book&)int totalBorrowed() const
Class: Library
| Attribute | Type | Description |
|---|---|---|
books |
std::vector<Book> |
Catalog of books |
Methods:
void addBook(const Book&)std::vector<Book*> searchByTitle(const std::string&)void displayAvailableBooks() const
Design Notes
- Aggregation:
Memberholds references toBook(does not own them) - Encapsulation: borrow/return logic checks availability internally
- Could be extended to track due dates and fines
4. Chat Application
Description
Design a chat room system where users can join rooms, send messages, and view chat history.
Class Design
Class: User
| Attribute | Type | Description |
|---|---|---|
username |
std::string |
Userβs name |
status |
std::string |
Online/Offline |
Methods:
getName() constsetStatus(const std::string&)
Class: Message
| Attribute | Type | Description |
|---|---|---|
sender |
User |
Sender of the message |
content |
std::string |
Message text |
timestamp |
std::time_t |
Time sent |
Methods:
getFormattedTime() constgetText() constgetSender() const
Class: ChatRoom
| Attribute | Type | Description |
|---|---|---|
roomName |
std::string |
Room identifier |
users |
std::vector<User*> |
Active users |
messages |
std::vector<Message> |
Chat log |
Methods:
void join(User&)void leave(User&)void sendMessage(User&, const std::string&)void showChatHistory() const
Design Notes
- Association: Users belong to multiple ChatRooms
- Composition: ChatRoom contains its Messages
- Can evolve to support private messages, attachments, or timestamps per message
Youtube Mock Interview
- link(Interview is in Python)