Question

You are creating a system to promote a chain of fancy restaurants around the world. Your...

You are creating a system to promote a chain of fancy restaurants around the world. Your system will use a dynamically allocated array of restaurants and should allow adding, removing and modifying restaurants. Your array will contain up to 100 restaurants. You will create an input .txt file with 20 command of your choice that will include: Adding a restaurant, by searching for the first not-null cell in the array. Removing a restaurant, by searching for the restaurant to be removed, deallocating its memory and setting the pointer to null (nullptr) Searching for a restaurant (and printing its detail) Modifying something on a restaurant, by searching for the restaurant and calling a setter() to modify Printing the details of all restaurants in your array Your command list (the input file) should be comprehensive and should contain all relevant scenarios. For example, after you remove one or more restaurants, have a command printing your restaurants to verify that your program works as expected. One of the commands should be QUIT to quit scanning. You can refer to the assignments of Module 1 for ideas on commands you can use in your input file. Make sure you deallocate your array before you exit the main() function.

in C++ please

Homework Answers

Answer #1

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
# define MAX 100
using namespace std;

// Defines a structure to store Restaurants information
struct Restaurants
{
// Data member to store data
string name;
string mobileNum;
int numTable;
};// End of structure

// Renames the structure Restaurants
typedef struct Restaurants RES;

/*
* Function to add a restaurant information
* Parameters:
* *res - Pointer type array of structure Restaurant
* &len - Record counter of reference type
*/
void add(RES *res, int &len)
{
// Accepts restaurant data to store it at len index position of res
cout<<"\n\n Enter Restaurant data to ADD.";
cout<<"\n Enter the restaurant name: ";
cin>>res[len].name;
cout<<"\n Enter the contact number: ";
cin>>res[len].mobileNum;
cout<<"\n Enter the number of tables: ";
cin>>res[len].numTable;
// Increase the record counter by one
len++;
}// End of function

/*
* Function to search a restaurant information
* Parameters:
* *res - Pointer type array of structure Restaurant
* &len - Record counter of reference type
* Returns found status
* If found then returns the found index position
* Otherwise returns -1 for not found
*/
int findRestaurant(RES *res, int &len)
{
string name;
// Accepts the name to search
cout<<"\n\n Enter the restaurant name to SEARCH: ";
cin>>name;

// Loops till number of records
for(int c = 0; c < len; c++)
{
// Checks if user entered name is equals to current record name
// return the current index position
if(res[c].name.compare(name) == 0)
return c;
}// End of for loop

// Otherwise return -1 for not found
return -1;
}// End of function

/*
* Function to delete a restaurant information
* Parameters:
* *res - Pointer type array of structure Restaurant
* &len - Record counter of reference type
*/
void removeRestaurant(RES *res, int &len)
{
// Calls the function to search a restaurant name
// Stores the return found status
int location = findRestaurant(res, len);

// Checks if found location is not -1 then record found
if(location != -1)
{
// Loops from found location till end
for(int c = location; c < len; c++)
// Shift each record to its left
res[c] = res[c + 1];
// Decrease the record counter by one
len--;
}// End of if condition

// Otherwise record not found
else
cout<<"\n No such restaurant found to Remove.";
}// End of function

/*
* Function to modify a restaurant information
* Parameters:
* *res - Pointer type array of structure Restaurant
* &len - Record counter of reference type
*/
void modify(RES *res, int &len)
{
// Calls the function to search a restaurant name
// Stores the return found status
int location = findRestaurant(res, len);

// Checks if found location is not -1 then record found
if(location != -1)
{
// Accepts the modified data for found location object
cout<<"\n\n Enter the restaurant name to MODIFY: ";
cin>>res[location].name;
cout<<"\n Enter the contact number: ";
cin>>res[location].mobileNum;
cout<<"\n Enter the number of tables: ";
cin>>res[location].numTable;
}// End of if condition

// Otherwise record not found
else
cout<<"\n No such restaurant found to Modify.";
}// End of function

/*
* Function to display all restaurant information
* Parameters:
* *res - Pointer type array of structure Restaurant
* &len - Record counter of reference type
*/
void print(RES *res, int &len)
{
cout<<"\n ************************ Restaurant Information ************************";
// Loops till number of records
for(int c = 0; c < len; c++)
{
// Displays each record information
cout<<"\n\n Restaurant name: "<<res[c].name;
cout<<"\n Contact number: "<<res[c].mobileNum;
cout<<"\n Number of tables: "<<res[c].numTable;
}// End of for loop
}// End of function

// main function definition
int main()
{
// Creates an array of pointers for structure restaurant of size MAX
RES *res = new RES[MAX];
// Record counter
int len = 0;

// To store the command read from file
string command;
// ifstream class object declared to write data from file
ifstream fileRead;

// Opens both the file for reading
fileRead.open("RestaurantsCommand.txt");

// Checks if the file unable to open for reading display's error message and stop
if(!fileRead)
{
cout<<"\n ERROR: Unable to open the file for reading.";
exit(0);
}// End of if condition

// Loops till end of the file
while(!fileRead.eof())
{
// Reads a command from file
fileRead>>command;

// Checks if the command read from file is "Adding" then calls the add() function
if(command.compare("Adding") == 0)
add(res, len);

// Otherwise checks if the command read from file is "Printing" then calls the print() function
else if(command.compare("Printing") == 0)
print(res, len);

// Otherwise checks if the command read from file is "Searching" then calls the findRestaurant() function
else if(command.compare("Searching") == 0)
{
// Calls the function to search a restaurant name
// Stores the found status
int pos = findRestaurant(res, len);

// Checks if found status is not -1 record found
if(pos != -1)
{
// Displays the record at pos index position
cout<<"\n\n Restaurant name: "<<res[pos].name;
cout<<"\n Contact number: "<<res[pos].mobileNum;
cout<<"\n Number of tables: "<<res[pos].numTable;
}// End of if condition
else
cout<<"\n No such restaurant found.";
}// End of else if condition

// Otherwise checks if the command read from file is "Modifying" then calls the modify() function
else if(command.compare("Modifying") == 0)
modify(res, len);

// Otherwise checks if the command read from file is "Removing" then calls the removeRestaurant() function
else if(command.compare("Removing") == 0)
removeRestaurant(res, len);

// Otherwise invalid command
else
cout<<"\n\n Invalid command: "<<command;
}// End of while loop
return 0;
}// End of main function

Sample Output:

Enter the contact number: 9566789844

Enter the number of tables: 45

************************ Restaurant Information ************************

Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45


Enter Restaurant data to ADD.
Enter the restaurant name: Dalema

Enter the contact number: 8861239984

Enter the number of tables: 60

************************ Restaurant Information ************************

Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45

Restaurant name: Dalema
Contact number: 8861239984
Number of tables: 60


Enter Restaurant data to ADD.
Enter the restaurant name: Anmol

Enter the contact number: 7733681117

Enter the number of tables: 65

************************ Restaurant Information ************************

Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45

Restaurant name: Dalema
Contact number: 8861239984
Number of tables: 60

Restaurant name: Anmol
Contact number: 7733681117
Number of tables: 65

Enter the restaurant name to SEARCH: Sunrise

No such restaurant found.


************************ Restaurant Information ************************

Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45

Restaurant name: Dalema
Contact number: 8861239984
Number of tables: 60

Restaurant name: Anmol
Contact number: 7733681117
Number of tables: 65

Enter the restaurant name to SEARCH: Lorian


Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45


************************ Restaurant Information ************************

Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45

Restaurant name: Dalema
Contact number: 8861239984
Number of tables: 60

Restaurant name: Anmol
Contact number: 7733681117
Number of tables: 65

Enter the restaurant name to SEARCH: Asha

No such restaurant found to Modify.


************************ Restaurant Information ************************

Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45

Restaurant name: Dalema
Contact number: 8861239984
Number of tables: 60

Restaurant name: Anmol
Contact number: 7733681117
Number of tables: 65

Enter the restaurant name to SEARCH: Anmol


Enter the restaurant name to MODIFY: Asha

Enter the contact number: 8899445511

Enter the number of tables: 110

************************ Restaurant Information ************************

Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45

Restaurant name: Dalema
Contact number: 8861239984
Number of tables: 60

Restaurant name: Asha
Contact number: 8899445511
Number of tables: 110

Enter the restaurant name to SEARCH: Quto

No such restaurant found to Remove.


************************ Restaurant Information ************************

Restaurant name: Lorian
Contact number: 9566789844
Number of tables: 45

Restaurant name: Dalema
Contact number: 8861239984
Number of tables: 60

Restaurant name: Asha
Contact number: 8899445511
Number of tables: 110

Enter the restaurant name to SEARCH: Lorian

************************ Restaurant Information ************************

Restaurant name: Dalema
Contact number: 8861239984
Number of tables: 60

Restaurant name: Asha
Contact number: 8899445511
Number of tables: 110


Invalid command: Check

RestaurantsCommand.txt file contents

Adding
Printing
Adding
Printing
Adding
Printing
Searching
Printing
Searching
Printing
Modifying
Printing
Modifying
Printing
Removing
Printing
Removing
Printing
Check

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
You can complete this assignment individually or as a group of two people. In this assignment...
You can complete this assignment individually or as a group of two people. In this assignment you will create a ​​Sorted Singly-Linked List​ that performs basic list operations using C++. This linked list should not allow duplicate elements. Elements of the list should be of type ‘ItemType’. ‘ItemType’ class should have a private integer variable with the name ‘value’. Elements in the linked list should be sorted in the ascending order according to this ‘value’ variable. You should create a...
Description: You will develop a small "text-based shell utility" ("ts") for Unix (or similar OS). A...
Description: You will develop a small "text-based shell utility" ("ts") for Unix (or similar OS). A common complaint of the most-used UNIX (text) shells (Bourne, Korn, C) is that it is difficult to remember (long) file names, and type "long" command names. A "menu" type shell allows a user to "pick" an item (file or command)from a "menu". You will display a simple menu, the following is a suggestion (you may change format): Current Working Dir: /home/os.progs/Me It is now:...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
IntNode class I am providing the IntNode class you are required to use. Place this class...
IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is. struct IntNode { int data; IntNode *next;...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT