In: Computer Science
You are creating a system to promote a chain of fancy restaurants around the world. Your system will use an array of dynamically allocated 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:
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.
Refer to the rubric to ensure that you have it all covered.
Please use C++ language for this programme.
rubric: 1)input text file Complete, comprehensive and shows all scenarios
2) adding a restaurant Adds a restaurant by searching the first not-null cell in the array and dynamically allocating memory for the new object
3)removing a restaurant Removes a restaurant by searching the restaurant to be removed, deallocating its memory and setting the pointer to null (nullptr)
4) searching The search returns null if the value is not found or the pointer to the restaurant found
5) modifying Searches the restaurant. If found, calls the related setter() to change the value of the restaurant.
6) printing Prints the array in a formatted way
#include <iostream>
#include<stdlib.h>
#define MAX 100
using namespace std;
struct restaurent
{
string name;
int id;
};
int main()
{
int ch=-1;
struct restaurent *arr[MAX];
int size=-1;
while(ch!=0)
{
cout<<"1 for
adding a restaurent\n";
cout<<"2 for
printing list\n";
cout<<"3 for
removing a restaurent\n";
cout<<"4 for
modifying a restaurent\n";
cout<<"0 for
quit";
cout<<"\nENTER
YOUR COMMAND:";
cin>>ch;
switch(ch)
{
case 1:
if(size<MAX-1)
{
struct restaurent *new1=(struct restaurent*)malloc(sizeof(struct
restaurent));
string name_;
int id_;
cout<<"\nEnter name of restaurent:";cin>>name_;
new1->name=name_;
cout<<"\nEnter the id of restaurent:";cin>>id_;
new1->id=id_;
arr[++size]=new1;
}
else
{
cout<<"\nNo restaurent added\n";
}
break;
case 2:
if(size>-1)
{
cout<<"\nList of restaurents\n";
for(int i=0;i<=size;i++)
{
cout<<"Name:"<<arr[i]->name<<"
ID:"<<arr[i]->id<<endl;
}
}
else
{
cout<<"\nList is empty\n";
}
break;
case 3:
if(size>-1)
{
int id_,i;
cout<<"\nEnter Id to remove
restaurent:";cin>>id_;
for(i=0;i<=size;i++)
{
if(arr[i]->id==id_);
{
struct restaurent *temp;
temp=arr[i];
if(i!=size)
{
arr[i]=arr[size];
}
size--;
free(temp);
break;
}
}
if(i>size)
{
cout<<"\nNo restaurent found with this ID.\n";
}
}
break;
case 4:
if(size>-1)
{
int id_,i;
string name_;
cout<<"\nEnter Id to remove
restaurent:";cin>>id_;
for(i=0;i<=size;i++)
{
if(arr[i]->id==id_);
{
cout<<"\n:Enter new name:";cin>>name_;
arr[i]->name=name_;
}
break;
}
if(i>size)
{
cout<<"\nNo restaurent found with this ID.\n";
}
}
break;
default:
cout<<"\nInvalid command\n";
break;
}
}
return 0;
}