Question
IN C++ PLEASE 1. For the priority queque, if the dequeque removes the largest value from the queque, what will be the values in the
IN C++ PLEASE
1. For the priority queque, if the dequeque removes the largest value from the queque, what will be the values in the queque after the following operations?
Enqueque (10);
Enqueque (100);
Enqueque(20);
Enqueque(5);
Dequeque();
2. Use code 1 to test out your answers. Please write a file including the above commands called PQtest.in, and use code1 to generate the output file called PQtest.out. Please make a screen capture of PQtest.out and paste it below. Explain how the output file PQtest.out demonstrates your answer in question 1.
3. Code 1 uses a heap to implement priority queque. Draw the heaps condition after each step above in question 1, on a piece of paper. Take a picture of it, and paste it here. There should be five heaps drawn on the paper.
Here is the code:
*******PQDr.cpp********
// Test driver #include #include typedef int ItemType; #include "PQType.h" #include
using namespace std;
int main() {
ifstream inFile; // file containing operations ofstream outFile; // file containing output string inFileName; // input file external name string outFileName; // output file external name string outputLabel; string command; // operation to be executed ItemType item; PQType queue(5); int numCommands;
// Prompt for file names, read file names, and prepare files cout << "Enter name of input command file; press return." << endl; cin >> inFileName; inFile.open(inFileName.c_str());
cout << "Enter name of output file; press return." << endl; cin >> outFileName; outFile.open(outFileName.c_str());
cout << "Enter name of test run; press return." << endl; cin >> outputLabel; outFile << outputLabel << endl;
inFile >> command;
numCommands = 0; while (command != "Quit") { try { if (command == "Enqueue") { inFile >> item; queue.Enqueue(item); outFile << item << " is enqueued." << endl; } else if (command == "Dequeue") { queue.Dequeue(item); outFile<< item << " is dequeued. " << endl; } else if (command == "IsEmpty") if (queue.IsEmpty()) outFile << "Queue is empty." << endl; else outFile << "Queue is not empty." << endl; else if (command == "IsFull") if (queue.IsFull()) outFile << "Queue is full." << endl; else outFile << "Queue is not full." << endl; else if (command == "MakeEmpty") queue.MakeEmpty(); } catch (FullPQ) { outFile << "FullQueue exception thrown." << endl; } catch (EmptyPQ) { outFile << "EmtpyQueue exception thrown." << endl; } numCommands++; cout << " Command number " << numCommands << " completed." << endl; inFile >> command; }; cout << "Testing completed." << endl; inFile.close(); outFile.close(); return 0; }
********PQType.h********
// Test driver #include #include typedef int ItemType; #include "PQType.h" #include
using namespace std;
int main() {
ifstream inFile; // file containing operations ofstream outFile; // file containing output string inFileName; // input file external name string outFileName; // output file external name string outputLabel; string command; // operation to be executed ItemType item; PQType queue(5); int numCommands;
// Prompt for file names, read file names, and prepare files cout << "Enter name of input command file; press return." << endl; cin >> inFileName; inFile.open(inFileName.c_str());
cout << "Enter name of output file; press return." << endl; cin >> outFileName; outFile.open(outFileName.c_str());
cout << "Enter name of test run; press return." << endl; cin >> outputLabel; outFile << outputLabel << endl;
inFile >> command;
numCommands = 0; while (command != "Quit") { try { if (command == "Enqueue") { inFile >> item; queue.Enqueue(item); outFile << item << " is enqueued." << endl; } else if (command == "Dequeue") { queue.Dequeue(item); outFile<< item << " is dequeued. " << endl; } else if (command == "IsEmpty") if (queue.IsEmpty()) outFile << "Queue is empty." << endl; else outFile << "Queue is not empty." << endl; else if (command == "IsFull") if (queue.IsFull()) outFile << "Queue is full." << endl; else outFile << "Queue is not full." << endl; else if (command == "MakeEmpty") queue.MakeEmpty(); } catch (FullPQ) { outFile << "FullQueue exception thrown." << endl; } catch (EmptyPQ) { outFile << "EmtpyQueue exception thrown." << endl; } numCommands++; cout << " Command number " << numCommands << " completed." << endl; inFile >> command; }; cout << "Testing completed." << endl; inFile.close(); outFile.close(); return 0; }
********Heap.h********
// Test driver #include #include typedef int ItemType; #include "PQType.h" #include
using namespace std;
int main() {
ifstream inFile; // file containing operations ofstream outFile; // file containing output string inFileName; // input file external name string outFileName; // output file external name string outputLabel; string command; // operation to be executed ItemType item; PQType queue(5); int numCommands;
// Prompt for file names, read file names, and prepare files cout << "Enter name of input command file; press return." << endl; cin >> inFileName; inFile.open(inFileName.c_str());
cout << "Enter name of output file; press return." << endl; cin >> outFileName; outFile.open(outFileName.c_str());
cout << "Enter name of test run; press return." << endl; cin >> outputLabel; outFile << outputLabel << endl;
inFile >> command;
numCommands = 0; while (command != "Quit") { try { if (command == "Enqueue") { inFile >> item; queue.Enqueue(item); outFile << item << " is enqueued." << endl; } else if (command == "Dequeue") { queue.Dequeue(item); outFile<< item << " is dequeued. " << endl; } else if (command == "IsEmpty") if (queue.IsEmpty()) outFile << "Queue is empty." << endl; else outFile << "Queue is not empty." << endl; else if (command == "IsFull") if (queue.IsFull()) outFile << "Queue is full." << endl; else outFile << "Queue is not full." << endl; else if (command == "MakeEmpty") queue.MakeEmpty(); } catch (FullPQ) { outFile << "FullQueue exception thrown." << endl; } catch (EmptyPQ) { outFile << "EmtpyQueue exception thrown." << endl; } numCommands++; cout << " Command number " << numCommands << " completed." << endl; inFile >> command; }; cout << "Testing completed." << endl; inFile.close(); outFile.close(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started