Answer to Question #154311 in C++ for Mr. Roy

Question #154311

Your task in this week is to convert an infix expression to postfix expression. See the code template and sample output given billow for a clear understanding.

Also, write a function to evaluate a postfix expression.

Please do Comment the steps for understanding. Thanks.


Code template:

#include <iostream>

#include <sstream>

using namespace std;


/// implement your 'stack' here



int main()

{

  Stack s;

  string infix, postfix[100];


  cout << "\t\tInfix to Postfix Converter v1.0\n";

  cout << "\t\t===============================\n\n";


  cout << "Enter an infix expression: ";

  getline(cin, infix);


  infix += " )";

  s.push("(");


  istringstream token(infix);

  string t, p;

  int i=0, j;


  while(token>>t)

  {

    /// You have got the input symbol 't'.

    /// Now you have to process all the input symbols and

    /// fill in the 'postfix' array accordingly.

  }


  cout << endl << "The equivalent postfix expression is: ";

  for(j=0; j<i; j++) cout << postfix[j] << " ";

  cout << endl << endl;


  return 0;

}



Sample output:

        Infix to Postfix Converter v1.0

        ===============================

Enter an infix expression:A + ( B * C - ( D / E ^ F ) * G ) * H

The equivalent postfix expression is: A B C * D E F ^ / G * - H * + 

Process returned 0 (0x0)execution time : 11.891 s

Press any key to continue. 



1
Expert's answer
2021-01-07T09:30:53-0500
Dear Mr. Roy, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog