Share
Explore BrainMass

C++ Output Functions

C++. See attached file for full problem description.

Question 1

What would the operation isEmptyStack return if applied to the stack above?

0

5

true

false

Question 2

template<class Type>
void stackType<Type>::operation1(const Type& newItem)
{
if(!isFullStack())
{
list[stackTop] = newItem;
stackTop++;
}
else
cerr<<"Cannot add to a full stack."<<endl;
}

Which stack operation does operation1 above define?

top

pop

push

initializeStack

Question 3

Stack s;

s.push(3);
s.push(7);
x = s.pop();
s.push(5);
y = s.pop();
z = s.pop();

Given the sequence of operations above, what is the value of x?

0

3

5

7

Question 4

Given the sequence of operations above, what is the value of z?

0

3

5

7

Question 5

If you applied the operation pop to the stack above, which book would be left on top of the stack?

Applied Math

World History

Chemistry

English

Question 6

What is the effect of the operation empty of the stack container class?

To empty the stack

Return the number of items in the stack

Return true if the stack is empty and false otherwise

Return true if the stack is nonempty and false otherwise

Question 7

Which operation would you use to return the Applied Math book from the stack above?

top

pop

push

return

Question 8

What is the value of the postfix expression: 5 4 * 3 + ?

17

23

27

35

Question 9

What is the equivalent postfix expression for the infix expression: (x - y) * (v + w)?

x v * y w - +

- x y + v w *

x * y + v * w -

x y - v w + *

Question 10

#include <iostream>
#include "myStack.h"

using namespace std;

int main()
{
stackType<int> intStack(50);
stackType<int> tempStack;

intStack.push(18);
intStack.push(21);
intStack.push(25);

tempStack = intStack;

while(!tempStack.isEmptyStack())
{
cout<<tempStack.top()<<""; //output 1
tempStack.pop();
}

cout<<endl;

cout<<intStack.top()<<endl; //output 2

return 0;
}

What is output 1 above?

18 21 25

21 18 25

25 21 18

25 18 21

Attachments

Solution Summary

The C++ output functions are examined. The equivalent postfix expression for the infix expression is determined.

$2.19