modify the Queue.cpp file by implementing

profileThehonest
 (Not rated)
 (Not rated)
Chat

modify the Queue.cpp file by implementing
the details for the predicate function called isEqual(), which will take in two queues as parameters and will determine if they are equal. The prototype for this function is as follows:
template
void isEqual(queue &Q1, queue &Q1);
Note: The implementation should use while-loops and not a single line consisting of the built in equality operator.
Hint: Again, you only need to modify the areas in the Queue.cpp file by adding the necessary code to implement the TODO areas as noted in the comments. The prototype for the function and everything else in the program will remain unchanged. You must use the function signature for your implementation. Use two while-loops embedded within each other. Check if each item in the first queue is also in the second queue. If it is then set the equal variable to true.
Output: The output for the program after the function is implemented should appear as follows:
Queue 1: 10 30 20 40
Queue 2: 20 30 10 40
Queue 3: 10 30 20 40
3
Queue 4: 10 30 20 40 51
Q1 equals Q2=0
Q1 equals Q3=1
Q1 equals Q4=0
Q2 equals Q3=0
Q2 equals Q4=0
Q3 equals Q4=0
** Press any key to continue **
THE QUEUE.CPP FILE THAT NEEDS TO BE MODIFIED BELOW:
/**
* Queue.cpp - This program implements and tests the
* isEqual() predicate funciton.
*
* TODO: Include your name and course number here.
*
*/
#include
#include
#include
using namespace std;
template
void print(queue Q);
template
bool isEqual(queue Q1, queue Q2);
int main(int argc, char **argv)
{
bool equal = false;
// Declare queue variables
queue Q1;
queue Q2;
queue Q3;
queue Q4;
// Add some data to queue 1
Q1.push(10);
Q1.push(30);
Q1.push(20);
Q1.push(40);
// Add some data to queue 2
Q2.push(20);
Q2.push(30);
Q2.push(10);
Q2.push(40);
// Add some data to queue 1
Q3.push(10);
Q3.push(30);
Q3.push(20);
Q3.push(40);
// Add some data to queue 4
Q4.push(10);
Q4.push(30);
Q4.push(20);
Q4.push(40);
Q4.push(51);
cout << "Queue 1: ";
print(Q1);
cout << "Queue 2: ";
print(Q2);
cout << "Queue 3: ";
print(Q3);
cout << "Queue 4: ";
print(Q4);
equal = isEqual(Q1, Q2);
cout << "Q1 equals Q2=" << equal << endl;
equal = isEqual(Q1, Q3);
cout << "Q1 equals Q3=" << equal << endl;
equal = isEqual(Q1, Q4);
cout << "Q1 equals Q4=" << equal << endl;
equal = isEqual(Q2, Q3);
cout << "Q2 equals Q3=" << equal << endl;
equal = isEqual(Q2, Q4);
cout << "Q2 equals Q4=" << equal << endl;
equal = isEqual(Q3, Q4);
cout << "Q3 equals Q4=" << equal << endl;
cout << "\n** Press any key to continue **\n";
getchar();
return 0;
}
template
void print(queue Q)
{
// queue tmpQueue = Q;
Object tmpItem;
while (!Q.empty())
{
tmpItem = Q.front();
cout << " " << tmpItem;
Q.pop();
}
cout << endl;
return;
}
template
bool isEqual(queue Q1, queue Q2)
{
bool equal = false;
// TODO: Implement the detail of the funciton here.
return equal;
}




 

 

    • 7 years ago
    A+ Work
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      queueequal.zip