Question

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

tacks. 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 doing are unpredictable, describe what happens and abort the program at that point. Assume the Stack class is fully defined in an appropriate header and implementation file. The effect of the functions (methods) is as follows: constructor - creates an empty stack empty - returns true if the stack is empty, false otherwise push - adds the specified element to the top of the stack display - displays every stack element on the specified stream, top to bottom order pop - removes the top element of a stack; attempting to pop an element from an empty stack causes an error condition and immediately terminates the program. top - returns the top element of the stack but does not remove it bool alpha - a flag that causes the words true or false to be displayed for a bool variable

#include <iostream>
using namespace std;
#include "Stack.h"
int main(void)
{int jimmy_carter, bill_clinton;
jimmy_carter=0;
Stack george_w_bush;
for (bill_clinton=17; bill_clinton>13; bill_clinton--)
{ george_w_bush.push(bill_clinton%3*2-2);
jimmy_carter=jimmy_carter+george_w_bush.top();
george_w_bush.push(george_w_bush.top()+2);
jimmy_carter=jimmy_carter+george_w_bush.top();
cout<<"Contents of george_w_bush "<<endl;
george_w_bush.display(cout);
cout<<"jimmy carter is "<<jimmy_carter<<endl;
}
while (!(george_w_bush.empty()))
{cout<<"popping "<<george_w_bush.top()<<endl;
jimmy_carter=jimmy_carter-george_w_bush.top();
george_w_bush.pop();
cout<<"popping "<<george_w_bush.top()<<endl;
george_w_bush.pop();
cout<<"Contents of george_w_bush: "<<endl;
george_w_bush.display(cout);
cout<<"jimmy_carter is now "<<jimmy_carter<<endl;
}
cout<<"at end jimmy_carter is "<<jimmy_carter<<endl;
cout<<boolalpha<<"george_w_bush is empty
"<<george_w_bush.empty()<<endl;
return 0;
}

Homework Answers

Answer #1

Output is as follows:

Contents of george_w_bush
4
2
jimmy_carter is 6
Contents of george_w_bush
2
0
4
2
jimmy_carter is 8
Contents of george_w_bush
0
-2
2
0
4
2
jimmy_carter is 6
Contents of george_w_bush
4
2
0
-2
2
0
4
2
jimmy_carter is 12
popping 4
popping 2
Contents of george_w_bush:
0
-2
2
0
4
2
jimmy_carter is now 8
popping 0
popping -2
Contents of george_w_bush:
2
0
4
2
jimmy_carter is now 8
popping 2
popping 0
Contents of george_w_bush:
4
2
jimmy_carter is now 6
popping 4
popping 2
Contents of george_w_bush:
jimmy_carter is now 2
at end jimmy_carter is 2
george_w_bush is empty true

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
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...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h"...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h" template StackLinked::StackLinked (int maxNumber) { } template StackLinked::StackLinked(const StackLinked& other) { } template StackLinked& StackLinked::operator=(const StackLinked& other) { } template StackLinked::~StackLinked() {    clear(); } template void StackLinked::push(const DataType& newDataItem) throw (logic_error) {    } template DataType StackLinked::pop() throw (logic_error) { } template void StackLinked::clear() {    StackNode* t;    while ( top != NULL)    {        t = top;       ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity  ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity   Code   Description   Project   File   Line   Suppression State Warning   C6385   Reading invalid data from 'DynamicStack': the readable size is '(unsigned int)*28+4' bytes, but '56' bytes may be read.   Here is the C++ code were I'm having the warning. // Sstack.cpp #include "SStack.h" // Constructor SStack::SStack(int cap) : Capacity(cap), used(0) {    DynamicStack = new string[Capacity]; } // Copy Constructor SStack::SStack(const SStack& s) : Capacity(s.Capacity), used(s.used)...
C++ program that Create a struct called car that has the following data members (variables): -...
C++ program that Create a struct called car that has the following data members (variables): - Color //color of the car - Model //model name of the car - Year //year the car was made - isElectric //whether the car is electric (true) or not (false) - topSpeed //top speed of the car, can be a decimal. code i have done struct not working properly. #include <iostream> using namespace std; struct Car { string color; string model_number; int year_model; bool...
Complete the following C program to solve the parenthesis matching problem using a stack. We studied...
Complete the following C program to solve the parenthesis matching problem using a stack. We studied the problem and the algorithm in class. Given a sequence of chars (symbols), check if each “(”, “{”, or “[” is paired with a matching “)”, “}”, or “[”. For example, correct: ( )(( )){([( )])}     correct: (( )(( ))){([( )])}   incorrect: )(( )){([( )])}     incorrect: ({[ ])}     incorrect: (   #include <stdio.h> #include <stdlib.h> #define size 100 void push(char *s, int* top, char element);...
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.          ...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
Data Structures using C++ Consider the following class #ifndef LINKEDQUEUETYPE_H #define LINKEDQUEUETYPE_H #include <iostream> #include <new>...
Data Structures using C++ Consider the following class #ifndef LINKEDQUEUETYPE_H #define LINKEDQUEUETYPE_H #include <iostream> #include <new>    #include <cstdlib> #include "QueueADT.h" using namespace std; // Definition of the node template <class ItemType> struct NodeType {        ItemType info;        NodeType<ItemType> *next; }; template <class ItemType> class LinkedQueueType: public QueueADT<ItemType> { public:        // Constructor        LinkedQueueType();           // Default constructor.           // Post: An empty queue has been created. queueFront = NULL;           //       queueBack = NULL;...
Something is either messed up in my operator overload <<, covertopostfix function, or my main output....
Something is either messed up in my operator overload <<, covertopostfix function, or my main output. Cannot figure it out. please help. Please comment your changes too. Program below is supposed to be outputting like this: InFix is:   A+B-C Post fix is:   A B + C - InFix is:   A+C Post fix is:   A C + InFix is:   x*(y+z)-(w+t) Post fix is:   x y z + * w t + - InFix is:   A+B*(C+D)-E/F+G+H Post fix is:   A B C...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT