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
#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
Get Answers For Free
Most questions answered within 1 hours.