All CoursesC++ Programming Course

Real-World Projects

Complete, production-style systems with full design documentation and implementation.

Homestay Management System

šŸ“‹ Features

• Room booking (Single, Double, Suite) with guest details and night count

• Hall booking (Ballroom, Conference, Meeting) with hourly pricing

• Food ordering from a preset menu (breakfast, lunch items)

• Customer records — view all rooms, halls, and orders

• Automated billing with tax calculation (10%)

šŸ’» Full Implementation

homestay_system.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;

// ========== ROOM CLASS ==========
class Room {
    int roomNo;
    string type; // Single, Double, Suite
    double pricePerNight;
    bool isBooked;
    string guestName;
    int nights;
public:
    Room(int no, string t, double price)
        : roomNo(no), type(t), pricePerNight(price), isBooked(false), guestName(""), nights(0) {}
    
    int getRoomNo() const { return roomNo; }
    bool getBooked() const { return isBooked; }
    double getTotal() const { return pricePerNight * nights; }
    string getGuest() const { return guestName; }
    
    void book(string guest, int n) {
        isBooked = true;
        guestName = guest;
        nights = n;
        cout << "Room " << roomNo << " (" << type << ") booked for " 
             << guest << " — " << n << " nights" << endl;
    }
    
    void checkout() {
        cout << "Room " << roomNo << " checked out. Total: $" << fixed << setprecision(2) << getTotal() << endl;
        isBooked = false;
        guestName = "";
        nights = 0;
    }
    
    void display() const {
        cout << "Room " << roomNo << " | " << type << " | $" << pricePerNight << "/night | "
             << (isBooked ? "BOOKED (" + guestName + ", " + to_string(nights) + " nights)" : "AVAILABLE") << endl;
    }
};

// ========== HALL CLASS ==========
class Hall {
    string name;
    int capacity;
    double pricePerHour;
    bool isBooked;
    string bookedBy;
    int hours;
public:
    Hall(string n, int cap, double price)
        : name(n), capacity(cap), pricePerHour(price), isBooked(false), bookedBy(""), hours(0) {}
    
    string getName() const { return name; }
    bool getBooked() const { return isBooked; }
    double getTotal() const { return pricePerHour * hours; }
    
    void book(string client, int h) {
        isBooked = true;
        bookedBy = client;
        hours = h;
        cout << name << " booked for " << client << " — " << h << " hours" << endl;
    }
    
    void release() {
        cout << name << " released. Total: $" << fixed << setprecision(2) << getTotal() << endl;
        isBooked = false;
        bookedBy = "";
        hours = 0;
    }
    
    void display() const {
        cout << name << " | Capacity: " << capacity << " | $" << pricePerHour << "/hr | "
             << (isBooked ? "BOOKED (" + bookedBy + ")" : "AVAILABLE") << endl;
    }
};

// ========== FOOD ORDER ==========
struct FoodItem {
    string name;
    double price;
};

class FoodOrder {
    string guestName;
    vector<pair<FoodItem, int>> items; // item, quantity
public:
    FoodOrder(string guest) : guestName(guest) {}
    
    void addItem(FoodItem item, int qty) {
        items.push_back({item, qty});
    }
    
    double getTotal() const {
        double total = 0;
        for (const auto& p : items) total += p.first.price * p.second;
        return total;
    }
    
    void display() const {
        cout << "\nFood Order for " << guestName << ":" << endl;
        for (const auto& p : items) {
            cout << "  " << p.first.name << " x" << p.second 
                 << " = $" << fixed << setprecision(2) << p.first.price * p.second << endl;
        }
        cout << "  TOTAL: $" << fixed << setprecision(2) << getTotal() << endl;
    }
};

// ========== HOMESTAY SYSTEM ==========
class HomestaySystem {
    vector<Room> rooms;
    vector<Hall> halls;
    vector<FoodOrder> foodOrders;
    
    vector<FoodItem> menu = {
        {"Continental Breakfast", 15.00},
        {"Full English Breakfast", 22.00},
        {"Lunch Buffet", 35.00},
        {"Dinner Set Menu", 45.00},
        {"Snack Platter", 18.00},
        {"Coffee & Tea", 5.00}
    };

public:
    HomestaySystem() {
        // Initialize rooms
        rooms.push_back(Room(101, "Single", 80.00));
        rooms.push_back(Room(102, "Single", 80.00));
        rooms.push_back(Room(201, "Double", 120.00));
        rooms.push_back(Room(202, "Double", 120.00));
        rooms.push_back(Room(301, "Suite", 200.00));
        
        // Initialize halls
        halls.push_back(Hall("Grand Ballroom", 200, 150.00));
        halls.push_back(Hall("Conference Room A", 50, 75.00));
        halls.push_back(Hall("Meeting Room B", 20, 40.00));
    }
    
    void bookRoom() {
        cout << "\n--- Available Rooms ---" << endl;
        bool hasAvailable = false;
        for (const auto& r : rooms) {
            if (!r.getBooked()) { r.display(); hasAvailable = true; }
        }
        if (!hasAvailable) { cout << "No rooms available!" << endl; return; }
        
        int roomNo, nights;
        string guest;
        cout << "Enter room number: ";
        cin >> roomNo;
        cout << "Guest name: ";
        cin.ignore(); getline(cin, guest);
        cout << "Number of nights: ";
        cin >> nights;
        
        for (auto& r : rooms) {
            if (r.getRoomNo() == roomNo && !r.getBooked()) {
                r.book(guest, nights);
                return;
            }
        }
        cout << "Room not available!" << endl;
    }
    
    void bookHall() {
        cout << "\n--- Available Halls ---" << endl;
        for (const auto& h : halls) {
            if (!h.getBooked()) h.display();
        }
        
        string hallName, client;
        int hours;
        cout << "Enter hall name: ";
        cin.ignore(); getline(cin, hallName);
        cout << "Client name: ";
        getline(cin, client);
        cout << "Hours: ";
        cin >> hours;
        
        for (auto& h : halls) {
            if (h.getName() == hallName && !h.getBooked()) {
                h.book(client, hours);
                return;
            }
        }
        cout << "Hall not available!" << endl;
    }
    
    void orderFood() {
        string guest;
        cout << "Guest name: ";
        cin.ignore(); getline(cin, guest);
        
        FoodOrder order(guest);
        
        cout << "\n--- MENU ---" << endl;
        for (int i = 0; i < menu.size(); i++) {
            cout << i + 1 << ". " << menu[i].name << " — $" << menu[i].price << endl;
        }
        
        int itemChoice;
        do {
            cout << "Select item (0 to finish): ";
            cin >> itemChoice;
            if (itemChoice >= 1 && itemChoice <= (int)menu.size()) {
                int qty;
                cout << "Quantity: ";
                cin >> qty;
                order.addItem(menu[itemChoice - 1], qty);
            }
        } while (itemChoice != 0);
        
        foodOrders.push_back(order);
        order.display();
    }
    
    void viewRecords() {
        cout << "\n========== HOMESTAY RECORDS ==========" << endl;
        cout << "\n--- ROOMS ---" << endl;
        for (const auto& r : rooms) r.display();
        cout << "\n--- HALLS ---" << endl;
        for (const auto& h : halls) h.display();
        cout << "\n--- FOOD ORDERS: " << foodOrders.size() << " ---" << endl;
        for (const auto& f : foodOrders) f.display();
    }
    
    void generateBill() {
        string guest;
        cout << "Guest name for billing: ";
        cin.ignore(); getline(cin, guest);
        
        double total = 0;
        cout << "\n============ BILL ============" << endl;
        cout << "Guest: " << guest << endl;
        cout << "------------------------------" << endl;
        
        for (auto& r : rooms) {
            if (r.getBooked() && r.getGuest() == guest) {
                cout << "Room " << r.getRoomNo() << ": $" << fixed << setprecision(2) << r.getTotal() << endl;
                total += r.getTotal();
            }
        }
        
        for (const auto& f : foodOrders) {
            total += f.getTotal();
        }
        
        cout << "------------------------------" << endl;
        cout << "Subtotal: $" << fixed << setprecision(2) << total << endl;
        double tax = total * 0.10;
        cout << "Tax (10%): $" << fixed << setprecision(2) << tax << endl;
        cout << "TOTAL: $" << fixed << setprecision(2) << total + tax << endl;
        cout << "==============================" << endl;
    }
    
    void run() {
        int choice;
        do {
            cout << "\n===== HOMESTAY MANAGEMENT SYSTEM =====" << endl;
            cout << "1. Book Room" << endl;
            cout << "2. Book Hall" << endl;
            cout << "3. Order Food" << endl;
            cout << "4. View All Records" << endl;
            cout << "5. Generate Bill" << endl;
            cout << "6. Exit" << endl;
            cout << "Choice: ";
            cin >> choice;
            
            switch (choice) {
                case 1: bookRoom(); break;
                case 2: bookHall(); break;
                case 3: orderFood(); break;
                case 4: viewRecords(); break;
                case 5: generateBill(); break;
                case 6: cout << "Thank you! Goodbye." << endl; break;
                default: cout << "Invalid choice!" << endl;
            }
        } while (choice != 6);
    }
};

int main() {
    HomestaySystem system;
    system.run();
    return 0;
}