Design a class Expression { public: //methods... private: string infix; string postfix; }; that contains a constructor: Expression(string input, int direction) { if (direction == 1) } infix input; else if(direction == 2) postfix input; and three methods, inToPost, postToIn and evaluate string inToPost() { //... } string postToIn() { //... } } double evaluate() { //... The first method transforms the local infix expression to postfix, stores it as the local postfix and returns it as a String. The second method is the inverse: it transforms the local postfix expression to infix, stores it locally, and returns it as a string. The method evaluate() returns the value of the expression. Your main() should display a prompt to the user, give him/her the opportunity to enter a string in either notation (hence the two different directions in the constructor) to be transformed to the other, and evaluate the result. You will probably also need to declare different types of Stack classes, to be used each for a different purpose. You must create your own stack from scratch. Do not use std::vector or any other std:: container. If your program has any fancy features, such as allowing multiple-digit numbers, checking for illegal characters in the input, adding some extra operators, or others, please make that clear in a comment at the beginning of your program. Also, when you display the menu of options to the user, make it clear how they should enter the expressions (i.e. leave spaces around operators etc..)

icon
Related questions
Question
Design a
class Expression {
public:
//methods...
private:
};
string infix;
string postfix;
that contains a constructor:
Expression(string input, int direction) {
if (direction == 1)
infix = input;
else if(direction == 2)
postfix input;
}
and three methods, inToPost, postToIn and evaluate
string inToPost() {
// ...
}
string postToIn() {
// ...
}
double evaluate() {
// ...
}
The first method transforms the local infix expression to postfix, stores it as the local postfix and returns it as a
String. The second method is the inverse: it transforms the local postfix expression to infix, stores it locally,
and returns it as a string. The method evaluate() returns the value of the expression.
Your main() should display a prompt to the user, give him/her the opportunity to enter a string in either
notation (hence the two different directions in the constructor) to be transformed to the other, and evaluate
the result. You will probably also need to declare different types of Stack classes, to be used each for a
different purpose.
You must create your own stack from scratch. Do not use std::vector or any other std:: container.
If your program has any fancy features, such as allowing multiple-digit numbers, checking for illegal
characters in the input, adding some extra operators, or others, please make that clear in a comment at the
beginning of your program. Also, when you display the menu of options to the user, make it clear how they
should enter the expressions (i.e. leave spaces around operators etc..)
Transcribed Image Text:Design a class Expression { public: //methods... private: }; string infix; string postfix; that contains a constructor: Expression(string input, int direction) { if (direction == 1) infix = input; else if(direction == 2) postfix input; } and three methods, inToPost, postToIn and evaluate string inToPost() { // ... } string postToIn() { // ... } double evaluate() { // ... } The first method transforms the local infix expression to postfix, stores it as the local postfix and returns it as a String. The second method is the inverse: it transforms the local postfix expression to infix, stores it locally, and returns it as a string. The method evaluate() returns the value of the expression. Your main() should display a prompt to the user, give him/her the opportunity to enter a string in either notation (hence the two different directions in the constructor) to be transformed to the other, and evaluate the result. You will probably also need to declare different types of Stack classes, to be used each for a different purpose. You must create your own stack from scratch. Do not use std::vector or any other std:: container. If your program has any fancy features, such as allowing multiple-digit numbers, checking for illegal characters in the input, adding some extra operators, or others, please make that clear in a comment at the beginning of your program. Also, when you display the menu of options to the user, make it clear how they should enter the expressions (i.e. leave spaces around operators etc..)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer