-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (36 loc) · 2.02 KB
/
main.cpp
File metadata and controls
50 lines (36 loc) · 2.02 KB
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
// Audrey Harris and Drew Milton
// P2 - Assignment Expression Tree: Creating funtions and implementation of them
#include "ExpTree.h" // Including ExpTree.h to call functions
#include <iostream>
#include <iomanip> // Input-Ouput manipulation for fixed << setprecision
#include <string>
#include <algorithm> // Allows for the implementation of erase(), remove(), etc
using namespace std;
int main() {
string create; // Using same name from ExpTree.h
double result; // Using same name from ExpTree.h
ExpTree tmp; // ExpTree object tmp
cout << "Please enter an expression, ctrl-Z to stop: \t";
while (getline(cin, create)) { // Obtaining the input for create
if (create == "^Z") { // Ctrl Z will cause the loop to break
break;
}
create.erase(remove(create.begin(), create.end(), ' '), create.end());
cout << "Expression Tree created:\n"; // Requirement
tmp.makeExpTree(create); // Calling makeExpTree function with object ExpTree with create passed in
tmp.IP(); // Calling IP function with object ExpTree
cout << "\n\nPostOrder: "; // Requirement
tmp.postorder(cout, " "); // Calling postorder function with object ExpTree
cout << endl;
if (tmp.eval(result) == true) { // Calling eval function with tmp ExpTree, if true execute loop
cout << "Evaluation Result: " << fixed << setprecision(2) << result; // Requirement
cout << endl;
}
else {
cout << "Evaluation Failed\n"; // Requirement
}
cout << "Please enter an expression, ctrl-Z to stop: \t\t"; // Requirement
}
cout << "Press any key to continue . . .\n"; // Requirement
return 0;
}