Question

In: Computer Science

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 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:

  • Adding a restaurant, by searching the first not-null cell in the array.
  • Removing a restaurant, by searching the restaurant to be removed, deallocating its memory and setting the pointer to null (nullptr)
  • Searching a restaurant (and printing its detail)
  • Modifying something on a restaurant, by searching the restaurant and calling a setter() for the modification
  • Printing 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.

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

Solutions

Expert Solution

#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;
}


Related Solutions

Zagat restaurant guides publish ratings of restaurants for many large cities around the world. The restaurants...
Zagat restaurant guides publish ratings of restaurants for many large cities around the world. The restaurants are rated on a 0 to 30 point scale based on quality of food, decor, service, and cost. Suppose the regression equation that predicts the cost of dinner using the rating of the quality of food for the restaurants in a particular city is (cost of dinner) = 4.089*(food quality) + 2.371. Interpret the slope. 1) We are not given the dataset, so we...
Zagat restaurant guides publish ratings of restaurants for many large cities around the world. The restaurants...
Zagat restaurant guides publish ratings of restaurants for many large cities around the world. The restaurants are rated on a 0 to 30 point scale based on quality of food, decor, service, and cost. Suppose the regression equation that predicts the cost of dinner using the rating of the quality of food for the restaurants in a particular city is (cost of dinner) = 4.201*(food quality) + 2.823. Interpret the slope. Question 3 options: 1) When food quality increases by...
What is a process for creating a sense of urgency around change? How does collaboration promote...
What is a process for creating a sense of urgency around change? How does collaboration promote self-analysis and help you prevent or correct mistakes? How does collaboration promote problem solving and help team members improve their skills? What are the connections between new behaviors and organizational change? How do you replace old habits?
To meet your retirement goals (and pay for that big trip around the world) you will...
To meet your retirement goals (and pay for that big trip around the world) you will need $85,000 in your travel account at the end of 12 years. You are able to place $2800 in to the account at the end of each year. However, you know that this won't make it. Once the estate clears, you are expecting an inheritance from you late uncle in 5 years. (start the savings account now.. 5 years from now, you will have...
Advise your manager on how to or what promotions tools can be used to promote your Restaurants service in your locality
Advise your manager on how to or what promotions tools can be used to promote your Restaurants service in your locality
Consider your work environment, domain of interest, or the world around you, and discuss when it...
Consider your work environment, domain of interest, or the world around you, and discuss when it might be more appropriate to use the mean, median, or mode for measures of central tendency.
This question has two parts Part 1 You are CFO of a major chain of restaurants...
This question has two parts Part 1 You are CFO of a major chain of restaurants called Chipotle. In an increasingly challenging business environment, Chipotle is considering an acquisition of its major competitor, Los Pollos Hermanos (LPH). Your research indicates that LPH is expected to generate a positive cashflow of $186 million per year for each of the next 20 years. The first of the annual cashflows will be received one year from today. You estimate that an appropriate opportunity...
Imagine you are a Human Resource Manager of chain restaurants in Istanbul. During the next year,...
Imagine you are a Human Resource Manager of chain restaurants in Istanbul. During the next year, the competitive strategy of restaurants is to provide a fast and high-quality delivery system. How do you Translating Strategy into Human Resource Policies and Practices?
Your company is tasked with creating software for a home security system.
1. Consider the following:Your company is tasked with creating software for a home security system. The software helps manage all the security cameras and devices installed in the house, relays communications between all parties, and provides a “dashboard” mechanism for homeowners and security personnel to access and monitor.Develop 8 to 10 requirements concerning this scenario.2. What is a “recommendation system” and how can it assist in requirements engineering? What tools can be used to assist in requirements gathering?
You will explore obesity around the world. You will research information on obesity in the United...
You will explore obesity around the world. You will research information on obesity in the United States and two other countries, each from different continents. Discuss obesity in the United States and the two countries you selected. What comparisons can be made? What are the cultural differences in these countries that contribute to obesity? What are some of the contributing factors to worldwide obesity rates? What are some social determinants that may contribute to obesity rates? What are shared causal...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT