stack.h
#ifndef STACK_H#define STACK_H#define MAX 100//class stackclass stack{int top;public://function declarationsstack();char array[MAX];void push(char x);char pop();char getTop();bool isEmpty();bool isFull();};#endif
stack.cpp
#include "stack.h"
#include using namespace std;//default constructor initializes top as -1stack::stack() {top = -1;}//returns the top element of stackchar stack::getTop() {return array[top];}//thuis method adds an element in array by adding the top by 1void stack::push(char x) {if (isFull()) {cout < "stack="">} else {array[++top] = x;}}//this method returns the top element of stack and decrement the top by 1char stack::pop() {if (isEmpty()) {cout < "\nstack="" is="">return 0;} else {char x = array[top];top--;return x;}}//this methd checks the stack is empty or notbool stack::isEmpty() {return (top <>}//this method checks the stack is full or notbool 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 * 4The postfix form is 2 3 4 * +The result is 14This program needs to be developed using c++ language
using namespace std;//default constructor initializes top as -1stack::stack() {top = -1;}//returns the top element of stackchar stack::getTop() {return array[top];}//thuis method adds an element in array by adding the top by 1void stack::push(char x) {if (isFull()) {cout < "stack="">
} else {array[++top] = x;
}
}//this method returns the top element of stack and decrement the top by 1char stack::pop() {if (isEmpty()) {cout < "\nstack="" is="">return 0;} else {char x = array[top];top--;return x;}}//this methd checks the stack is empty or notbool stack::isEmpty() {return (top <>}//this method checks the stack is full or notbool 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
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here