Question

In: Computer Science

C++ Linkedlist Create a food menu so the customer can see what we are selling, if...

C++ Linkedlist

Create a food menu so the customer can see what we are selling, if the users place order that not on the menu, prompt the users to enter again. Food code and food must be matched when users enter.

Solutions

Expert Solution

Here is the solution to your question. I tried my best to solve your doubt, however, if you find it is not as good as expected by you. Please do write your further doubts regarding this question in the comment section, I will try to resolve your doubts regarding the submitted solution as soon as possible.

Please give proper indentation as shown in the screenshot

If you think, the solution provided by me is helpful to you please do an upvote.

Either you forget to upload some files or you have incomplete question. However based on your provided information that might help you:

#include<iostream>

using namespace std;
class Food
{
public:
    int code;
    string name;
    Food* next;
};
class Menu:public Food
{
 
    Food *first,*last;
public:
    Menu()
    {
        first=NULL;
        last=NULL;
    }
    void insert(int fcode,string fname);
    void search();
};

void Menu::insert(int fcode,string fname)
{
    Food *prev,*cur;
    prev=NULL;
    cur=first;
    int count=1,pos,ch,n;
    Food *temp=new Food;
    temp->code=fcode;
    temp->name=fname;
    temp->next=NULL;
    temp->next=first;
    first=temp;
}
void Menu::search()
{
    int value,pos=0;
    bool flag=false;
    if(first==NULL)
    {
        cout<<"Menu is Empty";
        return;
    }
    cout<<"Enter the Food code to be Searched:";
    cin>>value;
    Food *temp;
    temp=first;
    while(temp!=NULL)
    {
        pos++;
        if(temp->code==value)
        {
            flag=true;
            cout<<"Food "<<temp->name<<" is Found at "<<pos<<" Position"<<endl;
            return;
        }
        temp=temp->next;
    }
    if(!flag)
    {
        cout<<"Food "<<value<<" not Found in the Menu, Try Again!!!"<<endl;
        this->search();
    }
}
int main()
{
    Menu m;
    
    m.insert(1,"tea");
    m.insert(2,"water");
    m.insert(3,"breakfast");
    m.insert(4,"lunch");
    m.insert(5,"dinner");

    m.search();
    return 0;
}

Related Solutions

print a menu so that the user can then order from that menu. The user will...
print a menu so that the user can then order from that menu. The user will enter each item they want until they are done with the order. At the end you will print the items the user ordered with their price and the total. Note: You will be storing your menu items (pizza, burger, hotdog, salad) and your prices (10, 7, 4, 8) in separate lists. Menu 0) pizza $10 1) burger $7 2) hotdog $4 3) salad $8...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER TEMPERATURE – JAMES SMITH Convert Fahrenheit temperature to Celsius Convert Celsius temperature to Fahrenheit Exit CASE 1: Convert Fahrenheit temperature to Celsius -Display the message to ask to enter Fahrenheit degree from the keyboard -Use the following formula to convert to Celsius degree         Celsius Temperature = (Fahrenheit Temperature – 32) * 5/9 ; -Display the output as below: TemperatureConverter_Smith.cpp TEMPERATURE CONVERTER – JAMES...
Write in Java! (Not Javascript) Consider the LinkedList class we discussed in class (see the slides...
Write in Java! (Not Javascript) Consider the LinkedList class we discussed in class (see the slides for lecture 8). Add the following methods to the class and submit the completed LinkedList class. int size() which returns the size of the linked list Link getElementByIndex(int index) which returns the Link/node specified by the index. For example, getElementByIndex(0) should return the first Link, getElementByIndex(2) should return the third Link. If index is not in range, your method should return null. boolean hasDuplicate()...
We need a Stock and Bond trading application. Here is what is required: Create Menu with...
We need a Stock and Bond trading application. Here is what is required: Create Menu with the options organized as below: ******************************************************************************** A. Buy Bonds B. Sell Bonds C. Buy Stocks D. Sell Stocks E. Short Stock Sale    X. Exit Here are the steps involved. Create a char variable named menuChoice. Display the menu as described above. Prompt for the menu choice (A-E,X) (Assume the input will be uppercased). Use an IF statement to validate that the choices are...
Write a C++ code to print to the user a simple menu of a fast food...
Write a C++ code to print to the user a simple menu of a fast food restaurant. You should allow the user to select his/her preferred burgers and/or drinks and you should display the final bill to the user for payment. The user should be able to select more than one item. You should use the switch statement.
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
C++ Create a recursive program what will test three recursive functions. It would have a menu...
C++ Create a recursive program what will test three recursive functions. It would have a menu like: 1. Recursive factorial 2. Towers of Hanoi 3. Recursive summation 0. Exit Enter selection: 3 Enter number: 4 The recursive summation will take an integer and sum value from 1 to the integer. Don’t enter a number if the selection is 0 for quit. Please have the functions in an implementation file and the prototypes of the functions in a header file and...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
Food inspectors inspect samples of food products to see if they are safe. This can be...
Food inspectors inspect samples of food products to see if they are safe. This can be thought of as a hypothesis test with the following hypotheses. H0: the food is safe Ha: the food is not safe The following is an example of what type of error? The sample suggests that the food is safe, but it actually is not safe. type I type II not an error
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT