-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
148 lines (143 loc) · 4.49 KB
/
main.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "include/calculator.h"
#include "include/string_parser.h"
#include <iostream>
using namespace std;
int main() {
string name;
Calculator calculator;
system("Color E8");
cout << " _____________________ " << endl;
cout << "| _________________ | " << endl;
cout << "| | | | " << endl;
cout << "| |_________________| | " << endl;
cout << "| ___ ___ ___ ___ | " << endl;
cout << "| | 7 | 8 | 9 | | + | | " << endl;
cout << "| |___|___|___| |___| | " << endl;
cout << "| | 4 | 5 | 6 | | - | | " << endl;
cout << "| |___|___|___| |___| | " << endl;
cout << "| | 1 | 2 | 3 | | x | | " << endl;
cout << "| |___|___|___| |___| | " << endl;
cout << "| | . | 0 | = | | / | | " << endl;
cout << "| |___|___|___| |___| | " << endl;
cout << "|_____________________| " << endl;
cout << "Hello, what's your name?\n";
cin >> name;
system("cls");
while (true) {
menu:
system("cls");
cout << "Hello " << name <<", what would you like to do today?\n" << endl;//show menu
cout << "Option" << endl;
cout << "1. Calculate an expression" << endl;
cout << "2. Check calculator history" << endl;
cout << "3. Clear history" << endl;
cout << "4. Glossary" << endl;
cout << "5. End session" << endl;
cout << "Enter Option: ";
system("Color F5");//change color again because aesthetic
int choice;
cin >> choice; //get menu command
if (choice == 1) {
system("cls");
input:
cout << "Input your expression: ";
string input, dummy;
getline(cin, dummy);
getline(cin, input);
double result = calculator.calculate(input, true);
cout << "Result:\n" << result;
cout <<"\nWould you like to continue calculating?\n" << "y/n\n";
string opt1;
cin >> opt1;
if (opt1=="y" || opt1=="Y") {
system("cls");
goto input;
}
else if (opt1=="n" || opt1=="N") {
goto menu;
}
}
else if (choice == 2) {
list<string> history = calculator.getHistory();
cout << history.size() << '\n';
if (history.empty()) {
system("cls");
cout << "There is no history detected.\n";
}
else {
system("cls");
int number = 1;
for (string str : history) {
cout << number++ << ". " << str << '\n' << endl;
}
}
cout << "Enter any key to return\n";
string any;
cin >> any;
if (any=="1"){
goto menu;
}
else {
goto menu;
}
}
else if (choice == 3){
calculator.deleteAllHistory();
}
else if (choice == 4) {
glossary:
system("cls");
system("Color F5");
cout << "Glossary:" << endl;
cout << "1. sqrt(x) : square root of x" << endl;
cout << "2. exp(x,y): x to the power of y" << endl;
cout << "3. log(x) : log of x" << endl;
cout << "4. ln(x) : ln of x" << endl;
cout << "5. sin(x) : sinus of x" << endl;
cout << "6. cos(x) : cosinus of x" << endl;
cout << "7. tan(x) : tan of x\n" << endl;
cout << "8. The x for the trigonometry is in radian instead of degree." << endl;
cout << "Where would you like to go?" << endl;
cout << "1. Calculate an expression" << endl;
cout << "2. Back to menu" << endl;
string opt2;
cin >> opt2;
if (opt2 == "1") {
cout << '\n';
goto input;
}
else if (opt2 == "2") {
goto menu;
}
else {
cout << "\nThere is no such option" << endl;
system("Color 4F");
goto glossary;
}
}
else if (choice == 5) {
break; //ends session
}
else {
cout << "\nInvalid. There is no such option." << endl;
system("Color 4F"); //screen flash then back to normal menu
}
}
system("cls");
cout << " _____________________ " << endl;
cout << "| _________________ | " << endl;
cout << "| | | | " << endl;
cout << "| |_________________| | " << endl;
cout << "| ___ ___ ___ ___ | " << endl;
cout << "| | 7 | 8 | 9 | | + | | " << endl;
cout << "| |___|___|___| |___| | " << endl;
cout << "| | 4 | 5 | 6 | | - | | " << endl;
cout << "| |___|___|___| |___| | " << endl;
cout << "| | 1 | 2 | 3 | | x | | " << endl;
cout << "| |___|___|___| |___| | " << endl;
cout << "| | . | 0 | = | | / | | " << endl;
cout << "| |___|___|___| |___| | " << endl;
cout << "|_____________________| " << endl;
cout << "Thank you for using our service, have a great day" << endl;
system("Color 8E"); //goodbye
}