Help with reservation program.

I've been given an assignment to design a hotel reservation system.
The problem I have is I'm not even sure what method to use to actually reserve the room for specific dates.

Right now, I've drawn a floorplan for each floor using for loops and arrays and I can easily make the program work by changing the booked rooms to null.

But I have no idea how to book rooms for a period of time only.

Can anyone suggest a better method of things?
You don't give any indication how simple or complex this reservation system needs to be.

The easiest way is to not think about the reservation system in terms of specific rooms, only with regard to the total number of room you have.

Simply create an array for the period of time for which you will accept reservations (perhaps 1 year). Initialize each cell of the array to the number of rooms you have. Each time you want to reserve a room, check the cell for the desired days is non-zero. If any of the cells are zero, you're fully booked on that day and can't accept the reservation. Assuming you can accept the reservation, then decrement the counter for each day of the reservation.

Keep in mind that each day you need to adjust your array to drop off yesterday's reservations and allow for a reservation 365 days from today.

If your reservation system needs to keep track of who booked the reservation, needs to be able to find a specific reservation, or needs to book a specific room (presidential suite), then the problem is more complicated.
closed account (o3hC5Di1)
Hi there,

Interesting assignment.
Are you allowed to use STL containers for this, or does it have to be regular arrays?

Just of the top of my head, using regular arrays:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
struct reservation_period
{
    std::time_t checkin_time;
    std::time_t checkout_time;

    //Edit: using std::tm might be more convenient asit will allow you to make checks based on dates easier
}

enum class room_type { single, double, twin, suite }
struct room
{
    //this array holds reservations for this room
    reservation_period reservations[100];
    //max people in the room
    unsigned int max_occupants;
    //single, double, twin, suite
    room_type type;
    //is the room ensuite or not?
    bool ensuite;
    //roomnumber
    int number;
}

//then you can have an array of rooms:
room room_arr[300];


When someone wants to reserve a room, you just iterate the array and find a room that does not have a reservation_period colliding with the requested time. You can easily do this checking whether the requested checkin date is later than the reserved checkout date, or if it's earlier than the reserved checkin date, if the requested checkout date is sooner than the reserved checkin date.

I don't see a requirement to draw out a floor plan, in fact if you don't do this, youre program will work for every hotel, not just one specific one. It's just a matter of filling up the rooms_arr with the rooms that apply to the hotel.

Hope that makes sense.
Please do let us know if you have any further questions.

All the best,
NwN
Last edited on
I am sorry for not being specific enough.

I need to be able to display, add and delete records from manager view.

I can use any method to do this program but I chose arrays because I thought it was a good idea at the time. You guys should know that I am fairly new to c++ so I am very much still a beginner so I am not even sure what STL containers are but I am looking them up now
closed account (o3hC5Di1)
The STL containers provide safe alternatives to regular arrays.
For example, a std::vector will allow you to dynamically resize it (add or remove from it), which regular arrays don't do.

Is this a GUI application, or does it run in the console?

All the best,
NwN
NwN, sorry just didnt know the terminology, but yes we are allowed to use containers
closed account (o3hC5Di1)
In that case, it's probably best to use either a std::vector for storing the room-objects.
Unless, for some reason you would want roomnumbers like "101" for the first floor, "201" for the second floor, and you would want to access rooms immediately by their number, then you probably want to use a std::unordered_map.

To elaborate on my example above, the benefit is that by creating a room-struct, you are defining a blueprint of what a room is. You can then create an arbitrary number of actual room-objects, so it could work for any type of hotel. For instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//create a room
room r1;
r1.max_occupants = 2;
r1.type = room_type::double;
r1.ensuite = true;

//or simplify it by creating a constructor for room:
room r2(3, room_type::suite, false);

//vector storing room objects
std::vector<room> room_container;
room_container.push_back(r1);
room_container.push_back(r2);

//now you can iterate the vector and check which room is available 


Perhaps you can try and work with that idea and get back to us with the code you have come up with, we'd be happy to help you further along.
Let us know if you have any further questions.

All the best,
NwN
Topic archived. No new replies allowed.