Trace the C++ program below showing all output in the order that it is displayed. If anything happens that makes it impossible to accomplish an operation or the results of so doingare unpredictable, describe what happens and abort the program at that point. Assume the Queue class is fully defined in an appropriate header and implementation file. The effect of the functions (methods) is as follows
- Constructor - creates an empty queue
#include <iostream>
#include using namespace std;
#include "Queue.h"
int main(void)
{ int george_hw_bush, ronald_reagan;
Queue gerald_ford;
cout<<"Program begins"<< endl;
cout<<boolalpha<<"gerald_ford is empty "<<
gerald_ford.empty()<<endl;
ronald_reagan=0;
for (george_hw_bush=12; george_hw_bush>=9; george_hw_bush--)
{cout<<"george_hw_bush is "<<george_hw_bush<<endl;
gerald_ford.enqueue(george_hw_bush%5+3);
gerald_ford.enqueue(gerald_ford.front()+6);
gerald_ford.display(cout);
ronald_reagan=ronald_reagan+george_hw_bush-gerald_ford.front();
cout<<"ronald_reagan is "<<ronald_reagan<<endl;
}
ronald_reagan=0;
while (!(gerald_ford.empty()))
{cout<<"adding "<<gerald_ford.front()<<endl;
ronald_reagan=ronald_reagan+gerald_ford.front();
gerald_ford.dequeue();
}
cout<<"at end ronald_reagan is "<<ronald_reagan<<endl;
return 0;
}
- empty - returns true if the queue is empty, false otherwise
- enqueue - adds the specified element to the back of the queue
- display - displays all queue elements on the specified stream front to back order
- front - returns but does not remove the front element of the queue
- dequeue - deletes the front element of the queue
Hello !
I have gone through your code, although I did not find any
general issue with the implementation but it is too hard for me or
anyone to decide whether all the functionality is working fine or
not without that Queue.h header file.
On your behalf I tried compliling the code and tried putting the
#include Queue.h in comment and tried fixing nomal errors that were
coming only because the header file is not present, but it seems
the header file ia all brain for this coding implementation.
I suggest you to add the header file along with the main program
from next time because every little piece of code plays a vital
role in code implementation.
Here is a Screenshot for the error issues I faced while compiling
the program.
Let me repeat it again, I did not find any general issue like
syntax error or logical error but due to unavailabilty of Queue.h
header file, your program is not functionable. So none of us can
trash it and check If anything happens that makes it impossible to
accomplish an operation or the results of so doingare
unpredictable, describe what happens and abort the program at that
point.
I hope it helps.
Get Answers For Free
Most questions answered within 1 hours.