SaeedGHF / HMS

Hotel management system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hotel management system

Keywords: computer networks, socket programming, c++

Project structure

  • DateHandler
  • FileHandler
  • JsonHandler
  • User
  • Room

DateHandler

This is a C++ class named "DateHandler" that provides static methods for handling and manipulating dates.

The class includes the following methods:

  1. verifyDateFormat: This method takes a string as input and verifies whether it is in a valid date format. It returns a boolean value true if the date format is valid, otherwise false.

  2. addDaysToDate: This method takes a string representing a date and an integer representing the number of days to add to it. It returns a string representing the new date after adding the specified number of days.

  3. getDatesBetween: This method takes two strings representing start and end dates, and returns a vector of strings representing all the dates between the start and end dates (inclusive).

  4. isDateBetween: This method takes three strings representing start, end, and check dates, and checks whether the check date is between the start and end dates. It returns a boolean value true if the check date is between the start and end dates, otherwise false.

The class requires the inclusion of four header files: string, vector, sstream, and iomanip.

FileHandler

This is a C++ class named "FileHandler" that provides static methods for reading and writing JSON files.

The class includes the following methods:

  1. readContents: This method takes a string representing the file name and reads the contents of the specified file. It returns a string representing the contents of the file in JSON format.

  2. writeContents: This method takes a string representing the file name and a Json::Value object representing the contents to be written to the file. It writes the contents to the specified file in JSON format.

  3. writeLog: This method takes a string message as its argument and appends it to the log file, along with the current date and time.

The class requires the inclusion of three header files: string, fstream, and json/json.h.

JsonHandler

This is a C++ class named "JsonHandler" that provides a static method for parsing JSON data.

The class includes the following method:

  1. parseJSON: This method takes a string representing the JSON data and parses it into a Json::Value object. The parsed object can then be used to access the JSON data in a structured way.

The class requires the inclusion of three header files: iostream, string, and json/json.h.

User

This is a C++ header file named "User" that defines a class for handling user data.

The class includes the following private variables:

  1. instance: A static instance of the class.

  2. fileName: A string representing the file name where user data is stored.

  3. users: A Json::Value object representing the user data.

The class includes the following private methods:

  1. User: A private constructor for creating an instance of the class.

  2. getUsers: A method for reading user data from the file using FileHandler and JsonHandler classes.

  3. setUsers: A method for writing user data to the file using FileHandler and JsonHandler classes.

The class includes the following public methods:

  1. getInstance: A static method for getting an instance of the class.

  2. printUsers: A method for printing all the user data.

  3. updateUser: A method for updating an existing user data.

  4. findUserIndexById: A method for finding the index of a user by their ID.

  5. findUserById: A method for finding a user by their ID.

  6. verifyLogin: A method for verifying a user's login credentials.

  7. getUserAsString: A method for getting a string representation of a single user.

  8. getAllUsersAsString: A method for getting a string representation of all the user data.

The class requires the inclusion of five header files: iostream, string, json/json.h, FileHandler.h, and JsonHandler.h.

Room

This is a C++ header file named "Room" that defines a class for handling room data.

The class includes the following private variables:

  1. instance: A static instance of the class.

  2. fileName: A string representing the file name where room data is stored.

  3. rooms: A Json::Value object representing the room data.

The class includes the following private methods:

  1. Room: A private constructor for creating an instance of the class.

  2. getRooms: A method for reading room data from the file using FileHandler and JsonHandler classes.

  3. setRooms: A method for writing room data to the file using FileHandler and JsonHandler classes.

The class includes the following public methods:

  1. getInstance: A static method for getting an instance of the class.

  2. findRoomIndexByNumber: A method for finding the index of a room by its number.

  3. findRoomByNumber: A method for finding a room by its number.

  4. updateRoom: A method for updating an existing room data.

  5. getAllRoomsAsString: A method for getting a string representation of all the room data.

  6. add: A method for adding a new room.

  7. modify: A method for modifying an existing room.

  8. remove: A method for removing a room.

  9. reserve: A method for reserving a room for a user.

  10. cancel: A method for canceling a room reservation for a user.

  11. leave: A method for checking out of a room.

  12. updateCapacity: A method for updating the capacity and status of each room based on the reservations for that date.

The class requires the inclusion of six header files: iostream, string, json/json.h, FileHandler.h, User.h, DateHandler.h, and JsonHandler.h.

Server

In server.cpp, we create a server socket, bind it to a port, and listen for incoming connections. Instead of using threads to handle each client, we use select() to monitor multiple file descriptors (i.e., sockets) for activity.

We start by initializing a fd_set called master_socket and adding the server socket to it using FD_SET(). We also initialize max_sd to the server socket's file descriptor.

In the main loop, we first create a copy of master_socket called readfds and call select() to wait for any of the file descriptors to become ready for reading. If select() returns -1, it means there was an error, so we exit.

Next, we iterate through all the file descriptors from 0 to max_sd. If a file descriptor is ready for reading ( i.e., it's in readfds), we check if it's the server socket. If it is, we accept the new connection and add the new client socket to master_socket and update max_sd if needed. If it's not the server socket, we receive the data from the client using recv() and handle it accordingly. If recv() returns -1, it means there was an error, so we close the client socket and remove it from master_socket using FD_CLR().

By using select(), we can monitor multiple sockets without having to create threads for each client. This can be more efficient if we have a large number of clients connected to the server.

Client

In client.cpp, we create a client socket using socket() function with AF_INET and SOCK_STREAM as arguments. We then connect to the server using connect() function and the server's IP address and port number.

We then enter a loop where we prompt the user to enter a message to send to the server. If the user enters "q", we break out of the loop and exit the program. Otherwise, we send the message to the server using send() function.

We then wait for a response from the server using recv() function. If recv() returns -1, it means there was an error, so we exit the loop and close the client socket. If recv() returns 0, it means the server has disconnected, so we exit the loop and close the client socket. Otherwise, we print the server's response to the console.

About

Hotel management system


Languages

Language:C++ 99.5%Language:Makefile 0.5%