-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcalc.h
64 lines (54 loc) · 1.46 KB
/
calc.h
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
#ifndef __CALC_H__
#define __CALC_H__
enum keycodes {
kzero, kone, ktwo, kthree, kfour, kfive, ksix, kseven, keight, knine,
kdot, kexp, kplus, kmod, ke, kpercent,
kminus, kpi, kround, ksqrt, klog, kln,
ktimes, ksquare, kreciprocal, kfact, kabs, kpower,
kdiv, kpush, kswap, kcosh, ksinh, ktanh,
kacos, kasin, katan, kxsqrty, kex, kangmode, ktorad, ktodeg, ktenx,
kexit, kdrop, kcos, ksin, ktan, kspare, keol, knop, kback, kneg
};
typedef struct key {
const char* text;
keycodes id;
} Key;
class CalcDisplay;
class StackElement {
public:
StackElement(int width, int height);
CalcDisplay* getLine() { return display; }
const char* getText();
void setText(const char* text);
void append(const char digit);
double getValue();
void setValue(double val);
void dropLastDigit();
bool isBlank();
private:
std::string content;
CalcDisplay* display;
};
class Calculator {
public:
void buttonPressed(Key key);
void setOutputs(std::vector<StackElement*> outputs);
int angmode;
private:
void append(const char digit);
void shuffleDown();
void shuffleUp();
void maybePush();
void didOp();
void undidOp();
void handleNumPad(int);
void handleUnaryOp(int);
void handleBinaryOp(int);
void handleConstants(int);
void handleStack(int);
double torad(double);
double todeg(double);
bool prevWasOp;
std::vector<StackElement*> stack;
};
#endif