Related questions
stack.h
#ifndef STACK_H
#define STACK_H
#define MAX 100
//class stack
class stack
{
int top;
public:
//function declarations
stack();
char array[MAX];
void push(char x);
char pop();
char getTop();
bool isEmpty();
bool isFull();
};
#endif
stack.cpp
#include "stack.h"
#include <iostream>
using namespace std;
//default constructor initializes top as -1
stack::stack() {
top = -1;
}
//returns the top element of stack
char stack::getTop() {
return array[top];
}
//thuis method adds an element in array by adding the top by 1
void stack::push(char x) {
if (isFull()) {
cout << "Stack Overflow";
} else {
array[++top] = x;
}
}
//this method returns the top element of stack and decrement the top by 1
char stack::pop() {
if (isEmpty()) {
cout << "\nStack is Empty";
return 0;
} else {
char x = array[top];
top--;
return x;
}
}
//this methd checks the stack is empty or not
bool stack::isEmpty() {
return (top < 0);
}
//this method checks the stack is full or not
bool stack::isFull() {
return (top >= MAX);
}
Create the postfix.cpp file the converts an infix expression into a postfix expression. You must use the stack.h and stack.cpp implemented in Part 1. The program must allow the user inputs, and the inputs should not include any alphabets. You need to handle (','), +, 5, 7, *** and % operators. "N? will not be considered in this program. Also, please consider only one digit numbers. The following links can be helpful for the conversions from string to integer or double types. Create a menu loop in your application asking if the user wants to enter another expression. When doing your error handling and showing this message "I cannot create a postfix form - Error". If you can replace "Error" with the reason for the error e.g. "I cannot create a postfix form - Non numeric values not allowed" for a + b * c.
This program also needs to evaluate the infix expression and display the result after the postfix.
EX.
Enter an infix expression: 2 + 3 * 4
The postfix form is 2 3 4 * +
The result is 14
This program needs to be developed using c++ language
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- C# Display the stack with the given information: int topNum; NumberStack stack2 = new NumberStack(5); stack2.Push(5);stack2.Push(7);stack2.Push(12);stack2.Push(3); public void PrintStack() { //Loop through each element of the stack and display it for (int i = size - 1 ; i >= 0; i--) { Console.WriteLine(stack[i]); } }arrow_forwardThe operation of a stack removes and stores the top element of the stack.arrow_forwardComputer science JAVA programming languarrow_forward
- Nesting procedure calls how many return addresses will be on the stack by the time Sub3 is called? main PROC call Subl exit main ENDP Subl PROC call Sub2 ret Subl ENDP Sub2 PROC call Sub3 ret Rectangu Sub2 ENDP Sub3 PROC ret Sub3 ENDP 2 O1 3arrow_forwardsuf: C nn.instru @ 2 S if the stack contains (from top) "5", "4", "3", "2", "1" and element = "new", the stack will contain "5", "4", "3", "new", "new" after interchange (). if the stack contains (from top) "5" and element "new", the stack will contain "new", "new" after interchange(). 30% Write public instanc method for MyStáck, called interchange (T element) to replac the bottom *two* items in the stack with element. wer than two items on the stack, upon return the stack should contain exactly two items that are element. Examples: F2 # ۲ 3 ۳ WE E ص X Assume class MyStack implements the following StackGen interface. For this question, make no assumptions about the implementation of MyStack except that the follo wing interface methods are implemented and work as documented. public interface StackGen { void push(T 0); // conventional stack behavior T pop(); // conventional stack behavior T top(); // returns, but does not remove, top element in stack boolean isEmpty(); // returns true...arrow_forwardC++ program that asks the user for an integer n followed by n other integers,if integer is prime then it adds it to a queue otherwise add it to a stack,then print both structuresarrow_forward
- Java data strucarrow_forward#include<bits/stdc++.h>using namespace std;#define MAX 1000 //Maximum size of stack class Stack{ int top;// to store top of stack public: int elements[MAX]; //Integer array to store elements Stack(){ //class constructor for initialization top=-1; } bool push(int x) { if(top>=(MAX-1)) //Condition for top when stack because full { cout<<"Stack is full\n"; return false; } else { ++top; //Increasing top value elements[top]=x; //storing it to element in to stack return true; }}int pop(){ if(top<0)// Condition for top when stack is empty { cout<<"stack is empty\n"; return INT_MIN; } else { int x=elements[top--];//poping out the element for stack by decreasing to element return x; }}int display(){if(top<0)//Condition for top when stack is empty { cout<<"Stack is...arrow_forwardNonearrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY