Booking system for a hotel

I am trying to create a ms-dos hotel booking system for college.
It is just an exercise.

I need to mimic checking for room availability. If a certain room is booked for a certain date I need to know.
I am having trouble thinking of the best way to cross reference dates and rooms.

A 4d array? month, date, floor, room?
Seems like the array will get really big

Is this a reasonable solution or should I structure it differently...

There will be 50 or so rooms in total
A array is not what you need I think. Certainly not a "4d" one. In console arrays go up to 3 dimensions. a 2d array would get you a grid, adding a 3rd gets you depth and would be used for 3d games or such.

sounds like using a class might be better

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Room{

public:
    
// not going to write them for you, but here you would use access-er methods like:

int getMonth();
int setMonth(int month);

// etc

private:

int itsMonth;
int itsDate;
int itsFloor;
int itsNumber; // room number


}


You of course would also need to define the functions. Anyways, using this method you could then make an array of rooms.

the other way is to use a Initializer List

1
2
3
public:
  Room( int itsMonth, int itsDate, int itsFloor, itsNumber):
   itsMonth(month), itsDate(date), etc etc


and then declare your room like:

Room bestSuite(3,5,2,123) which would make a room called bestSuite and set its Month to 3, date to 5, floor to 2, and number to 123

then in your program you would have to check if it was free:
1
2
3
4
if (bestSuite(month = 3)){
roomIsFree = false;
cout << "Room is taken";
}



Obviously none of that code is complete or even fully correct but those are the type of concepts you would use.
I agree entirely with Blitz. Room is a perfect candidate for a class :).
Glad you think I was right, that was just seemed to be the best candidate to me. Now, accessing the class and getting it to do what you want is a whole other game...
Although in this case I see no reason why the members should be private, just go ahead and make them public.
Just good coding practice in general. For this it probably does not matter but good to get into the habit of doing this the "correct" way.
Topic archived. No new replies allowed.