In this workshop, you will code three classes that are in composition and aggregation relations. The classes will simulate a very simplified form of managing reservations in a restaurant. The restaurant will manage a collection of reservations (composition); a messaging system will be used to send confirmations for the reservation.## *In-Lab*
The in-lab portion of this workshop consists of modules: `w4` (supplied) `Reservation`
Enclose all your source code within the `sdds` namespace and include the necessary guards in each header file.
### `w4` Module (supplied)
**Do not modify this module!** Look at the code and make sure you understand it.
### `Reservation` Module
This module defines a class that holds information about a single reservation at a restaurant for a date/time in October.
Design and code a class named `Reservation` that should be able to store the following information (for each attribute, you can chose any type you think its appropriateyou must be able to justify the decisions you have made):
**reservation id**: an array of characters **the name on the reservation** **the email** that can be used to send the confirmation that the reservation can be honored or not **the number of people** in the party **the day** when the party is expected to come (for simplicity, the day is an integer between 1 and 31) **the hour** when the party is expected to come (for simplicity, the hour is an integer between 1 and 24)
***Public Members*** a default constructor `Reservation(const std::string& m_res)`: A constructor that receives the reservation as a string; this constructor is responsible to extract the information about the reservation from the parameter and store it in the attributes of the instance. The parameter will always have the following format:`ID:NAME,EMAIL,PARTY SIZE,DAY,HOUR`This constructor should remove all spaces from the **beginning and end** of any token in the string.
When implementing the constructor, consider the following functions: [std::string::substr()](https://en.cppreference.com/w/cpp/string/basic_string/substr) [std::string::find()](https://en.cppreference.com/w/cpp/string/basic_string/find) [std::string::erase()](https://en.cppreference.com/w/cpp/string/basic_string/erase) [std::stoi()](https://en.cppreference.com/w/cpp/string/basic_string/stol)
***Friend Helpers*** overload the insertion operator to insert the content of a reservation object into an **ostream** object: if the hour is between 6AM and 9AM (inclusive), the kitchen serves breakfast:`Reservation ID: NAME <email> Breakfast on day DAY @ HOUR:00 for #PARTY_SIZE people.` if the hour is between 11AM and 3PM (inclusive), the kitchen serves lunch:`Reservation ID: NAME <email> Lunch on day DAY @ HOUR:00 for #PARTY_SIZE people.` if the hour is between 5PM and 9PM (inclusive), the kitchen serves dinner:`Reservation ID: NAME <email> Dinner on day DAY @ HOUR:00 for #PARTY_SIZE people.` at any other time the kitchen is closed and only drinks can be served:`Reservation ID: NAME <email> Drinks on day DAY @ HOUR:00 for #PARTY_SIZE people.` the name on the reservation should be printed on a field of size 10, aligned to the right the email on the reservation (including the characters `<` and `>`) should be printed on a field of size 20, aligned to the left. this operator should insert the endline character before exiting.
### Sample Output
When the program is started with the command (the file `data.txt` is provided):`w4.exe data.txt`the output should look like:`Command Line:1: w4.exe2: data.txt
ReservationsReservation RES-001: John <[email protected]> Drinks on day 3 @ 5:00 for 2 people.Reservation RES-002: David <[email protected]> Breakfast on day 4 @ 6:00 for 1 people.Reservation RES-003: Sara <[email protected]> Breakfast on day 5 @ 7:00 for 2 people.Reservation RES-004: Ana <[email protected]> Breakfast on day 5 @ 8:00 for 1 people.Reservation RES-005: John <[email protected]> Breakfast on day 4 @ 9:00 for 1 people.Reservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-007: Mike <[email protected]> Lunch on day 4 @ 11:00 for 4 people.Reservation RES-008: Mike <[email protected]> Lunch on day 5 @ 12:00 for 8 people.Reservation RES-009: Dan <[email protected]> Lunch on day 3 @ 13:00 for 2 people.Reservation RES-010: Donna <[email protected]> Lunch on day 5 @ 14:00 for 5 people.Reservation RES-011: Ana <[email protected]> Lunch on day 4 @ 15:00 for 4 people.Reservation RES-012: John <[email protected]> Drinks on day 5 @ 16:00 for 2 people.Reservation RES-013: Sara <[email protected]> Dinner on day 3 @ 17:00 for 6 people.Reservation RES-014: Jennifer <[email protected]> Dinner on day 5 @ 18:00 for 6 people.Reservation RES-015: Stan <[email protected]> Dinner on day 4 @ 19:00 for 5 people.Reservation RES-016: Chris <[email protected]> Dinner on day 4 @ 20:00 for 3 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.Reservation RES-018: David <[email protected]> Drinks on day 5 @ 22:00 for 4 people.Reservation RES-019: Chris <[email protected]> Drinks on day 3 @ 23:00 for 1 people.Reservation RES-020: Donna <[email protected]> Drinks on day 4 @ 24:00 for 3 people.`
## *At-Home*
The *at-home* part of this workshop upgrades your *in-lab* solution to include two more modules: `Restaurant` `ConfirmationSender`
The module `Reservation` dosnt need any change.
### `Restaurant` Module
Add a `Restaurant` module to your project. This module should maintain a dynamically allocated array of objects of type `Reservation`: `Reservation*` (each element of the array is an object of type `Reservation`).
***Public Members***
`Restaurant(Reservation* reservations[], size_t cnt)`: a constructor that receives as a parameter an array of pointers to objects of type `Reservation` (i.e., each element of the array is a pointer). If you need a refresh on arrays of pointers, re-read the material from the last term (chapter **Abstract Base Classes**, section **Array of Pointers**). this constructor should store copies of all reservations
add any other special members that are necessary to manage a the resource
`size_t size() const`: return how many reservations are in the system.
***Friend Helpers***
overload the insertion operator to insert the content of a `Restaurant` object into an **ostream** object: if there are no reservations:`Fancy RestaurantThe object is empty!` if there are reservations:`Fancy RestaurantRESERVATIONRESERVATION`
### `ConfirmationSender` Module
Add a `ConfirmationSender` module to your project. The purpose of this module is to receive all the reservations from multiple restaurants, and contact the recipients with a confirmation message.
This module should maintain a dynamically allocated array of **pointers** to objects of type `Reservation`: `const sdds::Reservation**` (each element of the array is a pointer to an object of type `Reservation`).
***Public Members***
add any special members that are necessary to manage a the resource (the resource is an **array of pointers**; the array must be managed by this class, but the objects at the addresses stored in the array are managed outside the class)
`ConfirmationSender& operator+=(const Reservation& res)`: add the parameter to the array. if `res` is already in the array, this operator does nothing resize the array to make room for the `res` store the **address** of `res` in the array (this function should not make copies of the parameter)
`ConfirmationSender& operator-=(const Reservation& res)`: remove the parameter from the array if `res` is not in the array, this operator does nothing search the array for `res`, set the pointer in the array to `nullptr` when `res` is found. **To challenge yourself, try to actually resize the array.**
***Friend Helpers***
overload the insertion operator to insert the content of a `ConfirmationSender` object into an **ostream** object: if there are no reservations to confirm:`cppConfirmations to SendThe object is empty!` if there are reservations to confirm`cppConfirmations to SendRESERVATIONRESERVATION`
### Sample Output
When the program is started with the command:`w4.exe data.txt`the output should look like:`Command Line:1: w4.exe2: data.txt
ReservationsReservation RES-001: John <[email protected]> Drinks on day 3 @ 5:00 for 2 people.Reservation RES-002: David <[email protected]> Breakfast on day 4 @ 6:00 for 1 people.Reservation RES-003: Sara <[email protected]> Breakfast on day 5 @ 7:00 for 2 people.Reservation RES-004: Ana <[email protected]> Breakfast on day 5 @ 8:00 for 1 people.Reservation RES-005: John <[email protected]> Breakfast on day 4 @ 9:00 for 1 people.Reservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-007: Mike <[email protected]> Lunch on day 4 @ 11:00 for 4 people.Reservation RES-008: Mike <[email protected]> Lunch on day 5 @ 12:00 for 8 people.Reservation RES-009: Dan <[email protected]> Lunch on day 3 @ 13:00 for 2 people.Reservation RES-010: Donna <[email protected]> Lunch on day 5 @ 14:00 for 5 people.Reservation RES-011: Ana <[email protected]> Lunch on day 4 @ 15:00 for 4 people.Reservation RES-012: John <[email protected]> Drinks on day 5 @ 16:00 for 2 people.Reservation RES-013: Sara <[email protected]> Dinner on day 3 @ 17:00 for 6 people.Reservation RES-014: Jennifer <[email protected]> Dinner on day 5 @ 18:00 for 6 people.Reservation RES-015: Stan <[email protected]> Dinner on day 4 @ 19:00 for 5 people.Reservation RES-016: Chris <[email protected]> Dinner on day 4 @ 20:00 for 3 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.Reservation RES-018: David <[email protected]> Drinks on day 5 @ 22:00 for 4 people.Reservation RES-019: Chris <[email protected]> Drinks on day 3 @ 23:00 for 1 people.Reservation RES-020: Donna <[email protected]> Drinks on day 4 @ 24:00 for 3 people.
R: Testing Constuctor==========================Fancy RestaurantReservation RES-001: John <[email protected]> Drinks on day 3 @ 5:00 for 2 people.Reservation RES-002: David <[email protected]> Breakfast on day 4 @ 6:00 for 1 people.Reservation RES-003: Sara <[email protected]> Breakfast on day 5 @ 7:00 for 2 people.Reservation RES-004: Ana <[email protected]> Breakfast on day 5 @ 8:00 for 1 people.Reservation RES-005: John <[email protected]> Breakfast on day 4 @ 9:00 for 1 people.Reservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-007: Mike <[email protected]> Lunch on day 4 @ 11:00 for 4 people.Reservation RES-008: Mike <[email protected]> Lunch on day 5 @ 12:00 for 8 people.Reservation RES-009: Dan <[email protected]> Lunch on day 3 @ 13:00 for 2 people.Reservation RES-010: Donna <[email protected]> Lunch on day 5 @ 14:00 for 5 people.Reservation RES-011: Ana <[email protected]> Lunch on day 4 @ 15:00 for 4 people.Reservation RES-012: John <[email protected]> Drinks on day 5 @ 16:00 for 2 people.Reservation RES-013: Sara <[email protected]> Dinner on day 3 @ 17:00 for 6 people.Reservation RES-014: Jennifer <[email protected]> Dinner on day 5 @ 18:00 for 6 people.Reservation RES-015: Stan <[email protected]> Dinner on day 4 @ 19:00 for 5 people.Reservation RES-016: Chris <[email protected]> Dinner on day 4 @ 20:00 for 3 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.Reservation RES-018: David <[email protected]> Drinks on day 5 @ 22:00 for 4 people.Reservation RES-019: Chris <[email protected]> Drinks on day 3 @ 23:00 for 1 people.Reservation RES-020: Donna <[email protected]> Drinks on day 4 @ 24:00 for 3 people.==========================
R: Testing Copy Constuctor==========================Fancy RestaurantReservation RES-001: John <[email protected]> Drinks on day 3 @ 5:00 for 2 people.Reservation RES-002: David <[email protected]> Breakfast on day 4 @ 6:00 for 1 people.Reservation RES-003: Sara <[email protected]> Breakfast on day 5 @ 7:00 for 2 people.Reservation RES-004: Ana <[email protected]> Breakfast on day 5 @ 8:00 for 1 people.Reservation RES-005: John <[email protected]> Breakfast on day 4 @ 9:00 for 1 people.Reservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-007: Mike <[email protected]> Lunch on day 4 @ 11:00 for 4 people.Reservation RES-008: Mike <[email protected]> Lunch on day 5 @ 12:00 for 8 people.Reservation RES-009: Dan <[email protected]> Lunch on day 3 @ 13:00 for 2 people.Reservation RES-010: Donna <[email protected]> Lunch on day 5 @ 14:00 for 5 people.Reservation RES-011: Ana <[email protected]> Lunch on day 4 @ 15:00 for 4 people.Reservation RES-012: John <[email protected]> Drinks on day 5 @ 16:00 for 2 people.Reservation RES-013: Sara <[email protected]> Dinner on day 3 @ 17:00 for 6 people.Reservation RES-014: Jennifer <[email protected]> Dinner on day 5 @ 18:00 for 6 people.Reservation RES-015: Stan <[email protected]> Dinner on day 4 @ 19:00 for 5 people.Reservation RES-016: Chris <[email protected]> Dinner on day 4 @ 20:00 for 3 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.Reservation RES-018: David <[email protected]> Drinks on day 5 @ 22:00 for 4 people.Reservation RES-019: Chris <[email protected]> Drinks on day 3 @ 23:00 for 1 people.Reservation RES-020: Donna <[email protected]> Drinks on day 4 @ 24:00 for 3 people.Fancy RestaurantReservation RES-001: John <[email protected]> Drinks on day 3 @ 5:00 for 2 people.Reservation RES-002: David <[email protected]> Breakfast on day 4 @ 6:00 for 1 people.Reservation RES-003: Sara <[email protected]> Breakfast on day 5 @ 7:00 for 2 people.Reservation RES-004: Ana <[email protected]> Breakfast on day 5 @ 8:00 for 1 people.Reservation RES-005: John <[email protected]> Breakfast on day 4 @ 9:00 for 1 people.Reservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-007: Mike <[email protected]> Lunch on day 4 @ 11:00 for 4 people.Reservation RES-008: Mike <[email protected]> Lunch on day 5 @ 12:00 for 8 people.Reservation RES-009: Dan <[email protected]> Lunch on day 3 @ 13:00 for 2 people.Reservation RES-010: Donna <[email protected]> Lunch on day 5 @ 14:00 for 5 people.Reservation RES-011: Ana <[email protected]> Lunch on day 4 @ 15:00 for 4 people.Reservation RES-012: John <[email protected]> Drinks on day 5 @ 16:00 for 2 people.Reservation RES-013: Sara <[email protected]> Dinner on day 3 @ 17:00 for 6 people.Reservation RES-014: Jennifer <[email protected]> Dinner on day 5 @ 18:00 for 6 people.Reservation RES-015: Stan <[email protected]> Dinner on day 4 @ 19:00 for 5 people.Reservation RES-016: Chris <[email protected]> Dinner on day 4 @ 20:00 for 3 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.Reservation RES-018: David <[email protected]> Drinks on day 5 @ 22:00 for 4 people.Reservation RES-019: Chris <[email protected]> Drinks on day 3 @ 23:00 for 1 people.Reservation RES-020: Donna <[email protected]> Drinks on day 4 @ 24:00 for 3 people.==========================
R: Testing Move Constuctor==========================Fancy RestaurantThe object is empty!Fancy RestaurantReservation RES-001: John <[email protected]> Drinks on day 3 @ 5:00 for 2 people.Reservation RES-002: David <[email protected]> Breakfast on day 4 @ 6:00 for 1 people.Reservation RES-003: Sara <[email protected]> Breakfast on day 5 @ 7:00 for 2 people.Reservation RES-004: Ana <[email protected]> Breakfast on day 5 @ 8:00 for 1 people.Reservation RES-005: John <[email protected]> Breakfast on day 4 @ 9:00 for 1 people.Reservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-007: Mike <[email protected]> Lunch on day 4 @ 11:00 for 4 people.Reservation RES-008: Mike <[email protected]> Lunch on day 5 @ 12:00 for 8 people.Reservation RES-009: Dan <[email protected]> Lunch on day 3 @ 13:00 for 2 people.Reservation RES-010: Donna <[email protected]> Lunch on day 5 @ 14:00 for 5 people.Reservation RES-011: Ana <[email protected]> Lunch on day 4 @ 15:00 for 4 people.Reservation RES-012: John <[email protected]> Drinks on day 5 @ 16:00 for 2 people.Reservation RES-013: Sara <[email protected]> Dinner on day 3 @ 17:00 for 6 people.Reservation RES-014: Jennifer <[email protected]> Dinner on day 5 @ 18:00 for 6 people.Reservation RES-015: Stan <[email protected]> Dinner on day 4 @ 19:00 for 5 people.Reservation RES-016: Chris <[email protected]> Dinner on day 4 @ 20:00 for 3 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.Reservation RES-018: David <[email protected]> Drinks on day 5 @ 22:00 for 4 people.Reservation RES-019: Chris <[email protected]> Drinks on day 3 @ 23:00 for 1 people.Reservation RES-020: Donna <[email protected]> Drinks on day 4 @ 24:00 for 3 people.==========================
CS: Testing Constuctor==========================Confirmations to SendThe object is empty!==========================
CS: Testing Operators==========================Confirmations to SendReservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.Reservation RES-009: Dan <[email protected]> Lunch on day 3 @ 13:00 for 2 people.Confirmations to SendReservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.==========================
CS: Testing Copy Constuctor==========================Confirmations to SendReservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.Confirmations to SendReservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.==========================
CS: Testing Move Constuctor==========================Confirmations to SendThe object is empty!Confirmations to SendReservation RES-006: Vanessa <[email protected]> Drinks on day 3 @ 10:00 for 2 people.Reservation RES-017: Vanessa <[email protected]> Dinner on day 4 @ 21:00 for 4 people.==========================`
Reviews
There are no reviews yet.