Question
C++ Programming. I already have the rest of the code written out just copy and paste the header and source files below into a project
C++ Programming. I already have the rest of the code written out just copy and paste the header and source files below into a project and complete the 2 "To Do" tasks. Please make sure both parts are fully answered and that you upload copyable code for each cpp or header file that was edited. Make sure it runs and compiles so I can give 5 stars
Files:
StackArray.cpp:
#include "StackArray.h"
template
template
template
template
template
template
}
template
template
template
template
// Array implementation. Outputs the data items in a stack. If the // stack is empty, outputs "Empty stack". This operation is intended // for testing and debugging purposes only.
{ if( isEmpty() ) { cout
StackLinked.cpp:
#include "StackLinked.h"
template
template
template
template
template
template
template
template
template
template } test6.cpp: //-------------------------------------------------------------------- // // Laboratory 6 test6.cpp // // Test program for the operations in the Stack ADT // //-------------------------------------------------------------------- #include using namespace std; #include "config.h" #if !LAB6_TEST1 # include "StackArray.cpp" #else # include "StackLinked.cpp" #endif void print_help() { cout template print_help(); do { testStack.showStructure(); // Output stack cout > cmd; if ( cmd == '+' ) cin >> testDataItem; try { switch ( cmd ) { case 'H' : case 'h': print_help(); break; case '+' : // push cout case '-' : // pop cout case 'C' : case 'c' : // clear cout case 'E' : case 'e' : // isEmpty if ( testStack.isEmpty() ) cout case 'F' : case 'f' : // isFull if ( testStack.isFull() ) cout case 'Q' : case 'q' : // Quit test program break; default : // Invalid command cout } while ( cin && cmd != 'Q' && cmd != 'q' ); } int main() { #if !LAB6_TEST1 cout s1; test_stack(s1); #else cout s2; test_stack(s2); #endif } config.h: /** * Stack class (Lab 6) configuration file. * Activate test #N by defining the corresponding LAB6_TESTN to have the value 1. */ #define LAB6_TEST1 0 // 0 => use array implementation, 1 => use linked impl. Stack.h: //-------------------------------------------------------------------- // // Laboratory 6 Stack.h // // Class declaration of the abstract class interface to be used as // the basis for implementations of the Stack ADT. // //-------------------------------------------------------------------- // for the exception warnings #pragma warning( disable : 4290 ) #ifndef STACK_H #define STACK_H #include using namespace std; template virtual ~Stack(); virtual void push(const DataType& newDataItem) throw (logic_error) = 0; virtual DataType pop() throw (logic_error) = 0; virtual void clear() = 0; virtual bool isEmpty() const = 0; virtual bool isFull() const = 0; virtual void showStructure() const = 0; }; template #endif // #ifndef STACK_H StackArray.h: //-------------------------------------------------------------------- // // Laboratory 6 Stack.h // // Class declaration of the abstract class interface to be used as // the basis for implementations of the Stack ADT. // //-------------------------------------------------------------------- // for the exception warnings #pragma warning( disable : 4290 ) #ifndef STACK_H #define STACK_H #include using namespace std; template virtual ~Stack(); virtual void push(const DataType& newDataItem) throw (logic_error) = 0; virtual DataType pop() throw (logic_error) = 0; virtual void clear() = 0; virtual bool isEmpty() const = 0; virtual bool isFull() const = 0; virtual void showStructure() const = 0; }; template #endif // #ifndef STACK_H StackLinked.h: //-------------------------------------------------------------------- // // Laboratory 6 StackArray.h // // Class declaration for the array implementation of the Stack ADT // //-------------------------------------------------------------------- #ifndef STACKARRAY_H #define STACKARRAY_H #include using namespace std; #include "Stack.h" template public: StackLinked(int maxNumber = Stack void push(const DataType& newDataItem) throw (logic_error); DataType pop() throw (logic_error); void clear(); bool isEmpty() const; bool isFull() const; void showStructure() const; private: class StackNode { public: StackNode(const DataType& nodeData, StackNode* nextPtr) { dataItem = nodeData; next = nextPtr; } DataType dataItem; StackNode* next; }; StackNode* top; }; #endif //#ifndef STACKARRAY_H
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started