Develop a hotel reservation system to allow customers to book rooms and control demand for hotel owners. Your program should handle the following events:
BOOK time hotel_name client_id room_count — Book by the client with ID client_id a certain number of rooms (room_count) at the hotel named hotel_name at the specified time (time). Time is measured in seconds from a certain moment.
CLIENTS hotel_name — Display the count of different clients who have booked rooms at the hotel named hotel_name in the last 24 hours. More formally, the time range of interest is described as follows: let current_time be the time of the last BOOK event. In this query, consider all events with current_time - 86400 < time ⩽ current_time, where 86400 is the number of seconds in a day. Note that the last booking should be considered, and a booking exactly 24 hours prior to it should not be included.
ROOMS hotel_name — Display the count of rooms booked in the last 24 hours at the hotel named hotel_name.
In my first version I came up with the following approach:
#include #include #include #include #include #include #include #include using namespace std; class HotelManagement { public: HotelManagement() : hotel_rooms(), hotel_time(){} void Book (int &time, string &hotel_name, int &client_id, int &room_count){ hotel_rooms[hotel_name].push_back(room_count); hotel_time[hotel_name].push_back(time); for (auto &pair : hotel_time){ while(hotel_time.at(pair.first).front()
Develop a hotel reservation system to allow customers to book rooms and control demand for hotel owners. Your program should handle the following events: [list] [*][b]BOOK time hotel_name client_id room_count[/b] — Book by the client with ID client_id a certain number of rooms (room_count) at the hotel named hotel_name at the specified time (time). Time is measured in seconds from a certain moment. [*][b]CLIENTS hotel_name[/b] — Display the count of different clients who have booked rooms at the hotel named hotel_name in the last 24 hours. More formally, the time range of interest is described as follows: let current_time be the time of the last BOOK event. In this query, consider all events with current_time - 86400 < time ⩽ current_time, where 86400 is the number of seconds in a day. Note that the last booking should be considered, and a booking exactly 24 hours prior to it should not be included. [*][b]ROOMS hotel_name[/b] — Display the count of rooms booked in the last 24 hours at the hotel named hotel_name. [/list] In my first version I came up with the following approach:
#include #include #include #include #include #include #include #include using namespace std; class HotelManagement { public: HotelManagement() : hotel_rooms(), hotel_time(){} void Book (int &time, string &hotel_name, int &client_id, int &room_count){ hotel_rooms[hotel_name].push_back(room_count); hotel_time[hotel_name].push_back(time); for (auto &pair : hotel_time){ while(hotel_time.at(pair.first).front()