Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello, this is for programming in C++ . Please follow the assignment below. I have several errors and I just dont know how to do
Hello, this is for programming in C++. Please follow the assignment below. I have several errors and I just dont know how to do this, please oh please help. I included the default programs that are included with this assignment at the bottom. Please follow the instructions. I really really need help, Thank you sooooo very much, seriously.
Below are the default programs given for the assignment. they are as follow and are separated by dash symbols:
stack.cpp, stack.h, and dsexceptions.h.
-------------------------------------------------------------------------------------------------------------------------------
//stack.cpp
/**
* Construct the stack.
*/
template
Stack
{
topOfStack = -1;
}
/**
* Test if the stack is logically empty.
* Return true if empty, false otherwise.
*/
template
bool Stack
{
return topOfStack == -1;
}
/**
* Test if the stack is logically full.
* Return true if full, false otherwise.
*/
template
bool Stack
{
return topOfStack == theArray.size( ) - 1;
}
/**
* Make the stack logically empty.
*/
template
void Stack
{
topOfStack = -1;
}
/**
* Get the most recently inserted item in the stack.
* Does not alter the stack.
* Return the most recently inserted item in the stack.
* Exception Underflow if stack is already empty.
*/
template
const Object & Stack
{
if( isEmpty( ) )
throw Underflow( );
return theArray[ topOfStack ];
}
/**
* Remove the most recently inserted item from the stack.
* Exception Underflow if stack is already empty.
*/
template
void Stack
{
if( isEmpty( ) )
throw Underflow( );
topOfStack--;
}
/**
* Insert x into the stack, if not already full.
* Exception Overflow if stack is already full.
*/
template
void Stack
{
if( isFull( ) )
throw Overflow( );
theArray[ ++topOfStack ] = x;
}
/**
* Return and remove most recently inserted item from the stack.
* Return most recently inserted item.
* Exception Underflow if stack is already empty.
*/
template
Object Stack
{
if( isEmpty( ) )
throw Underflow( );
return theArray[ topOfStack-- ];
}
--------------------------------------------------------------------------------------------------------------------------------------
//stack.h
#include "dsexceptions.h"
#include
using namespace std;
// Stack class -- array implementation
//
// CONSTRUCTION: with or without a capacity; default is 10
//
// ******************PUBLIC OPERATIONS*********************
// void push( x ) --> Insert x
// void pop( ) --> Remove most recently inserted item
// Object top( ) --> Return most recently inserted item
// Object topAndPop( ) --> Return and remove most recently inserted item
// bool isEmpty( ) --> Return true if empty; else false
// bool isFull( ) --> Return true if full; else false
// void makeEmpty( ) --> Remove all items
// ******************ERRORS********************************
// Overflow and Underflow thrown as needed
template
class Stack
{
public:
explicit Stack( int capacity = 10 );
bool isEmpty( ) const;
bool isFull( ) const;
const Object & top( ) const;
void makeEmpty( );
void pop( );
void push( const Object & x );
Object topAndPop( );
private:
vector
int topOfStack;
};
#include "stack.cpp"
------------------------------------------------------------------------------------------------------------------------------------------------
//dsexceptions.h
#ifndef _DSEXCEPTIONS_H_
#define _DSEXCEPTIONS_H_
class Underflow { };
class Overflow { };
class OutOfMemory { };
class BadIterator { };
class DataError { };
class DivisionByZero { };
#endif
-----------------------------------------------------------------------------------------------------------------------------------------------
Thank you.
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