Group
Data Structures: Stacks, Queues in C++
Objective
1. Create a queue to store print jobs.
2. Add new print jobs to the queue.
3. Process the print jobs by removing them from the queue in the order they were added.
4. Output the status of the print jobs (processed or pending) after each operation.
Write a program that simulates a print queue.
Example C++ Exercise
Show C++ Code
#include <iostream> // Include for input/output operations
#include <queue> // Include for queue data structure
#include <string> // Include for string handling
using namespace std;
// Function to simulate the print queue
void processPrintQueue(queue<string>& printQueue) {
// Check if the queue is empty
while (!printQueue.empty()) {
// Process the next print job in the queue
cout << "Processing print job: " << printQueue.front() << endl;
printQueue.pop(); // Remove the processed job from the queue
}
cout << "All print jobs have been processed." << endl;
}
// Main function
int main() {
queue<string> printQueue; // Queue to store the print jobs
// Add print jobs to the queue
printQueue.push("Document1.pdf");
printQueue.push("Image1.png");
printQueue.push("Report.docx");
cout << "Initial print queue: " << endl;
cout << "1. Document1.pdf" << endl;
cout << "2. Image1.png" << endl;
cout << "3. Report.docx" << endl;
// Process the print jobs
processPrintQueue(printQueue); // Call the function to process the jobs
return 0;
}
Output
Initial print queue:
1. Document1.pdf
2. Image1.png
3. Report.docx
Processing print job: Document1.pdf
Processing print job: Image1.png
Processing print job: Report.docx
All print jobs have been processed.