-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·126 lines (106 loc) · 2.95 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
#include <iostream>
#include <limits>
#include <locale>
#include "lib/calculator.h"
#include "windows.h"
using namespace std;
void display_help();
int main(int argc, char** argv) {
string default_text = "1(2-4)/3*9^6/5*-4";
cout << "Command line calculator program\n"
<< "Made by Jan Rubacha\n"
<< "Version: 0.0.2\n"
<< "\n"
<< "For help type h\n";
fstream constants;
constants.open("../memory/constants", ios::in);
bool installed = false;
if(constants.good()) {
installed = true;
}
if(argc == 1) {
calculator::calc calc;
string input;
string equation;
try {
calc.parse(default_text);
} catch(logic_error &e) {
cout << e.what() << endl;
}
while(true) {
break;
if(installed) {
cout << "<I>: ";
} else {
cout << "<S>: ";
}
getline(cin, input);
if(input == "q") {
break;
} else if(input == "d") {
equation = default_text;
} else if(input == "h") {
display_help();
continue;
} else {
equation = input;
}
try {
calc.parse(equation);
} catch(logic_error &e) {
cout << e.what() << endl;
}
}
// system("pause");
} else {
cout << "number of arguments: " << argc << '\n';
for(int i = 0; i < argc; i++) {
cout << argv[i] << '\n';
}
}
return 0;
}
void display_help() {
cout << "d - default input (for debugging purposes)\n"
<< "h - display help\n"
<< "q - quit program\n"
<< "\n"
<< "Input different than those above will be parsed\n"
<< "That is, just type calculation you want to do\n"
<< "\n"
<< "Available operators:\n"
<< "\t\'+\' addition\n"
<< "\t\'-\' subtraction\n"
<< "\t\'*\' multiplication\n"
<< "\t\'/\' division\n"
<< "\t\'^\' power\n"
<< "\t\'^/\' root\n"
<< "\n"
<< "Rules of syntax:\n"
<< "\t- every constant needs to be preceded with \'_\'\n"
<< "\t ex. _pi\n"
<< "\t- every function needs to be preceded with \'?\'\n"
<< "\t ex. ?sin(_pi)\n"
<< "\t- operators can be combined in any order and quantity, -* = ++*---\n"
<< "\t- for use of brackets use only (), they can be freely nested\n"
<< "\t- in floating point decimals use \'.\' as separator\n"
<< "\t- in functions with many arguments separate them with \',\'\n"
<< "\n"
<< "Modes:\n"
<< "<I> - installed, you will be able to save your own constants\n"
<< "<S> - standalone, all changes will be lost upon exit\n"
<< "\n"
<< "Implemented constants:\n"
<< "pi, e\n"
<< "Implemented functions\n"
<< "sin\n"
<< "\n";
}
/*
todo:
zaimplementować obsługę funkcji
zaimplementować funkcje optymalizujące drzewo
funkcję która wyświetla wszystkie liczby jako int
klasy wyjątków
dołożyć destruktor
*/