For these kind of problems - first define all the entities in the ecosystem for this application and the assumptions you are going to make.
Define the problem -
- In a restaurant, there are multiple tables with varying seating capacities.
- A table of a seating capacity of n can be booked for m people of a group such that m <= n
- A table can be re-booked for the same day only if the there is a minimum T duration difference between 2 bookings.
- Booking can be done in fixed hours when the restaurant operates.
- Number of people [input]
- Time of booking required [input]
- Contact details [input (optional)]
- int CheckTableAvailability(int NumPeople, time_t TimeOfBooking, int *tableNumber, time_t *alternativeTime) - This function will tell whether the booking is possible or not. If possible on the input time it will return 1 and file the tableNumber. If not on the input time, but at some time near to that, it will return 2 with the alternativeTime and TableNumber that can be booked. If not at all possible then it will return 0.
- bookTable(contactDetails, tableNumber, time_t TimeOfBooking)
for CheckTableAvailability , it can also return an array of tableNumber possible for booking. Like some restaurants have different sections (smoking zone, pool side, garden side etc) which will give the customer a choice to make.
Class: Table
{
int TableId;
int SeatingCapacity;
string speciality;
}
Class Booking
{
int bookingId;
int TableId;
time_t startTime;
customerDetails;
}
Class: BookedTables
{
HashTable bookings ( key: timeslot, value: int booked[NumTables] )