-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (57 loc) · 2.39 KB
/
Copy pathmain.cpp
File metadata and controls
66 lines (57 loc) · 2.39 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include <sstream>
#include "bet.h"
using namespace std;
int main(void)
{
BET<string> userInput; //users inputted postfix
BET<string> exPostfix("4 5 + 5 6 + /"); //example
BET<string> infix3; //to copy example using operator=
BET<string> testCopy(exPostfix); //COPY constructor
//EXAMPLE ONE (4 5 + 5 6 + /) --> ( 4 + 5 ) / ( 5 + 6 )
cout << "\nPostfix Example: ";
exPostfix.printPostfixExpression();
cout << "\nInfix conversion: ";
exPostfix.printInfixExpression();
cout << "\nNumber of Leaf Nodes in expression: " << exPostfix.leaf_nodes() << endl;
cout << "Size of expression: " << exPostfix.size() << endl;
//SHOWING TEST FOR OPERATOR= OVERLOAD
cout << "\nTesting the assignment operator= overload" << endl;
infix3 = exPostfix;
cout << "Copied infix: ";
infix3.printInfixExpression();
cout << "\nSize of new infix (copied from first example) is: " << infix3.size() << endl;
//SHOWING TEST FOR COPY CONSTRUCTOR
cout << "\nTesting the copy constructor for the testCopy. " << endl;
cout << "testCopy: ";
testCopy.printInfixExpression();
cout << "\nSize of copy using copy constructor is: " << testCopy.size() << endl;
//LOOP FOR USER INPUTTED POST FIX. Stops when user inputs exit
while(1){
string instr;
//PROMPT
cout << "\nDIRECTIONS: Enter a postfix expression WITH SPACES when prompted."
<< "\nhelp: To see these directions again"
<< "\nexit: To stop program" << endl;
cout << "\nEnter a postfix notation (variables allowed): ";
getline(cin, instr);
if(instr == "help") {
cout << "\nDIRECTIONS: Enter a postfix expression WITH SPACES when prompted."
<< "\nhelp: To see these directions again"
<< "\nexit: To stop program" << endl;
}
else if(instr == "exit") {
cout << "Exiting program..." << endl;
break;
}
else{
userInput.buildFromPostfix(instr);
cout << "Infix conversion: ";
userInput.printInfixExpression();
cout << "\nNumber of Leaf Nodes in expression: " << userInput.leaf_nodes() << endl;
cout << "Size of expression: " << userInput.size() << endl;
}
}
return 0;
}