Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

Files:

StackArray.cpp:

#include "StackArray.h"

template StackArray::StackArray(int maxNumber) { }

template StackArray::StackArray(const StackArray& other) { }

template StackArray& StackArray::operator=(const StackArray& other) { }

template StackArray::~StackArray() { }

template void StackArray::push(const DataType& newDataItem) throw (logic_error) { }

template DataType StackArray::pop() throw (logic_error) {

}

template void StackArray::clear() { }

template bool StackArray::isEmpty() const { return false; }

template bool StackArray::isFull() const { return false; }

template void StackArray::showStructure() const

// 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 StackLinked::StackLinked (int maxNumber) { }

template StackLinked::StackLinked(const StackLinked& other) { }

template StackLinked& StackLinked::operator=(const StackLinked& other) { }

template StackLinked::~StackLinked() { clear(); }

template void StackLinked::push(const DataType& newDataItem) throw (logic_error) { }

template DataType StackLinked::pop() throw (logic_error) { }

template void StackLinked::clear() { StackNode* t; while ( top != NULL) { t = top; top = top->next; delete t; } }

template bool StackLinked::isEmpty() const { return false; }

template bool StackLinked::isFull() const { return false; }

template void StackLinked::showStructure() const { if( isEmpty() ) { cout next) { if( temp == top ) { cout dataItem dataItem

}

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 void test_stack(Stack& testStack) { DataType testDataItem; // Stack data item char cmd; // Input command

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 #include

using namespace std;

template class Stack { public: static const int MAX_STACK_SIZE = 8;

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 Stack::~Stack() // Not worth having a separate class implementation file for the destuctor {}

#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 #include

using namespace std;

template class Stack { public: static const int MAX_STACK_SIZE = 8;

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 Stack::~Stack() // Not worth having a separate class implementation file for the destuctor {}

#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 #include

using namespace std;

#include "Stack.h"

template class StackLinked : public Stack {

public:

StackLinked(int maxNumber = Stack::MAX_STACK_SIZE); StackLinked(const StackLinked& other); StackLinked& operator=(const StackLinked& other); ~StackLinked();

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

To Do: implement the Stack ADT (50 points) using array based approach implement the Stack ADT (50 points) using the linked list approach

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

Step: 3

blur-text-image

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago