Write Python functions to implement a room booking system.

Thu, 28 Mar 2024 18:00

Write Python functions to implement a room booking system.

Background

In many large organizations (including this one!), there are many rooms that are used by many people at many times. There needs to be a way of scheduling access to these rooms, or else I’ll never know whether my classroom will be free when I go there to teach!

Electronic room booking systems (e.g., https://www.engr.mun.ca/bookings) allow events to be scheduled by people in specific rooms. You will implement some Python code to implement such a system.

Requirements

You will create a Python module containing functions that implement the following contracts:

def add_room(room_number, capacity, classroom=False):
    """Add a room to the booking system.

    Parameters
    ----------
    room_number : str
        An identifier for the room, e.g., "EN2043".

    capacity : int
        The number of people who can use a room at a time.

    classroom : bool
        Whether or not the room is equipped for teaching purposes
        (microphone, lecture capture, etc.).
    """

def book_event(room_number, event_name, day, start_time, length, people, teaching=False):
    """Book an event on someone's behalf.

    If the room exists, has the capacity for the event and has not yet been
    booked for the given time, the booking will be created and recorded.
    If any of these conditions are not met, no booking is made.

    Parameters
    ----------
    room_number : str
        An identifier for the room, e.g., "EN2043".

    event_name : str
        The event being booked

    day : int (1–31)
        What day of the month the event will happen on.
        (note: a real system would allow booking in other months too)

    start_time : int (0–23)
        The hour of the day that the event will start at.
        (note: a real system would allow, e.g., 10:30, but we'll stick to hours)

    length : int
        How long the event will be, in hours.
        (note: a real system would allow fractional hours)

    people : int
        How many people will attend the event (i.e., required capacity).

    teaching : bool
        Is this a class (which requires teaching equipment in the room)?

    Returns
    -------
    True if the booking was created, False if it was not (for any reason)
    """

def event_info(room_number, day, hour):
    """Describe the event that is booked for a given hour on a given day.

    Precondition: the specified room exists

    Parameters
    ----------
    room_number : str
        An identifier for the room, e.g., "EN2043".

    day : int (1–31)
        What day of the month the event will happen on.
        (note: a real system would allow booking in other months too)

    time : int (0–23)
        The hour of the day being queried (0–23).

    Returns
    -------
    If an event has been booked at the specified hour on the specified day,
    returns a tuple of (event_name, day, start_time, length, people, teaching).

    If no event has been booked at the specified time, returns None.
    """

Note that, in order to keep track of the existing rooms and bookings, this will be one of the very few times in which global variables are recommended. In later programming courses, you’ll learn about how to create classes for object-oriented programming, and you won’t need global variables like this any more. For now, however, with what we’ve learned in ENGI 1020, you will.

You should not need any external modules for this assignment. In fact, you may not import any external modules.

Define these three functions in a file called bookings.py and submit to Gradescope. As always, please don’t hesitate to contact me if you have questions! Also as always, remember that assignments are individual work.