-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExpressionManager.h
executable file
·78 lines (67 loc) · 2.4 KB
/
ExpressionManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include "ExpressionManagerInterface.h"
#include <sstream>
#include <iostream>
#include <fstream>
#include <stack>
#include <cctype>
using namespace std;
class ExpressionManager :
public ExpressionManagerInterface
{
public:
ExpressionManager() {}
~ExpressionManager() {}
bool isOpen(char ch);
bool isClose(char ch);
bool isLeftParen(string t);
bool isRightParen(string t);
bool isOperator(string left, string right);
bool isOperator(string t);
bool isNumber(string t);
int getPrecedence(string t);
/*
* Checks whether an expression is balanced on its parentheses
*
* - The given expression will have a space between every number or operator
*
* @return true if expression is balanced
* @return false otherwise
*/
bool isBalanced(string expression);
/**
* Converts a postfix expression into an infix expression
* and returns the infix expression.
*
* - The given postfix expression will have a space between every number or operator.
* - The returned infix expression must have a space between every number or operator.
* - Redundant parentheses are acceptable i.e. ( ( 3 * 4 ) + 5 ).
* - Check lab requirements for what will be considered invalid.
*
* return the string "invalid" if postfixExpression is not a valid postfix expression.
* otherwise, return the correct infix expression as a string.
*/
string postfixToInfix(string postfixExpression);
/*
* Evaluates a postfix expression returns the result as a string
*
* - The given postfix expression will have a space between every number or operator.
* - Check lab requirements for what will be considered invalid.
*
* return the string "invalid" if postfixExpression is not a valid postfix Expression
* otherwise, return the correct evaluation as a string
*/
string postfixEvaluate(string postfixExpression);
/*
* Converts an infix expression into a postfix expression
* and returns the postfix expression
*
* - The given infix expression will have a space between every number or operator.
* - The returned postfix expression must have a space between every number or operator.
* - Check lab requirements for what will be considered invalid.
*
* return the string "invalid" if infixExpression is not a valid infix expression.
* otherwise, return the correct postfix expression as a string.
*/
string infixToPostfix(string infixExpression);
};