1.Use the ArrayStackType class (implementation of stacks as arrays) given to you in Week 7 Day 3 Example Programs. What output do you expect for the following program segment (without actually executing the program in Visual C++)?

ArrayStackType< int> stack;
int x, y;

x = 4;
y = 0;
stack.push(7);
stack.push(x);
stack.push(x + 5);
y = stack.top();
stack.pop();
stack.push(x + y);
stack.push(y - 2);
stack.push(3);
x = stack.top();
stack.pop();

cout << "x = " << x << endl;
cout << "y = " << y << endl;

while ( !stack.isEmpty() )
{
cout << stack.top() << endl;
stack.pop();
}

2.Use the ArrayStackType class (implementation of stacks as arrays) given to you in Week 7 Day 3 Example Programs. Consider the following statements:

ArrayStackType< int> stack;
int x;

Suppose that the input is:

14 45 34 23 10 5 -999

What output do you expect for the following program segment (without actually executing the program in Visual C++)?

stack.push(5);

cin >> x;
while ( x != -999 )
{
if ( x % 2 == 0 )
{
if ( !stack.isFull() )
stack.push(x);
}
else
cout << "x = " << x << endl;
cin >> x;
}

cout << "Stack Items: ";
while ( !stack.isEmpty() )
{
cout << " " << stack.top();
stack.pop();
}
cout << endl;

3.Use the ArrayStackType class (implementation of stacks as arrays) given to you in Week 7 Day 3 Example Programs. What output do you expect for the following program segment (without actually executing the program in Visual C++)?

#include < iostream>
#include < string>
#include "ArrayStackType.h"
using namespace std;

template < class Type>
void mystery(ArrayStackType< Type>& s, ArrayStackType< Type>& t);

int main()
{
ArrayStackType< string> s1;
ArrayStackType< string> s2;
string list[] = {"Winter", "Spring", "Summer", "Fall",
"Cold", "Warm", "Hot"};

for (int i = 0; i < 7; i++)
s1.push(list[i]);

mystery(s1, s2);

while ( !s2.isEmpty() )
{
cout << s2.top() << " ";
s2.pop();
}
cout << endl;
}

template < class Type>
void mystery(ArrayStackType< Type>& s, ArrayStackType< Type>& t)
{
while ( !s.isEmpty() )
{
t.push(s.top());
s.pop();
}
}

4.What is the effect of the following statements? If a statement is invalid, explain why it is invalid. The classes StackADT, ArrayStackType, LinkedStackType are given to you in Week 7 Day 3 Example Programs.

(a)StackADT< int> newStack;

(b)ArrayStackType< double> sales;

(c)ArrayStackType< string> names;

(d)LinkedStackType< int> numStack(50);

5.Use the ArrayStackType class (implementation of stacks as arrays) given to you in Week 7 Day 3 Example Programs. What output do you expect for the following program segment (without actually executing the program in Visual C++)?

#include < iostream>
#include < string>
#include "ArrayStackType.h"
using namespace std;

void mystery(ArrayStackType< int>& s, ArrayStackType< int>& t);

int main()
{
int list[] = {5, 10, 15, 20, 25};

ArrayStackType< int> s1;
ArrayStackType< int> s2;
for (int i = 0; i < 5; i++)
s1.push(list[i]);

mystery(s1, s2);

while ( !s2.isEmpty() )
{
cout << s2.top() << " ";
s2.pop();
}
cout << endl;
}

void mystery(ArrayStackType< int>& s, ArrayStackType& t)
{
while ( !s.isEmpty() )
{
t.push(2 * s.top());
s.pop();
}
}

6.Use the LinkedStackType class (implementation of stacks as linked lists) given to you in Week 7 Day 3 Example Programs. What output do you expect for the following program segment (without actually executing the program in Visual C++)?

LinkedStackType< int> myStack;

myStack.push(10);
myStack.push(20);
myStack.pop();
cout << myStack.top() << endl;
myStack.push(25);
myStack.push(2 * myStack.top());
myStack.push(-10);
myStack.pop();

LinkedStackType< int> tempStack;

tempStack = myStack;

while ( !tempStack.isEmpty() )
{
cout << tempStack.top() << " ";
tempStack.pop();
}
cout << endl;
cout << myStack.top() << endl;

7.Write the definition of the function template printListReverse that uses a stack to print a linked list in reverse order. Assume that this function is a member of the LinkedListType as given in Week 6 Day 1 Example Programs.

8.Write the definition of the function template second that takes as a parameter a stack object and returns the second item (from the bottom) of the stack. The original stack remains unchanged.

9.Use the ArrayQueueType class (implementation of queues as arrays) given to you in Week 7 Day 3 Example Programs. What output do you expect for the following program segment (without actually executing the program in Visual C++)?

ArrayQueueType< int> queue;
int x, y;

x = 4;
y = 5;
queue.add(x);
queue.ddd(y);
x = queue.front();
queue.add(x + 5);
queue.add(9);
queue.add(x);
queue.remove();
queue.add(y - 2);

cout << "queue Items: ";

while ( !queue.isEmpty() )
{
cout << queue.front() << " ";
queue.remove();
}
cout << endl;

10.Use the ArrayStackType and ArrayQueueType classes given to you in Week 7 Day 3 Example Programs. Consider the following statements:

ArrayStackType< int> stack;
ArrayQueueType< int> queue;
int x;

Suppose that the input is:

15 28 14 22 64 35 19 32 7 11 13 30 -999

What output do you expect for the following program segment (without actually executing the program in Visual C++)?

stack.push(0);
queue.add(0);
cin >> x;

while ( x != -999 )
{
switch (x % 4)
{
case 0:
stack.push(x);
break;
case 1:
if ( !stack.isEmpty() )
{
cout << "Stack Item = " << stack.top()
<< endl;
stack.pop();
}
else
cout << "Sorry, the stack is empty." << endl;
break;
case 2:
queue.add(x);
break;
case 3:
if ( !queue.isEmpty() )
{
cout << "Queue Item = " << queue.front()
<< endl;
queue.remove();
}
else
cout << "Sorry, the queue is empty." << endl;
break;
}//end switch

cin >> x;
}//end while

cout << "Stack Items: ";
while ( !stack.isEmpty() )
{
cout << stack.top() << " ";
stack.pop();
}
cout << endl;

cout << "Queue Items: ";
while ( !queue.isEmpty() )
{
cout << queue.front() << " ";
queue.remove();
}
cout << endl;

11.Use the ArrayStackType and ArrayQueueType classes given to you in Week 7 Day 3 Example Programs. What does the following function do?

void mystery(ArrayQueueType< int>& q)
{
ArrayStackType< int> s;

while ( !q.isEmpty() )
{
s.push(q.front());
q.remove();
}

while ( !s.isEmpty() )
{
q.add( 2 * s.top() );
s.pop();
}
}

12.What is the effect of the following statements? If a statement is invalid, explain why it is invalid. The classes QueueADT, ArrayQueueType, LinkedQueueType are given to you in Week 7 Day 3 Example Programs.

(e)QueueADT< int> newQueue;

(f)ArrayQueueType< double> sales;

(g)ArrayQueueType< string> names;

(h)LinkedQueueType< int> numQueue;

LinkedQueueType< int> numQueue2(numQueue);

13.Use the LinkedQueueType class given to you in Week 7 Day 3 Example Programs. What output do you expect for the following program segment (without actually executing the program in Visual C++)?

LinkedQueueType< int> queue;

queue.add(10);
queue.add(20);
cout << queue.front() << endl;
queue.remove();
queue.add(2 * queue.back());
queue.add(queue.front());
queue.add(5);
queue.add(queue.back() - 2);

LinkedQueueType< int> tempQueue;

tempQueue = queue;

while ( !tempQueue.isEmpty() )
{
cout << tempQueue.front() << " ";
tempQueue.remove();
}
cout << endl;
cout << queue.front() << " " << queue.back() << endl;

14.Use the ArrayQueueType class given to you in Week 7 Day 3 Example Programs. Suppose that queue is an ArrayQueueType object and MAX_QUEUE_SIZE = 100. Also, suppose that the value of queueFront is 50 and the value of queueBack is 99.

(a)What is the value of length?

(b)What are the values of queueFront and queueBack after adding an item to queue?

(c)What are the values of queueFront and queueBack after removing an item from queue?

15.Use the ArrayQueueType class given to you in Week 7 Day 3 Example Programs. Suppose that queue is an ArrayQueueType object and MAX_QUEUE_SIZE = 100. Also, suppose that the value of queueFront is 99 and the value of queueBack is 25.

(a)What is the value of length?

(b)What are the values of queueFront and queueBack after adding an item to queue?

(c)What are the values of queueFront and queueBack after removing an item from queue?

16.Use the ArrayQueueType class given to you in Week 7 Day 3 Example Programs. Suppose that queue is an ArrayQueueType object and MAX_QUEUE_SIZE = 100. Also, suppose that the value of queueFront is 25 and the value of queueBack is 75.

(a)What is the value of length?

(b)What are the values of queueFront and queueBack after adding an item to queue?

(c)What are the values of queueFront and queueBack after removing an item from queue?

17.Use the ArrayQueueType class given to you in Week 7 Day 3 Example Programs. Suppose that queue is an ArrayQueueType object and MAX_QUEUE_SIZE = 100. Also, suppose that the value of queueFront is 99 and the value of queueBack is 99.

(a)What is the value of length?

(b)What are the values of queueFront and queueBack after adding an item to queue?

(c)What are the values of queueFront and queueBack after removing an item from queue?

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.