0% found this document useful (0 votes)
7 views2 pages

Quiz 5

Uploaded by

marcmercado2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Quiz 5

Uploaded by

marcmercado2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

November 22, 2024

Code Explanation and Example Output:

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

int main() {
queue<int> ticketQueue;
int choice, ticketNumber = 1;

do {
cout << "\n--- Ticketing System ---\n";
cout << "1. Issue Ticket\n";
cout << "2. Serve Ticket\n";
cout << "3. Display Queue\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;

switch (choice) {
case 1:
ticketQueue.push(ticketNumber);
cout << "Ticket " << ticketNumber << " issued.\n";
ticketNumber++;
break;

case 2:
if (!ticketQueue.empty()) {
cout << "Serving Ticket " << ticketQueue.front() << ".\n";
ticketQueue.pop();
} else {
cout << "No tickets to serve!\n";
}
break;

case 3:
if (!ticketQueue.empty()) {
cout << "Current Queue: ";
queue<int> tempQueue = ticketQueue; // Create a copy to iterate
while (!tempQueue.empty()) {
cout << tempQueue.front() << " ";
tempQueue.pop();
}
cout << "\n";
} else {
cout << "Queue is empty.\n";
}
break;

case 4:
cout << "Exiting the system.\n";
break;

default:
cout << "Invalid choice! Please try again.\n";
}
} while (choice != 4);

return 0;
}

You might also like