联系我们: 手动添加方式: 微信>添加朋友>企业微信联系人>13262280223 或者 QQ: 1483266981
Lab 1: Stack Application
Statement of Work: Implement a generic stack container. Implement a program that converts
infix expression to postfix expression and implement a program that evaluates postfix
expression using the stack container you developed.
Project Description:
A stack is a type of data container/data structure that implements the LAST-IN-FIRST-OUT
(LIFO) strategy for inserting and recovering data. This is a very useful strategy, related to many
types of natural programming tasks.
Remember that in the generic programming paradigm, every data structure is supposed to
provide encapsulation of the data collection, enabling the programmer to interact with the entire
data structure in a meaningful way as a container of data. By freeing the programmer from
having to know its implementation details and only exporting the interface of its efficient
operations, a generic Stack provides separation of data access/manipulation from internal data
representation. Programs that access the generic Stack only through the interface can be re
used with any other Stack implementation, which results in modular programs with clear
functionality and that are more manageable
Goals:
1. Implement a generic Stack.
2. Write a program that parses Infix arithmetic expressions to Postfix arithmetic
expressions using a Stack.
3. Write a program that evaluates Postfix arithmetic expressions using a Stack.
Task 1: Implement a GenericStack:
GenericStack: MUST store elements internally in a BasicContainer. It should use only the public
interface to BasicContainer, as you will compile/link your GenericStack implementation with the
BasicContainer class. Therefore, in particular:
GenericStack MUST:
o
be able to store elements of an arbitrary type.
o
have a no-argument constructor that initializes it to some size. This size MUST
NOT be so large as to prevent a calling program to initialize several
GenericStack instances in a single execution. Suggested length values are 10,
16, or 256.
Every GenericStack instance holding n elements MUST accept insertions as long as the
system has enough free memory to dynamically allocate an array of 2n+1 elements at
insertion request time, regardless of the initial capacity of the
GenericStack. If the system does not have such free memory, GenericStack MUST
report an error message as the result of the insertion request.
GenericStack MUST implement the full interface specified below.
You MUST provide both the template (in a class named GenericStack.h) and the
implementation (in a class named GenericStack.cpp).
Interface:
The interface of GenericStack is specified below. It provides the following public functionality, all
of which can be efficiently achieved using an internal array representation for the data.GenericStack(): no-argument constructor. Initializes the Stack to some pre-specified capacity.
~GenericStack (): destructor.
GenericStack (const GenericStack
GenericStack
bool empty() const: returns true if the GenericStack contains no elements, and false otherwise.
void push(const T& x): adds x to this GenericStack.
void pop(): removes and discards the most recently added element of the GenericStack.
T& top(): mutator that returns a reference to the most recently added element of the
GenericStack.
const T& top() const: accessor that returns the most recently added element of the
GenericStack.
int size(): returns the number of elements stored in this GenericStack.
void print(std::ostream& os, char ofc = ‘

