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 »

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.




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. 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 correctly formatted. However, your program should not allow an attempt to divide by zero. Instead of dividing by zero, your program should display an error message and then begin evaluating a new input transaction. Sample input transactions are these: a. 2.0 3.3 + (result = 5.3) b. 3 4 * -2.5 / (result = -4.8) c. 9.5 8 3.0 2 * 6 - / + (result= “error: 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 b. 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 [email protected] 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 DayOct 28, 2021

Answer To: Your task for this assignment is to implement a stack data structure in C++. This may be...

Hardik answered on Oct 30 2021
157 Votes
#include
using namespace std;
Course ID & Section : Csc 331f20prog3spec-5c2cgzmv-kegttyt5
My Full N
ame : 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->array = (int*) malloc(stack->capacity * sizeof(int));
if (!stack->array) 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