Implement a C++ program that converts infix expressions to postfix expressions. Requirement: - Design a function called

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Implement a C++ program that converts infix expressions to postfix expressions. Requirement: - Design a function called

Post by answerhappygod »

Implement a C++ program that converts infix expressions topostfix expressions.
Requirement:
- Design a function called I2PConvertor, which use followingprototype:
std::string I2PConvertor(const std::string& infix_expr);
- The above function takes in a valid infix expression andreturns its corresponding postfix expression.
- Use provided main function to test the program.
Note:
- Infix expressions may have binary operators: +, -, *, /
- Infix expressions may have round parentheses: ()
- Infix expressions uses lower case letters to representoperands, such as a, b, c, …
Please use provided main function to test your program:
int main(){
std::string infix1 {"a*b+c"};
std::string infix2 {"a-b*c"};
std::string infix3 {"(a+b)/c"};
std::string infix4 {"(a+b)*(c-d)"};
// expected: ab*c+
std::cout << I2PConvertor(infix1) << std::endl;
// expected: abc*-
std::cout << I2PConvertor(infix2) << std::endl;
// expected: ab+c/
std::cout << I2PConvertor(infix3) << std::endl;
// expected: ab+cd-*
std::cout << I2PConvertor(infix4) << std::endl;
return 0; }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply