write a program in c++
Read an infix expression from an input file and convert to postfix. Instead of displaying directly on the screen, first place in a queue, and then display the contents of the queue on the screen.
Precondition:
Example:
1+2
converts to
12+
INPUT
##########
Input to the program is a text file "input.txt" as shown in the screenshot below

########################### PGM START ###################################
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define SIZE 100
//********************** Stack implementation
class Stack
{
int top;
public:
char a[SIZE];
Stack(){
//initialising top of stack as
-1
//which measn empty stack
top = -1;
}
//function declaration
bool push(char x);
char pop();
bool isEmpty();
char topElement();
};
//function to push character into stack
bool Stack::push(char x)
{
//checking the overflow condition in the stack
if (top >= (SIZE-1))
{
cout <<
"Stack Overflow";
return false;
}
else
{
//pushing element to stack
a[++top] =
x;
return true;
}
}
//returns the first top elemnt of the stack
char Stack::topElement()
{
if (top < 0)
{
cout <<
"empty Stack";
return 'N';
}
else
{
char x =
a[top];
return x;
}
}
//pop() remove the top element from stack
char Stack::pop()
{
if (top < 0)
{
cout << "Stack
Underflow";
return 'N';
}
else
{
char x = a[top--];
return x;
}
}
//isEmpty() checks if stack is empty or not
bool Stack::isEmpty()
{
return (top < 0);
}
//**************************** Queue
Implementation
class Queue
{
int front,rear;
public:
char a[SIZE];
Queue(){
rear=-1;
front=0;
}
//function declaration
bool enqueue(char x);
char dequeue();
bool isEmpty();
};
bool Queue::enqueue(char x)
{
//checking the overflow condition for queue
if (rear >= (SIZE-1))
{
cout <<
"Queue Overflow";
return false;
}
else
{
//inserting element to queue
a[++rear] =
x;
return true;
}
}
//dequeue() remove the front element from queue
char Queue::dequeue()
{
if (rear < 0)
{
cout << "Queue
Underflow";
return 'N';
}
else
{
char x =
a[front++];
return x;
}
}
//isEmpty() checks if queue is empty or not
bool Queue::isEmpty()
{
return (front>rear);
}
//************************Infix to postfix conversion
***
//Function to return precedence of operators
int precedenceValue(char c){
if(c == '*' || c == '/')
return 2;
else if(c == '+' || c == '-')
return 1;
else
return -1;
}
/*
infixToPostfix() function converts infix expression
to postfix expression
*/
void infixToPostfix(string s)
{
Stack st;
Queue q;
int l = s.length();
string finalString;
for(int i = 0; i < l; i++)
{
// If the character is
an operand, append it to queue
if((s[i] >= '0'
&& s[i] <= '9'))
q.enqueue(s[i]);
// If the character is
an ‘(‘, push it to the stack.
else if(s[i] ==
'(')
st.push('(');
// If the character is
an ‘)’, pop and to output string from the stack
// until an ‘(‘ is
seen
else if(s[i] ==
')'){
while(!st.isEmpty() && st.topElement() !=
'(')
{
char c = st.topElement();
st.pop();
q.enqueue(c);
}
if(st.topElement() == '(')
{
char c = st.topElement();
st.pop();
}
}
//If an operator is
scanned, if the precedence of current operator is less than one in
stack
//pop th eoperator in
stack and enqueue i to queue
//else push the operator
to stack
else{
while(!st.isEmpty() && precedenceValue(s[i]) <=
precedenceValue(st.topElement())){
char c = st.topElement();
st.pop();
q.enqueue(c);
}
st.push(s[i]);
}
}
//Pop all the remaining elements from the
stack
//enqueue it to queue
while(!st.isEmpty())
{
char c =
st.topElement();
st.pop();
q.enqueue(c);
}
//removing elements one by one from queue to get
final string
while(!q.isEmpty()){
finalString+=q.dequeue();
}
cout <<"Postfix Notation = "<<
finalString << endl;
}
// Driver program to test above functions
int main()
{
string s;
//reading the infix expression from input.txt
file
//file have only one line
fstream infile;
infile.open("input.txt");
//storing the line read into string s
getline(infile,s);
cout<<"Infix Expression =
"<<s<<"\n";
//calling infixto postfix conversion function
infixToPostfix(s);
return 0;
}
################################ PGM END #################################
Output Screenshot
#################

write a program in c++ Read an infix expression from an input file and convert to...
In C++, write a program that reads a postfix expression from an input file. Then, the program should evaluate the postfix format and display the results. Use these concepts for the program: 1) Struct Node 2) Enqueue and Dequeue 3) Push and Pop 4) DO NOT USE classes 5) Possibly Stack Precondition: The expression will be read from a file (input.txt) that contains a single line. There will be no spaces between the operands and the operators. The following operators...
implement a class of infix calculators (Using C++). Consider a simple infix expression that consist of single digit operands; the operators +, -, *, and / ; and parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces. Design and implement a class of infix calculators. Use the algorithms given in the chapter 6 to evaluate infix expressions as entered into the calculator. You must first convert the infix expression to postfix form and then...
In C programming Language Write a version of the infix-to-postfix conversion algorithm. Write a program that converts an ordinary infix arithmetic expression (assume a valid expression is entered) with single-digit integers For Example: Infix expression (6 + 2) * 5 - 8 / 4 to a postfix expression is 62+5*84/- The program should read the expression into character array infix and use the stack functions implemented in this chapter to help create the postfix expression in character array postfix. The...
Write a program to convert an expression written in infix notation to be converted to postfix notation. The program must do the following: a. Read a string of characters representing an expression in infix notation. The '$' is to be added at the end of the string to mark its ending. Each character is a letter, digit, +,-,*, or /. If a character is any other character an error must be signaled and the program is terminated b. Use stacks...
Total point: 15 Introduction: For this assignment you have to write a c program that will take an infix expression as input and display the postfix expression of the input. After converting the postfix expression, the program should evaluate the expression from the postfix and display the result. What should you submit? Write all the code in a single file and upload the .c file. Problem We as humans write math expression in infix notation, e.g. 5 + 2 (the...
Write a java program for the following: Your program reads an infix expression represented by a string S from the standard input (the keyboard). Then your program converts the infix expression into a postfix expression P using the algorithm. Next, your program evaluates the postfix expression P to produce a single result R. At last, your program displays the original infix expression S, the corresponding postfix expression P and the final result R on the standard output ( the screen...
You are to write a program name expressionTree.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits). (2) One alphabetic character - "x" (representing a value to be supplied later). (3) Binary operators (+, -, *, / and % (modulo)). (4) Parentheses You will parse the input expression creating an expression tree with the tokens, then use the postOrder tree traversal algorithm to extract...
Write a program in c++ to convert an expression written in infix notation to be converted to postfix notation. The program must do the following: a. Read a string of characters representing an expression in infix notation. The '$' is to be added at the end of the string to mark its ending. Each character is a letter, digit, +,-,*, or /. If a character is any other character an error must be signaled and the program is terminated b....
Develop an Expression Manager that can do the following operations: Balanced Symbols Check • Read a mathematical expression from the user. • Check and report whether the expression is balanced. • {, }, (, ), [, ] are the only symbols considered for the check. All other characters can be ignored. Infix to Postfix Conversion • Read an infix expression from the user. • Perform the Balanced Parentheses Check on the expression read. • If the expression fails the Balanced...
Write a java program to convert and print an infix expression to postfix expression. You can use Java stack methods. (Must read input from System.in) Your main method should be as follow: public static void main(String args[]) { intopost p = new intopost (); String iexp, pexp; //infix postfix expression try{ Scanner inf = new Scanner (System.in); // Read input from KB/ File while(inf.hasNext()){ // read next infix expression iexp = inf.next(); // Assume method name to convert infix...