Group
Data Structures: Stacks, Queues in C++
Objective
1. Implement a queue to represent the bank queue system.
2. Add customers to the queue as they arrive.
3. Serve customers in the order they entered the queue (FIFO).
4. Display the status of the queue after each operation.
5. Ensure the program can handle basic operations like checking if the queue is empty, adding customers, and serving them.
Implement a program to simulate a bank queue using a queue data structure.
Example C++ Exercise
Show C++ Code
#include <iostream> // Include for input/output operations
#include <queue> // Include for queue operations
using namespace std;
// Function to simulate the bank queue
void simulateBankQueue() {
queue<string> bankQueue; // Declare a queue to store customer names
// Simulate adding customers to the queue
bankQueue.push("John"); // Customer John arrives
bankQueue.push("Jane"); // Customer Jane arrives
bankQueue.push("Alice"); // Customer Alice arrives
cout << "Initial Queue: " << endl;
// Display the customers in the queue
cout << "Customers in the queue: " << endl;
while (!bankQueue.empty()) {
cout << bankQueue.front() << endl; // Display the customer at the front of the queue
bankQueue.pop(); // Serve the customer by removing them from the queue
}
cout << "The queue is now empty." << endl;
}
// Main function to run the program
int main() {
simulateBankQueue(); // Call the function to simulate the bank queue
return 0;
}
Output
Initial Queue:
Customers in the queue:
John
Jane
Alice
The queue is now empty.