Question

Trace the C++ program below showing all output in the order that it is displayed. If...

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

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Create a flowchart for the program below and Trace the program below with input of...
1) Create a flowchart for the program below and Trace the program below with input of 3 and then again with input of 5. #include <iostream> using namespace std; int Fall(int x, int m) { int Xm = 1, i=x; while(i>=x-m+1) { Xm = Xm*i; i=i-1; } return Xm; } int Delta(int x, int m) { int ans = 0; ans = Fall(x+1,m); ans = ans - Fall(x,m); return ans; } void main() { int x = 0, m =...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
Analyze the following programs and write down the output of the program. Please print every character...
Analyze the following programs and write down the output of the program. Please print every character (including whitespace character) clearly!       # include <iostream> using namespace std;   int fun( int a ) {       int b = a * 2;       return b;   }   int main()   {       int y = 5;       cout << fun(y) << endl;       cout << fun(-- y) << endl;       cout << fun(y--) << endl;       cout << y <<endl;           return 0;   }
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
Data Structures using C++ Consider the classes QueueADT and ArrayQueueType: QueueADT: #ifndef QUEUEADT_H #define QUEUEADT_H template...
Data Structures using C++ Consider the classes QueueADT and ArrayQueueType: QueueADT: #ifndef QUEUEADT_H #define QUEUEADT_H template <class ItemType> class QueueADT { public:        // Action responsibilities        virtual void resetQueue() = 0;           // Reset the queue to an empty queue.           // Post: Queue is empty.        virtual void add(const ItemType& newItem) = 0;           // Function to add newItem to the queue.           // Pre: The queue exists and is not full.          ...
Complete the missing code for the constructors as indicated in the comments in all three header...
Complete the missing code for the constructors as indicated in the comments in all three header files. C++ mainDriver.cpp #include <string> #include "Address.h" #include "Date.h" #include "Person.h" using namespace std; int main() {    Person p1;    Person p2("Smith", "Bobby", "[email protected]", 111, "Main St", "Clemson",            "SC", 29630, 1, 31, 1998);    cout << endl << endl;    p1.printInfo();    p2.printInfo();    return 0; } Person.h #ifndef PERSON_H #define PERSON_H #include <iostream> #include <string> using namespace std; class...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void modifyArray( int [ ], int );    void modifyElement ( int );      int main( ) {   const int arraySize = 8;   int a[arraySize] = { 2, -2, 10, -3, -1 ,0, 10, -5 };      modifyArray ( a, arraySize);      for ( int i =0; i < arraySize; i++)               cout << a[i] << ‘  ’;         modifyElement ( a[4] );          for ( int i =0; i <...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I feel like I know how to write that. What I'm having trouble with is implementing two files the professer gave us. I would appreicate any help in understanding their purpose as in if Im supposed to take information from those files or give it information. Thank you! I have attatched the homework instructions and the two files given. Implementation The main program, called calculator.cpp...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment 2 (karatsuba.cpp) in Canvas (please do not rename file or use cout/cin statements in your solution). As a reminder, the algorithm uses recursion to produce the results, so make sure you implement it as a recursive function. Please develop your code in small The test program (karatsuba_test.cpp) is also given. PLEASE DO NOT MODIFY THE TEST FILE. KARATSUBA.CPP /* Karatsuba multiplication */ #include <iostream>...
Please fill in the blank bolded below that would be the best choice for this program....
Please fill in the blank bolded below that would be the best choice for this program. #include <iostream> using namespace std; const int size = 100000; class TheBig { public: double operator[](int index) const {return (theData[index]);} private: double theData[size]; }; void firstToBeThe( ______________________________________________________) { for (int i = 0; i <size; i++) cout << value[i] <<endl; } int main() { TheBig one; firstToBeThe(one); }