Inputs have the documented types. Times, capacities, seat requests, and counts are integers. Room and booking IDs are case-sensitive strings. Each returned list/value record must be a detached snapshot, and instances must be independent. Time is an abstract coordinate; no clock, time zones, recurrence, or elapsed-time cleanup is used.
Prototype: implement RoomCalendar():
reserve():start >= 0andend > startare required, otherwise raisestd::invalid_argumentunchanged. Intervals are half-open. Returnfalseon any overlap, otherwise append the interval and returntrue.slots(): return all accepted intervals sorted by start then end, as a fresh list. Repeating the same reservation overlaps and returnsfalse.
Final: implement MeetingRoomBooking(rooms), where rooms is a value record the fields declared in the value record below. Copy the value record. Empty catalogs are allowed; an empty room ID or capacity below 1 raises std::invalid_argument.
book(): require nonempty booking ID,start >= 0,end > start,seats >= 1, androom_count >= 1; otherwise raisestd::invalid_argumentbefore any other check. Each selected room must independently hold at leastseatspeople. Choose exactlyroom_countavailable rooms by(capacity, room_id)ascending. Return their IDs in that order and commit them together. If too few rooms qualify, returnnulloptwithout reserving anything or consuming the ID.- A successfully used booking ID remains reserved for the instance's lifetime, including after cancellation. Repeating
bookwith that ID returnsnullopt, even if arguments match; validation still happens first. A failed request's ID may be retried. cancel(): cancel all assignments for one active booking and returntrue. Missing or already cancelled bookings returnfalsewithout changing other bookings.allocation(): return a fresh list of room IDs in the original selection order for an active booking. Missing or cancelled bookings returnnullopt.schedule(): unknown room raisesstd::invalid_argument. Return active reservations for that room sorted by(start, end, id)ascending. Each entry has exactly the fields declared in the value record below. A multi-room booking appears once in each assigned room's schedule.
Invalid and unsuccessful requests preserve all schedules and existing allocations.
The public C++ API below is authoritative for field types and return values. erase is used where another language might use a method named delete, because delete is a C++ keyword. Returned records are value snapshots with the documented named fields; mutating a record or its nested vectors cannot affect the service.
struct Reservation {std::string id;Int start,end,seats;bool operator==(const Reservation&)const=default;};
class RoomCalendar { public:
RoomCalendar();
bool reserve(Int start,Int end);
Vec<Pair> slots() const;
};
class MeetingRoomBooking { public:
explicit MeetingRoomBooking(std::map<std::string,Int> rooms);
Opt<Strings> book(const std::string& id,Int start,Int end,Int seats,Int room_count=1);
bool cancel(const std::string& id);
Opt<Strings> allocation(const std::string& id) const;
Vec<Reservation> schedule(const std::string& room) const;
};Compile and run from this directory:
c++ -std=c++20 -O2 -Wall -Wextra -pedantic -pthread main.cpp -o practice
./practice --stage prototype
./practice --stage finalEdit exercise.hpp. Both stages start unfinished and must report failures until implemented. Keep main.cpp as the executable contract. The runner returns nonzero for a failed check, an unexpected exception, an invalid stage, or an empty suite. C++20 and only the standard library are required.
Complete the starter code, then run the checks.
Results and errors will appear here.
C++ runtime powered by Wasmer.