Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE C + + : Implement a generic stack container. Implement a program that converts infix expression to postfix expression and implement a program that

USE C++: 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 &): copy constructor.
GenericStack& operator=(const GenericStack &): assignment operator.
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 ='\0') const: print this instance of GenericStack to
ostream os. Note that gs.print() prints elements in opposite order as if bc.print() was invoked in
the underlying BasicContainer.
The following non-member functions should also be supported:
std::ostream& operator<<(std::ostream& os,const GenericStack& a): invokes the print()
method to print the GenericStack a in the specified ostream.
bool operator==(const GenericStack&,const GenericStack &): returns true if the two
compared "GenericStack"s have the same elements, in the same order.
bool operator<(const GenericStack& a, const GenericStack & b): returns true if every
element in GenericStack a is smaller than corresponding elements of GenericStatck b, i.e., if
repeatedly invoking top() and pop() on both a and b will generate a sequence of elements a_i
from a and b_i from b, and for every i, a_i < b_i, until a is empty.USE C++

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago