Question

In: Computer Science

(c++) Create a program that is like deli. You can enter peoples names in, and they...

(c++) Create a program that is like deli. You can enter peoples names in, and they will be placed into a stl queue. You can also choose to "serve" someone, which will choose the next person in line. (It will say "now serving" and then the persons's name.). Last, you can choose to "quit", which will "serve" the remaining people in the queue, and then the program will end.

Solutions

Expert Solution

There is very little information provided in the problem statement regarding the code, I was confused a little about how the code should be, so I have coded a menu-driven program that has the option of adding people in the queue, serving and quit as mentioned in the problem statement. If you needed something else, you can mention in the comment section I will modify the code ASAP. A sample of output has been added below the code as well.

CODE:


#include<iostream>
#include<queue>
#include<string>
using namespace std;

int main(){

    queue<string> deli;   // created a queue of string named deli
    string name;          // a string variable to store the name of person

    while(1){

        cout<<"\n1. Enter People's Name: "<<endl;    // menu for adding, serving and quitting
        cout<<"2. Serve someone"<<endl;
        cout<<"3. Quit "<<endl;

        cout<<"\nEnter your choice? ";
        int choice;
        cin>>choice;
        switch(choice){
            case 1:
                cout<<"Enter person name: ";
                cin>>name;
                deli.push(name);                     // pushed the name in the queue
                cout<<"Added in queue successfully"<<endl;
                break;

            case 2:
                name = deli.front();
                deli.pop();                         // popped the first name in the queue
                cout<<"Serving "<<name<<"..."<<endl;
                cout<<"Served successfully"<<endl;
                break;

            case 3:
                while(!deli.empty()){             // in case of quit, pop and print all the name until queue gets empty and end the program.
                    cout<<"Serving "<<deli.front()<<"..."<<endl;
                    deli.pop();
                }
                cout<<"Served successfully"<<endl;
                exit(0);
                break;

            default:
                cout<<"Invalid choice! please enter again..."<<endl;
                break;




        }




    }





    return 0;
}

OUTPUT:

NOTE: IN case of any query, you are always welcome in the comment section. HAPPY LEARNING!!


Related Solutions

Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
I have to create a program in C++ where a user can enter as many numbers...
I have to create a program in C++ where a user can enter as many numbers as they want (they predetermine the number of values to be inputted) and then the program can echo that input back to the user and then determine if the numbers were even, odd, or a zero and it outputs how many of each were found. This is to be down with four void functions and no arrays. The program initializes the variables zero, odds,...
You are off to shopping and need a program that allows you to enter the names...
You are off to shopping and need a program that allows you to enter the names of items, their price and quantities. Here is what a sample run should look like (with the keyboard input shown in italics) ... Enter item information ("exit" to exit) item 1: chips price: 3.5 quantity: 2 Enter item information ("exit" to exit) item 2: red wine price : 15.0 quantity : 1 Enter item information ("exit" to exit) item 3 : steaks price :...
Write a C++ program using dynamic arrays that allows the user to enter the last names...
Write a C++ program using dynamic arrays that allows the user to enter the last names of the candidates in a local election and the number of votes received by each candidate. The program must ask the user for the number of candidates and then create the appropriate arrays to hold the data. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should...
JAVA Write a program that will compare two names. The program prompts the user to enter...
JAVA Write a program that will compare two names. The program prompts the user to enter two names for a comparison. If the names are same, the program states that. If the names are different, the program converts both names to UPPERCASE, and compares then again. If they are equal, the programs displays a message stating that names are equal if CASE is ignored. Otherwise, the program prints names with a message that names are not equal.  Check also if there...
Time Calculator Create a C++ program that lets the user enter a number of seconds and...
Time Calculator Create a C++ program that lets the user enter a number of seconds and produces output according to the following criteria: • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *...
Use c# Create a program called ResortPrices that prompts the user to enter the number of...
Use c# Create a program called ResortPrices that prompts the user to enter the number of days for a resort stay. Then display the price per night and the total price. Nightly rates are R 500.00 for one or two nights, R 650.00 for three or four nights, R 850.00 for five, six or seven nights, and R 1500.00 for eight nights or more.
Create a C++ program which will prompt the user to enter a password continually until the...
Create a C++ program which will prompt the user to enter a password continually until the password passes the following tests. Password is 6 chars long Password has at least 1 number If the input does not match the tests, it will input a specific error message. "Pass must be 6 chars long." If the input is allowed, print a message saying "Correct Password Criteria."
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT