Question: The assignment is to create a working integer stack class with C + + , according to specifications and best practices, and to test it

The assignment is to create a working integer stack class with C++, according to specifications and best practices, and to test it thoroughly
Simple Int Stack Instructions:
Make 4 files(DO NOT make any other files): main.h, main.cpp, stack.h and stack.cpp
only attributes your stack may have are an integer array for the stack and a top integer to keep track of the top of the stack. No other attributes are allowed.
Make your stack size 10, and use a #define within the stack.h header file to do this Hint: This value is available outside the stack, you can use it in main for testing purposes.
The only public methods your stack should have are pop(), peek(), push(), isEmpty(). DO NOT MAKE ANY OTHER PUBLIC METHODS!
Testing: Use main to thoroughly test your stack. In main, you must write a comprehensive test suite which will thoroughly test your stack in an automated fashion (no user input).
Main.cpp and main() is your driver file and driver function. There Should only be one function in main, and no literals. Never use iostream or using namespace std; in main.
Complete all tests in main() to prove your stack works fully. You must test every possible operation in every possible combination and explicitly show your stack is fully functional and can handle underflow, overflow, incorrect input, multiple random operations in every combination.
The pop() and peek() functions will require you to show error somehow, and you cannot return an int to show error. One way to do this is exception handling ( The other way to do this, if you know how, is to use pass-by-reference. You may do it either way. push() should not be void.
Guide to proper testing:
Proper testing means you must execute every operation, in every possible combination, and in every possible state for the ADT in question. You must show what happens when your stack is pushed beyond its limits in both directions for all operations, and you must include hundreds or even thousands of random operations to do proper testing.
testing proceeds in two stages:
1) explicit testing: which tests all possible combinations of all states and operations
2) random testing which randomly executes every possible operation a number of times proportional to your ADT's size (for example 1000 random operations for size 10,10,000 for size 100, and so on).
Make sure to follow best practices for procedural and object oriented programming very closely.
Remember, main() is a driver function, so the rules are loosened a bit on what is or isn't allowed. For example, main() can be very long, and it is sometimes acceptable to repeat code in driver files.
Functions should have one-and-only-one return.
If statements should not have returns in them.
If you use exception handling, make sure to follow the rule of one-and-only-one logical operation per try (i.e. one operation that can throw). That means if your try has more than 1-3 lines of code in it, it's probably wrong, and a try should never have a loop inside of it.
Your methods should not print. Place the stack in underflow.
Execute, push, pop, peek, isEmpty
Make sure to do all operation multiple times
in this state.
Place the stack in overflow.
Execute, push, pop, peek, isEmpty
Make sure to do all operation multiple times
in this state.
Place the stack in neither overflow nor underflow.
Execute, push, pop, peek, isEmpty
Make sure to do all operation multiple times
in this state. Test your object / function / system 10,000s or
100,000s of times!
Use random operations.
int choice=0;
for (int i =0; i STACKSIZE*RMULTIPLIER; i++){
choice = rand()% CHOICES +1;
switch (choice){
case 1:
case 2:
// push here
break;
case 3:
case 4:
// pop here
break;
case 5:
// peek here
break;
case 6:
// isempty here
break;
}
} Example - The Stack
#define STACKSIZE 10
class Stack {
public:
Stack(); // constructor
-Stack(); // destructor
int pop();
int peek();
bool push(int);
bool isEmpty();
private:
int top;
int stack[STACKSIZE];
}; Example - Make Tests Automated
Never use user input!
Use defines and constants based on the object /
function / system being tested.
// testing filling the stack and overflow
cout "Filling stack..." endl;
for (int i =0; i STACKSIZE*MULTIPLIER; i++){
value = randome_int();
if (stack.push(value)){
cout "pushed: " value endl;
} else {
cout "overflow error: " value " not pushed" endl;
}
}
cout endl;IntStack() : top(-1){}// Constructor to initialize the stack
bool push(int x){
bool pushed = false;
if (top MAXSIZE -1){
arr[++top]= x;
}
pushed = true;
return pushed;
// Function to remove the top element from the stack
int pop(){
if (top 0){
throw -1; // Stack Underflow
}
}
return arr[top--];
// Function to return the top element of the stack
int peek(){
if (top 0){
return -1; // Stack is Empty
The assignment is to create a working integer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!