Question

Given main(). complete the program to add people to a queue.

 14.11 LAB: Ticketing service (queue)

 Given main(). complete the program to add people to a queue. The program should read in a list of people's names including "You" (ending with-1), adding each person to the peopleInQueue queue. Then, remove each person from the queue until "You" is at the head of the queue. Include print statements as shown in the example below.

 Ex. If the input is:

 Zadie Smith

 Tom Sawyer

 You

 Louisa Alcott

 -1

 the output is:

 Welcome to the ticketing service...

 You are number 3 in the queue.

 Zadie Smith has purchased a ticket.

 You are now number 2

 Tom Sawyer has purchased a ticket.

 You are now number 1

 You can now purchase your ticket!

-------------mian.cpp

#include
#include

using namespace std;

int main (int argc, char* argv[]) {
string personName = "";
int counter = 0;
int youPosition;

queuepeopleInQueue;

getline(cin, personName);
while (personName != "-1") {
// TODO: Add personName to peopleInQueue
// determine position of "You" (youPosition)

getline(cin, personName);
}

cout << "Welcome to the ticketing service... " << endl;
cout << "You are number " << youPosition << " in the queue." << endl;

// TODO: In a loop, remove head person from peopleInQueue,
// output their name and that they have purchased a ticket,
// then output your position in the queue. When you are at
// the head, output that you can purchase your ticket.


return 0;
}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include
#include

using namespace std;

int main (int argc, char* argv[]) {
   string personName = "";
   int counter = 0;
   int youPosition;
  
   queue peopleInQueue;
  
   getline(cin, personName);
   while (personName != "-1") {
       counter++;
       if(personName == "You")
           youPosition = counter;
          
       peopleInQueue.push(personName);
       getline(cin, personName);
   }
  
   cout << "Welcome to the ticketing service... " << endl;
   cout << "You are number " << youPosition << " in the queue." << endl;
   while (youPosition != 1) {
   cout << peopleInQueue.front() <<" has purchased ticket." << endl;
       youPosition--;
       peopleInQueue.pop();
       cout << "You are now number "<    }
   cout <<"You can now purchase your ticket!" <    return 0;
}



Screenshot of the program :

Output :

Output 2 :

Output 3 :

Add a comment
Answer #2

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

#include

#include

using namespace std;

int main (int argc, char* argv[]) {

                string personName = "";

                int counter = 0;

                int youPosition=-1;

               

                queue peopleInQueue;

               

                getline(cin, personName);

                while (personName != "-1") {

                                //simply adding personName to the queue

                                peopleInQueue.push(personName);    

                                //if the name of person is "You", setting current size as youPosition

                                if(personName=="You"){

                                                youPosition=peopleInQueue.size();

                                }

                                //reading next name

                                getline(cin, personName);

                }

               

                //if user did not enter 'You', displaying error and quitting

                if(youPosition==-1){

                                cout<<"'You' not found!"<

                                return 0;

                }

               

                cout << "Welcome to the ticketing service... " << endl;

                cout << "You are number " << youPosition << " in the queue." << endl;

               

                // looping until 'You' is at the front of the queue

                while(peopleInQueue.front()!="You"){

                                //fetching front name from queue, removing it

                                personName=peopleInQueue.front();

                                peopleInQueue.pop();

                                //displaying the removed guy's name

                                cout<

                                //updating youPosition

                                youPosition--;

                                //displaying updated position

                                cout << "You are number " << youPosition << endl;

                }

                //displaying that "You" is at the front of the queue; can now purchase the ticket

                cout<

                return 0;

}

/*INPUT*/

Zadie Smith

Tom Sawyer

You

Louisa Alcott

-1

/*OUTPUT*/

Welcome to the ticketing service...

You are number 3 in the queue.

Zadie Smith has purchased a ticket.

You are number 2

Tom Sawyer has purchased a ticket.

You are number 1

You can now purchase your ticket!

Add a comment
Know the answer?
Add Answer to:
Given main(). complete the program to add people to a queue.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given main(), complete the program to add people to a queue

    4.14 LAB: Ticketing service (Queue)Given main(), complete the program to add people to a queue. The program should read in a list of people's names including "You" (ending with -1), adding each person to thepeopleInQueue queue. Then, remove each person from the queue until "You" is at the head of the queue. Include print statements as shown in the example below.Ex. If the input isZadie Smith Tom Sawyer You Louisa Alcottthe output isWelcome to the ticketing service...  You are number 3 in the queue. Zadie Smith has purchased a ticket. You are now number 2 Tom Sawyer has purchased a ticket. You are now number 1 You can now purchase your ticket!Code that I have been...

  • LAB: Ticketing service (Queue)

    LAB: Ticketing service (Queue)Given main(), complete the program to add people to a queue. The program should read in a list of people's names including "You" (ending with -1), adding each person to the peopleInQueue queue. Then, remove each person from the queue until "You" is at the head of the queue. Include print statements as shown in the example below.Ex. If the input is:Zadie Smith Tom Sawyer You Louisa Alcott -1the output is:Welcome to the ticketing service...  You are number 3 in the queue. Zadie Smith has purchased a ticket. You are now number 2 Tom Sawyer has purchased a ticket. You are now number 1 You can now purchase your ticket!TicketingService.javaimport java.util.Scanner; import java.util.LinkedList; import java.util.Queue; public class TicketingService {    public static void main (String[] args) {       Scanner scnr = new Scanner(System.in);...

  • lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the...

    lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the complete main() function, partial queue class header queue.h, and queue.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor enqueue() dequeue() You may elect to create the following helper functions: isFull() isEmpty() A description of these ADT operations are available in this Zybook and in the textbook's chapter 17. Example: If the input is: 3 Led Zepplin...

  • 1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class...

    1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...

  • in C++ creat a DynamicQueue class, add a new data member called count to trace the...

    in C++ creat a DynamicQueue class, add a new data member called count to trace the total number of node you have in current queue (you need to modify some member functions for adding count). Add a member function called displayQueue() to display values stored in each node in the current queue, also the total number of nodes in the queue. You also need to have a driver program (refer to Tester) to test your modified new class and new...

  • working on a program in c++ The user enters an email address into your program. You...

    working on a program in c++ The user enters an email address into your program. You must cuteverything after the @ symbol and output it. #include <iostream> #include <string> using namespace std; int main() { string email_adress = ""; //email get the info cout <<"what is your email adress? "; getline(cin, email_adress) ; cin.ignore('@'); // now we put into writitng in sentence cout <<"the email you entered is: " << email_adress << ". " <<"your email adress domian is :"...

  • I have a queue and stack class program that deals with a palindrome, I need someone...

    I have a queue and stack class program that deals with a palindrome, I need someone to help to put in templates then rerun the code. I'd greatly appreciate it. It's in C++. Here is my program: #include<iostream> #include<list> #include<iterator> #include<string> using namespace std; class Queue { public: list <char> queue; Queue() { list <char> queue; } void Push(char item) { queue.push_back(item); } char pop() { char first = queue.front(); queue.pop_front(); return first; } bool is_empty() { if(queue.empty()) { return...

  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • Write a C++ program to allow the user to create a test bank of questions. The...

    Write a C++ program to allow the user to create a test bank of questions. The program should first ask the user how many questions he or she wishes to create. This quantity will be the first line in the test bank. The user should now be prompted for all information for each question, and then that question is written out to the test bank in the exact format specified in the Phase 2 Individual Project. For each question, the...

  • Need help with a C++ program. I have been getting the error "this function or variable...

    Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) {    // average function , declaring variable    int i;    char str[40];    float avg = 0;    // iterating in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT