Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Testing) Answer this question with respect to only the method Push using exactl

ID: 3864984 • Letter: #

Question

(Testing) Answer this question with respect to only the method Push using exactly two characteristics where each characteristic has two blocks in its partition.

2. Derive input space partitioning tests for the GenericStack class with the fol- lowing method signatures: public Genericstack 0; public void Push (0bject x); public object Pop 0; public boolean lsEmt 0; Assume the usual semantics for the stack. Try to keep your partitioning sim- ple, choose a small number of partitions and blocks. (a) Define characteristics of inputs (b) Partition the characteristics into blocks (c) Define values for the blocks

Explanation / Answer

Answer:

#include <iostream>
using namespace std;

const int MAX_SIZE = 10;

template <class StackType> class stack {
StackType input[MAX_SIZE];
int value;

public:
stack() {
     value = 0;
}
    void push(StackType take)
    {
      if(value==MAX_SIZE) {
        cout << "Stack is full. ";
        return;
      }
      input[value] = take;
      value++;
    }

    StackType pop()
    {
      if(value==0) {
        cout << "Stack is empty. ";
        return 0;
      }
      value--;
      return input[value];
    }
};

int main() {
stack<char> value1, value2;

value1.push('b');
value2.push('y');
value1.push('j');
value2.push('f');

for(int i=0; i<3; i++)
     cout << "Pop value1: " << value1.pop() << " ";
for(int i=0; i<3; i++)
     cout << "Pop value2: " << value2.pop() << " ";

stack<double> dvalue1, dvalue2;

dvalue1.push(1.9);
dvalue2.push(7.2);


for(int i=0; i<3; i++)
     cout << "Pop dvalue1: " << dvalue1.pop() << " ";
for(int i=0; i<3; i++)
     cout << "Pop dvalue2: " << dvalue2.pop() << " ";

return 0;
}