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 filesDO 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 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 passbyreference. 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:
explicit testing: which tests all possible combinations of all states and operations
random testing which randomly executes every possible operation a number of times proportional to your ADT's size for example random operations for size for size 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 oneandonlyone return.
If statements should not have returns in them.
If you use exception handling, make sure to follow the rule of oneandonlyone logical operation per try ie one operation that can throw That means if your try has more than 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 s or
s of times!
Use random operations.
int choice;
for int i ; i STACKSIZERMULTIPLIER; i
choice rand CHOICES ;
switch choice
case :
case :
push here
break;
case :
case :
pop here
break;
case :
peek here
break;
case :
isempty here
break;
Example The Stack
#define STACKSIZE
class Stack
public:
Stack; constructor
Stack; destructor
int pop;
int peek;
bool pushint;
bool isEmpty;
private:
int top;
int stackSTACKSIZE;
; 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 ; i STACKSIZEMULTIPLIER; i
value randomeint;
if stackpushvalue
cout "pushed: value endl;
else
cout "overflow error: value not pushed" endl;
cout endl;IntStack : top Constructor to initialize the stack
bool pushint x
bool pushed false;
if top MAXSIZE
arrtop x;
pushed true;
return pushed;
Function to remove the top element from the stack
int pop
if top
throw ; Stack Underflow
return arrtop;
Function to return the top element of the stack
int peek
if top
return ; Stack is Empty
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
