0% found this document useful (0 votes)
15 views20 pages

Hotel Management System: Project For Opps

Presentation

Uploaded by

Bhavya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views20 pages

Hotel Management System: Project For Opps

Presentation

Uploaded by

Bhavya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Project for opps


Hotel
Management
System
 Submitted to Sarabjit sir

By. Ravina Mittal

Aanshi

Bhavya

▪ This example of a hotel management system in C++ demonstrates how object-oriented programming
principles can be used to manage complex tasks. By encapsulating room properties and behaviors within the
`Room` class and managing these rooms within the `Hotel` class, the code achieves a modular and
maintainable structure. Key operations like checking in and out guests, and displaying room statuses, are
implemented as methods, making the system easy to understand and extend.

▪ ### Key Takeaways:

▪ 1. **Object-Oriented Design:** Using classes to represent entities like `Room` and `Hotel` encapsulates data
and behavior, enhancing code organization and readability.

▪ 2. **Data Management:** The use of a vector to store `Room` objects allows dynamic management of room
information.

▪ 3. **User Interaction:** A simple menu-driven interface facilitates interaction, demonstrating basic input
handling and control structures in C++.

▪ 4. **Scalability:** The design can be easily expanded to include more features, such as handling
reservations, managing different room types, and integrating a billing system.

▪ This basic implementation provides a solid foundation for a more comprehensive hotel management system,
showcasing how fundamental programming concepts can be applied to solve real-world problems effectively.

▪ ### 1. **Class `Room`**

▪ The `Room` class represents a single hotel room.

▪ ```cpp

▪ class Room {

▪ public:

▪ int roomNumber; // Unique identifier for the room

▪ bool isOccupied; // Flag to check if the room is occupied

▪ std::string guestName; // Name of the guest currently in the room


▪ Constructor to initialize a room with a room number, defaulting to unoccupied

▪ Room(int number) : roomNumber(number), isOccupied(false), guestName(“”) {}

▪ };

▪ ```

▪ - **Members:**

▪ - `roomNumber`: An integer representing the room number.

▪ - `isOccupied`: A boolean indicating whether the room is currently occupied.

▪ - `guestName`: A string storing the name of the guest if the room is occupied.

▪ - **Constructor:**

▪ - Initializes `roomNumber` w ith the provided number.

▪ - Sets `isOccupied` to `false` and `guestName` to an empty string.

▪ ### 2. **Class `Hotel`**

▪ The `Hotel` class manages a collection of `Room` objects.

▪ ```cpp

▪ class Hotel {

▪ private:

▪ std::vector<Room> rooms; //

▪ A vector of Room objects

▪ public:

▪ // Constructor to initialize the hotel with a specified number of rooms

▪ Hotel(int numberOfRooms) {

▪ for (int i = 1; i <= numberOfRooms; ++i) {

▪ rooms.emplace_back(i);

▪ }

▪ }

▪ Function to check in a guest to a specific room

▪ void checkIn(int roomNumber, const std::string& guestName)


{

▪ if (roomNumber <= 0 || roomNumber > rooms.size()) {


▪ Std::cout << “Invalid room number.\n”;

▪ return;

▪ }

▪ Room &room = rooms[roomNumber – 1];

▪ if (room.isOccupied) {

▪ std::cout << “Room is already occupied.\n”;

▪ } else {

▪ room.isOccupied = true;

▪ Room.guestName = guestName;

▪ std::cout << “Guest “ << guestName << “ checked into


room “ << roomNumber << “.\n”;

▪ }

▪ }


▪ Function to check out a guest from a specific room

▪ void checkOut(int roomNumber) {

▪ if (roomNumber <= 0 || roomNumber > rooms.size()) {std::cout << “Invalid room number.\n”;

▪ return;

▪ }

▪ Room &room = rooms[roomNumber – 1];

▪ if (!room.isOccupied) {

▪ std::cout << “Room is already vacant.\n”;

▪ } else {

▪ std::cout << “Guest “ << room.guestName << “ checked out from room “ << roomNumber << “.\n”;

▪ room.isOccupied = false;

▪ room.guestName = “”;

▪ }

▪ }

▪ Function to display the status of all rooms

▪ void displayStatus() {

▪ for (const auto &room : rooms) {

▪ std::cout << “Room “ << room.roomNumber << “: “

▪ << (room.isOccupied ? “Occupied by “ + room.guestName : “Vacant”) << “\n”;

▪ }

▪ }

▪ };

▪ ```

▪ - **Members:**

▪ - `rooms`: A vector of `Room` objects, each representing a hotel room.

▪ - **Constructor:**

▪ - Initializes the hotel w ith a specified number of rooms by creating `Room` objects w ith room numbers from 1 to `numberOfRooms `.

▪ - **Methods:**

▪ - `checkIn(int roomNumber, const std::string& guestName)`: Checks a guest into a specified room if the room is not already occ upied. If the room is occupied or
the room number is invalid, it prints an error message.

▪ - `checkOut(int roomNumber)`: Checks a guest out of a specified room if the room is occupied. If the room is vacant or the room number is invalid, it prints an
error message.

▪ - `displayStatus()`: Displays the occupancy status of all rooms, show ing either the guest name for occupied rooms or “Vacant” for empty rooms.

▪ ### 3. **Main Function**

▪ The `main` f unction prov ides the user interf ace to interact with the hotel management sy stem.

▪ ```cpp

▪ int main() {

▪ int numberOf Rooms;

▪ std::cout << “Enter the number of rooms in the hotel: “;

▪ std::cin >> numberOf Rooms;

▪ Hotel hotel(numberOf Rooms); // Create a hotel with the specif ied number of rooms

▪ int choice, roomNumber;

▪ std::string guestName;

▪ While (true) {

▪ std::cout << “\n1. Check In\n2. Check Out\n3. Display Status\n4. Exit\nEnter your choice: “;

▪ std::cin >> choice;

▪ switch (choice) {

▪ case 1:

▪ std::cout << “Enter room number: “;

▪ std::cin >> roomNumber;

▪ std::cin.ignore(); // Ignore newline character left in the buffer

▪ std::cout << “Enter guest name: “;

▪ std::getline(std::cin, guestName);

▪ Hotel.checkIn(roomNumber, guestName);

▪ break;

▪ case 2:

▪ std::cout << “Enter room number: “;

▪ std::cin >> roomNumber;

▪ hotel.checkOut(roomNumber);

▪ break;

▪ case 3:

▪ hotel.display Status();

▪ break;

▪ case 4:

▪ std::cout << “Exiting...\n”;

▪ return 0;

▪ Default:

▪ std::cout << “Invalid choice. Please try again.\n”;

▪ break;

▪ }

▪ }

▪ }

▪ ```

▪ - **Variables:**

▪ - `numberOfRooms`: The number of rooms in the hotel, input by the user.

▪ - `choice`: The user’s menu choice.

▪ - `roomNumber`: The room number for check-in or check-out operations.


▪ - `guestName`: The name of the guest for check-in.

▪ - **Flow :**

▪ - The program starts by asking the user for the number of rooms in the hotel.

▪ - It then creates a `Hotel` object w ith the specified number of rooms.

▪ - The program enters an infinite loop w here it displays a menu and processes the user’s choice:

▪ - `1`: Check in a guest by prompting for the room number and guest name.

▪ - `2`: Check out a guest by prompting for the room number.

▪ - `3`: Display the current status of all rooms.

▪ - `4`: Exit the program.

▪ This implementation provides a basic framew ork for managing a hotel’s room occupancy. It can be expanded w ith additional

▪ Reservations, managing billing, and more sophisticated error


handling.

▪ Thank you

You might also like