Question
Welcome to the one-of-a-kind All-or-Nothing-Restaurant, where if guests are lucky enough to get seated, then they can eat as much as they want. But, there's
Welcome to the one-of-a-kind "All-or-Nothing-Restaurant", where if guests are lucky enough to get seated, then they can eat as much as they want. But, there's a catch. The arriving group can only be seated all together at one table. If the current seating arrangement cannot accommodate them, they need to try coming back another night. Each table in the restaurant can only be used once in the entire evening.
Given the restaurant's popularity, there is large queue of groups waiting to be seated everyday. The restaurant however only has 3 types of tables - Large (which can accommodate 10 guests, Medium which can accommodate 7 guests and Small which can accommodate 5 guests). Currently, the restaurant has only 1 Large sized table, 2 Medium sized tables and 3 small sized tables. The owner of the restaurant has hired you to write a program to assign guests to tables.
Description
The input of the program consists of the size of the groups, in the order in which they appear in the queue. The size of the first group to be seated appears first. The table assignment program must first print a list of available tables in the restaurant. It should then read the sizes of each group to be seated and report on attempts to assign the group to a table. Finally, it should print a summary of seat assignments. See the example input and output files for details. If a group size is not valid (i.e. not a positive number) an exception should be thrown and an error message printed before the program proceeds with the next group.
Assignment
The program assigntables.cpp is provided, together with the header files Restaurant.h and Table.h . You should not modify these files. You will implement the classes Restaurant and Table in the files Restaurant.cpp and Table.cpp respectively. You will create a Makefile that includes a target assigntables (that builds the executable) and a target clean (that removes the executable and all object files). Use the test input files to verify that your program reproduces exactly the example output files. Use the Unix diff command to compare your output to the example output.
Specification of the Restaurant class
The Restaurant class constructor creates the list of tables using dynamic allocation of the (private) pointer array tableList. The tables should appear in the list in order of decreasing size. The Restaurant constructor takes three arguments (the number of large, medium and small tables in the restaurant). The size data member is the total number of tables in the restaurant. The Restaurant class has a member function addGuests that tries to assign a group of guests to a table by inspecting the list of tables and by assigning the group to the first table that can accommodate the group, starting at the beginning of the tableList array. The Restaurant class also has a member function printSummary that prints a list of tables with their current and maximum occupancy. Empty tables should not be printed in the summary. See the examples of output files for details on the output format.
Specification of the Table class
The Table class constructor takes one argument (the size of the table). It has accessor member functions maxOccupancy and currentOccupancy returning the maximum and current number of guests respectively. The addGuests member function attempts to add a group of guests to the table and modifies the occupancy accordingly. It returns true if the operation is successful and false otherwise.
//
// assigntables.cpp
//
#include
#include "Restaurant.h"
using namespace std;
int main(void)
{
// create a Restaurant with 1 large table, 2 medium tables and 3 small tables
Restaurant restaurant(1,2,3);
do
{
try
{
int party_size = 0;
cin >> party_size;
if ( cin )
{
cout << "Trying to seat party of " << party_size << endl;
restaurant.addGuests(party_size);
}
}
catch( invalid_argument &e )
{
cout << "Invalid party size: " << e.what() << " (skipped)" << endl;
}
}
while ( cin );
restaurant.printSummary();
}
//
// Restaurant.h
//
#ifndef RESTAURANT_H
#define RESTAURANT_H
#include "Table.h"
class Restaurant
{
public:
Restaurant(int nLarge, int nMedium, int nSmall);
void addGuests(int nGuests);
void printSummary(void);
private:
const int size;
Table** tableList;
};
#endif
//
// Table.h
//
#ifndef TABLE_H
#define TABLE_H
class Table
{
public:
Table(int n);
int maxOccupancy(void);
int currentOccupancy(void);
bool addGuests(int n);
private:
const int maxGuests;
int numGuests;
};
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started