Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Your task for this assignment is to implement a stack data structure in C++. This may be accomplished by utilizing the C++ standard template library (STL) or by utilizing a user-defined class. 1....

1 answer below »
Your task for this assignment is to implement a stack data structure in C++. This may be accomplished by utilizing the C++ standard template li
ary (STL) or by utilizing a user-defined class.
1. Implement a transaction-based stack data structure using C++. The program will be interactive. Data transactions will be entered at the command line and results will be displayed on the console.
2. Each input transaction will contain an arithmetic expression in post-fix format. Assume that operands and operations are separated by a space on an input line that contains one arithmetic expression. An operand will be a positive or negative float number. An operation may be +, -, * or /. You may assume that each arithmetic expression is co
ectly formatted. However, your program should not allow an attempt to divide by zero. Instead of dividing by zero, your program should display an e
or message and then begin evaluating a new input transaction.
Sample input transactions are these:
a XXXXXXXXXXresult = 5.3)
. 3 4 * -2.5 / (result = -4.8)
c XXXXXXXXXX * 6 - / + (result= “e
or: division by zero”)
3. An input transaction containing “end-of-file” indicates there are no more transactions to be processed. Implement a stack to evaluate each expression and display the result. Use the C++ built-in class or a user-defined class to implement stack functions.
4. The program will be run at the command prompt by navigating to the directory containing the executable version of the program after the program is compiled. The program should display a prompt requesting input, such as “Please enter an expression in post-fix notation:”.
5. Your C++ program file should be named csc331-section_prog3_lastname.cpp. Your program should contain comments starting on line 1 of the program containing the following information:
a. course ID and section
. your full name
c. the program file name
d. the program assignment number and due date
e. the program purpose
You are encouraged to add additional comments throughout the program that your feel might be helpful to the reader of your source code.
6. Submit your C++ program (cpp file; no zip file) as an attachment to an email message to XXXXXXXXXX using a subject in this form: “csc331-section_prog3_lastname”.
Course ID & Section : Csc 331/190
My Full Name : M M Tanvir Jahid Hridoy ( Last Name : Jahid Hridoy)
Answered Same Day Oct 28, 2021

Solution

Hardik answered on Oct 30 2021
159 Votes
#include
its/stdc++.h>
using namespace std;
Course ID & Section : Csc 331f20prog3spec-5c2cgzmv-kegttyt5
My Full Name : Hardik Karira
Declare linked list node
struct Node
{
int data;
struct Node* link;
};
struct Node* top;
Utility function to add an element
data in the stack insert at the beginning
struct Stack* createStack( unsigned capacity )
{
struct Stack* stack = (struct Stack*) malloc(sizeof(struct Stack));
if (!stack) return NULL;
stack->top = -1;
stack->capacity = capacity;
stack->a
ay = (int*) malloc(stack->capacity * sizeof(int));
if (!stack->a
ay) return NULL;
return stack;
}
void push(int data)
{

Create new node temp and allocate memory
struct Node* temp;
temp = new Node();

Check if stack (heap) is full.

Then inserting an element would

lead to stack overflow
if (!temp)
{
cout
"\nHeap Overflow";
exit(1);
}

Initialize data into temp data field
temp->data = data;

Put top pointer reference into temp link
temp->link = top;

Make temp as top of Stack
top = temp; ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here