Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ANSWER IN C++ i will upvote DO NOT EDIT OR MESS WITH THE MAIN FILE OR THE DEArraySTACK.h THOSE ARE READ ONLY USE THOSE VARIABLES

ANSWER IN C++ i will upvote DO NOT EDIT OR MESS WITH THE MAIN FILE OR THE DEArraySTACK.h THOSE ARE READ ONLY USE THOSE VARIABLES TO MAKE THE .CPP FILE PLEASE ANSWER CORRECTLY THANK YOU
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Task You are to implement a double-ended stack. The rules of operation/implementation for the double-ended stack are as follows: - Stack operations are allowed at each end. - The stack will be implemented as a class named: DEArraySTACK. - As the name implies, the underlying data storage will be in a member array. - The stack has a total of 50 integer elements (MAXELEMENTS=50). - The stack will accept positive non-zero values only. - All empty locations (either initially or after being vacated) will contain a value of 0 (zero). You can think of this as two separate stacks, but implemented in a single, underlying array. Each stack is independent. Furthermore, you are constrained in the way you must implement storing the data. This may not necessarily be the best way to do it, but you are required to do it this way The array starts with all zeros. the 'top' of the left ("front') stack will always be in data [0]. The 'top' of the right ("back') stack will always b in data [MAXELEMENTS - 11. When you push a new element onto the left stack, all successive values must cascade to the right. When you push an element to the right stack, all elements must cascade to the left. When you remove (pop) an element from either stack, you likewise must cascade the data, and you must also overwrite non-valid elements in the array to zero For example, assume that we had an array size of 10 . It would start with all zeros: You will write the missing member functions. The mainO [main.cpp] and class definition [DEArraySTACK.h] are provided and will remain unchanged: The main0 accepts an integer (02) from the console input field that corresponds to one of three testbenches. They are: - 0= easy (pushing and popping as a single ended stack - front only) - 1= medium (pushing and popping as a double-ended stack) - 2= harder (pushing and popping as a double-ended stack with overruns) The output of the hardest testbench is shown here: 2 Hard Test Use the above output as a guide. Remember that you can construct any testbench you like by copying and pasting individual test elements from any of the test benches: If you attempt to push a 0 or negative value or attempt to push into a full stack (elements >50 ), you should see the appropriate error message shown: Elements are positive non-zero values. Cannot paah. Max elements reached, Cannot push. You can see those messages embedded in the hard testbench output shown above. As with all programming projects, you should should have formal code that is properly commented and include headers. Your headers and comments will be evaluated after your code is submitted. Proper code documentation counts for 10% of this assignment. Please see the attached document if more information is needed. using namespace std; \#define MAXELEMENTS 50 11 list max length =50 \#include "DEArraySTACK,h" void easytest(DEArraySTACK "testStack); void meditest(DEArraySTACK "testStack); void hardtest(DEArraySTACK "testStack); ll description: this moin( tests a double-ended stack dAOT. the user is prompted for one of three testbenches. the list is to have a maximum of 50 elements. Il notes: this file is not to be edited. int main() \{ DEArraySTACK* myStack = new DEArraySTACKC); I instantiate double-ended Stack with array object int x8; cin x;//accept user choice if (x0) easytest(myStack); if (x1) meditest(myStack); if (x2) hardtest(myStack); Il harder double-ended push-pop overrun test return 8 \} 11 function: easytest(DEArraySTACK *testStack) 1/ purpose: performs low impact testing 1/ void easytest(DEArraySTACK *testStack) \{ cout "Easy Test " endl " -" end e end ; cout "Starting point: " endl; testStack->printStack(); /l Print the stack testStack->printElementCounts(); I/ Print the element counts cout "pushFront (101)" " endi; Il Push 101 onto the front stack testStack pushFront (101); testStack->pintStack(); I/ Print the stack testStack->printElementCounts(); I/ Print the element counts cout "pushFront (102) " endl I/ Push 102 onto the front stack testStack pushFront (102); testStack printStack(); I/ Print the stack testStack printElementCountsO; cout "popFront( )= " testStack->popFront( ) endl; I/ Pop the front stack testStack->printStack(); // Print the stack testStack->printElementCountsO; /l Print the element counts cout "popFront ()= " testStack->popFront ( endl; I/ Pop the front stack testStack->printStack ; _ Print the stack testStack-printElementCountsO; // Print the element counts return: 82I function: meditest(DEArraySTACK "testStack) 83 / purpose: performs medium impact testing 85 void meditest(DEArraySTACK "testStack) \{ 86 cout "Medium Test " end "... end endl; 95 testStack->printStack (101) Il Print the stack I/ Print the element counts teststack pushfront (102); I/ Push 102 onto the front stack 101102103testStack->printStackO;testStack->printElementCountsO;/Printthestack cout "popFront O" testStack->popfront () endl; I/ Pop the front stack testStack printStack testStack->printElementCounts O; /I Print the stack I/ Print the element counts cout "pushFront (103)"e endi; testStack pushfront (103); II Push 103 onto the front stack testStack->printstack(); testStack->printElementCounts O; Print the stack II Print the element counts cout "pushBack(901) " endl; testStack->pushBack(901); testStack printstackO; testStack printElementCounts 0 ; Print the stack cout cout "pushBack (902) " endl; teststack->pushBack(902); testStack->printStack(); testStack printElementCountsO; Print the stack cout "popBack() - " testStack->popiackO endl; I Pop the back stack testStack printStack ; testStack->printElementCounts O; I Print the stack If Print the element counts. cout "pushBack(903) " endi; testStack >pushBack(903): U Push 903 anto the back stack 128 testStack->printElementCounts(); 1 print the stack teststack-printstack; Fl Frtnt the stack testStack->printElementCounts C; II Print the element counts return; I/ function: hardtest (DEArraySTACK "testStack) Il purpose: performs high impoct testing void hardtest (DEArraySTACK "testStack) \{ cout "Hard Test " end "....... " endl end ; cout "Starting point: " endl; // Print the enpty stack testStack-iprintstackQ; _ Print the stack test5tock->printElementCounts O; Print the element counts cout "pushFront (101)= endl; 1 Push 101 onto the front stack testStack->pushFront (101); teststack->printstack( ll Print the stack testStack->printElementCounts O /I Print the element counts cout "popFrontO =n testStack-spopfront O endl; I Pop the front stack teststack->printStack ; testStack->pintElementCountsO; / Print the element counts cout "popfront O= " testStack->popFront O endl; I/ Pop the front stack testStack->printStackO; / Print the stack testStack->printElementCountsO; / Print the element counts cout pushFront(101) " endl; / Push 101 onto the front stack teststack-pushFront (101); testStack->printStack ; Cl Print the stack testStock > printElementCountsO: // Print the element counts cout pushfront(102)" / Push 102 onto the front stack testStack pushFront (102); testStack->printStack ( ) 1/ Print the stack testStack printElementCounts O; V Print the element counts I cout "popfrontO = = teststack-spopfront( ) endi; I/ Pop the front stack teststack-printstack ); ll Print the stack testStack->printElementCounts O; / Print the element counts cout "pushfront(103) " endl; Push 103 onto the front stack teststack pushfront (103); teststack->printstack(); II DEARraySTACK class I/ Double-ended stack abstract data type implemented with array data structure 11 class DEArraySTACK \& private: int data[MAXELEMENTS]; // Array data block of max MAXELEMENT positive integers int elementsfront; // Element count for front stack int elementsBack; 1/ Element count for back stack public: DEARTaYSTACKO { for (int i=0;i i MAXELEMENTS; i++ ) data [i]=0; elementsFront 0; elementsBack=0; } II Empty locations are to be set to zero bool pushfront(int j ); I/ Push integer onto front of DE stack. If successful, 1/ return true. If at MAXELEMENTS, return folse and 11 specified error message. If j is or negative, return 11 false and specified error message. int popfront O; 1/ Pop integer from front of OE stack. If successful, Il return value of popped element. If empty, return 1. int topFront O; I/ Return integer from front of DE stack. Do not 1/ alter the stack. If empty, return 1. bool pushBack(int j); // Push integer onto rear of DE stack. If successful, II return true. If at MAXELEMENTS, return false and 1/ specified error message. If j is or negative, return Il false and specified error message. int popBack(); /I Pop integer fram front of DE stack. If successful, I/ return value of popped element. If empty, return 1. int top Back O; II Return integer from back of OE stack. Do not Il alter the stack. If empty, return 1. void printstack@; void printElement Counts O; \#include siostrean> using namespace std; \#define MAXELEMENTS 50 1/ list max length =50 \#include "DEArroySTACK.h" I/ DEArraySTACK class member functions II Double-ended stack abstract data type implemented with array data structure bool DEArraySTACK::pushFront(int j) \{ / Push integer anto front of DE stack. If successful if (topFront = topBack - 1) \{ cout "Error: Stack overflow" end; Il return true. If at return; Il specified error message. If j is or negative, retu 3 Il false and specified error message. topfront;i; /shift all elements to right for (int i= topFront; 1>0;1){ data[i]=data[i1] J data [0]= value; 3 int DEArraySTACK: ipopFrontO. I Pop integer from front of OE stack. If successful if (topfront =1 ) I return value of popped element. If enp cout "Error: Stack overflow" endl; Il Vacated locations or return 0; 3 int value - data[0]; l/shift all volue to left for (int i=0;1MAXELEMENTS-1-elementsBack; i--) data[i]=data[i-1]; // Shift back da data[MAXELEMENTS-1-elementsBack] 0 ; I Set vacated value to ; elementsBack ; return topBack; DEArraySTACK: : topBack() I/ Return integer from back of DE stack. Do not THIS IS COUPLETED FOR YOU id DEArraySTACK: :printStackO) for (int i=0; iAMAXELEMENTS; i++ ) cout data[i] ";; cout endi; THIS IS COMPLETEO FOR YOU id DEArraySTACK: :printElementCounts( \{ cout "elementsFront " " elementsFront; cout " elementsBack=" elementsBack end endl

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Rules In Database Systems Third International Workshop Rids 97 Sk Vde Sweden June 26 28 1997 Proceedings Lncs 1312

Authors: Andreas Geppert ,Mikael Berndtsson

1997th Edition

3540635165, 978-3540635161

More Books

Students also viewed these Databases questions