-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPNCalc.h
151 lines (139 loc) · 3.53 KB
/
RPNCalc.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
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
149
150
151
//----------------------------------------------------------------------------
// File: RPNCalc.h
//
// Class: CRPNCalc
//----------------------------------------------------------------------------
#ifndef RPNCALC_H
#define RPNCALC_H
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <exception>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <string>
#include <new>
#include <sstream>
#include <stack>
//----------------------------------------------------------------------------
//
// Title: RPNCalc Class
//
// Description: This file contains the class definition for CRPNCalc
//
// Programmer: Paul Bladek
//
// Date: 5/3/11
//
// Version: 1.03
//
// Environment:
// Hardware: Intel Xeon PC
// Software: Windows 7
// Compiles under Microsoft Visual Studio 2010
//
// class CRPNCalc:
//
// Properties:
// double m_registers[10] --
// string m_buffer --
// stack<string> m_stack --
// vector<list<string>> m_programs(NUMPROGRAMS) --
// istringstream m_inStrStream --
// m_on --
// bool m_error --
// bool m_helpOn --
//
// Methods:
//
// inline: None
//
// non-inline:
// public:
// CRPNCalc(bool on);
// void run();
// void print(ostream& ostr);
// void input(istream& istr);
// private:
//
// void add() --
// void bin_prep(double& d1, double& d2) --
// void clear() --
// void clearAll() --
// void divide() --
// void exp() --
// void getReg(int reg) --
// void loadProgram() --
// void mod() --
// void multiply() --
// void neg() --
// void parse() --
// void recordProgram() --
// void rotateUp() --
// void rotateDown() --
// void runProgram() --
// void saveToFile() --
// void setReg(int reg) --
// void subtract() --
// void unary_prep(double& d) --
//
// History Log:
// 4/20/03 PB completed version 1.0
// 5/27/05 PB minor modifications 1.01
// 5/3/11 PB minor modifications 1.02
// 6/3/12 PB minor modifications 1.03
// ----------------------------------------------------------------------------
using namespace std;
namespace PB_CALC
{
const char helpMenu[] = "C clear stack | CE clear entry | D rotate down | F save program to file\n"
"G0-G9 get reg n | H help on/off | L load program | M +/- | P program on/off\n"
"R run program | S0-S9 set reg n | U rotate up | X exit\n";
const char line[] = "____________________________________________________________________________\n";
const unsigned short NUMREGS = 10;
class CRPNCalc
{
public:
CRPNCalc(bool on = true);
void run();
void print(ostream& ostr); // changes m_error on error, so not const
void input(istream& istr);
private:
// private methods
void add();
void binary_prep(double& d1, double& d2);
void clearEntry();
void clearAll();
void divide();
void exp();
void getReg(int reg);
void loadProgram();
void mod();
void multiply();
void neg();
void parse();
void recordProgram();
void rotateUp();
void rotateDown();
void runProgram();
void saveToFile();
void setReg(int reg);
void subtract();
void unary_prep(double& d);
// private properties
double m_registers[NUMREGS];
string m_buffer;
deque<double> m_stack;
list<string> m_program;
istringstream m_instrStream;
bool m_error;
bool m_helpOn;
bool m_on;
bool m_programRunning;
};
ostream &operator <<(ostream &ostr, CRPNCalc &calc);
istream &operator >>(istream &istr, CRPNCalc &calc);
} // end namespace PB_CALC
#endif