-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.cpp
More file actions
40 lines (31 loc) · 949 Bytes
/
driver.cpp
File metadata and controls
40 lines (31 loc) · 949 Bytes
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
#include <iostream>
#include "Array.h"
#include "Stack.h"
#include "Expr_Command.h"
#include "Stack_Expr_Command_Factory.h"
#include "Calculator.h"
int main()
{
std::string infix;
Calculator calc;
while (true) {
std::cout << "Enter expression: ";
getline(std::cin, infix);
if (infix == "QUIT" || infix == "quit") {
break;
} else {
// COMMENT I think you have some memory leaks since you are not deleting
// the created commands between expressions.
// commands are getting deleted in the calculator.cpp inside evaluate_expression function
Stack<int> result;
Stack_Expr_Command_Factory factory(result);
Array<Expr_Command *> postfix;
if (calc.infix_to_postfix(infix, factory, postfix)) {
std::cout << result.top() << "\n"; // Result top contains the evaluated result for the given expression
} else {
std::cout << "Something went wrong!!!\n";
}
}
}
return 0;
}