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.
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 now
This is a popular solution!
Step by step
Solved in 2 steps