Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need a help here to code simple program as below. After the pandemic, to help with contact tracing each restaurant is responsible to

Hello, I need a help here to code simple program as below.

After the pandemic, to help with contact tracing each restaurant is responsible to write the name and phone number of all their guests.

Help to complete a program that receives the name and phone number of a restaurant, then stands by to receive guest names and numbers.

The number of guests is unknown and the guest list should be kept dynamically.

At the end of the day to end the program, the user hits enter instead of entering the guest name. This should end the program and display all the guests visited that day.

Sample execution:

Please enter the name of the restaurant: Seneca Cafe Enter Phone Number [area] [number]: 416 4915050 Guest entry... Enter guest information or Enter to exit: Guest name: Fred Soley Enter Phone Number [area] [number]: 416 1112222 Enter guest information or Enter to exit: Guest name: Homer Simpson Enter Phone Number [area] [number]: 541 2223333 Enter guest information or Enter to exit: Guest name: Barney Gumble Enter Phone Number [area] [number]: 541 3332222 Enter guest information or Enter to exit: Guest name: Edna Krabappel Enter Phone Number [area] [number]: 541 4443333 Enter guest information or Enter to exit: Guest name: Seneca Cafe, Phone Number: (416) 4915050 ********************************************** Guestlist and their contacts: 1- Fred Soley, (416) 1112222 2- Homer Simpson, (541) 2223333 3- Barney Gumble, (541) 3332221 4- Edna Krabappel, (541) 4443333 

Implementation

This application is implemented in two modules:

  • Main Module (provided)
  • Guest Module (partially provided)

Your task is to complete the implementation of the Guest module to provide the functions needed in the Main module.

You may freely use/copy any logic or code needed from the LAB section!

Structures to be used:

 struct PhoneNumber { int m_number; int m_areacode; }; struct Guest { char m_name[21]; PhoneNumber m_phno; }; struct GuestList { Guest* m_gst; // Dynamically holds the list of guests. int m_noOfGuests; }; 

Mandatory functions

 void read(char* str, int len); 

Reads a CString into the str pointer up to len characters.

This function is already implemented and is provided in the Guest module

void read(char* str, int len) {

if (cin.peek() == ' ') cin.ignore(); // checks the incomming character, if it is newline, it will remove it

cin.getline(str, len);

}

 void read(PhoneNumber& thePhoneNumber); 

Prompts: "Enter Phone Number [area] [number]: " and then receives two integers from cin into the area code and number of thePhoneNumber reference.

 bool read(Guest& theGuest); 

Prompts: "Guest name: " and then reads a CString into the name of theGuest reference. If the user enters a value, then it will read the phone number of theGuest and returns true, otherwise, if the CString for the name is empty after entry, the function returns false.

 void print(const PhoneNumber& thePhoneNumber); 

Prints a phone number as follows:

  • Open parenthesis "("
  • phone area code
  • close parenthesis and space ") "
  • phone number
  • newline
 void print(const Guest& theGuest); 

Prints the guest information as follows:

  • name
  • comma and space ", "
  • phone number
 void print(const GuestList& theGuestList); 

Prints all the guests in a list. It also adds a row number with a dash before each name.

 void addGuest(GuestList& theGuestList, const Guest& aGuest); 

Adds aGuest to the dynamically allocated list of guests in theGuestList

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

The symbols > , Answered: 1 week ago

Answered: 1 week ago