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
|
#pragma once
template <class C>
class iohandler
{
private:
C mX, mY;
enum Operation{
MULTIPLY=4,
DIVIDE=3,
SUBTRACT=2,
ADD=1,
M=4,
D=3,
S=2,
A=1,
UNDEFINED = 0
};
C finalresult;
C& result = finalresult;
public:
iohandler();
~iohandler(void);
C getInput(){
using namespace std;
cout << "please enter what you want to calculate: ";
cin >> mX >> Operation >> mY;
return mX, Operation, mY;
};
void performOperation(C mX, Operation, C mY, C& result){
if (Operation == 1){
result = mX + mY;
} else if (Operation == 2){
result = mX-mY;
} else if (Operation == 3) {
result = mX/mY;
} else if (Operation == 4) {
result = mX*mY;
} else {
cout << "you have entered an invalid calculation, exiting...." << endl;
}
};
void printResult(C x){
cout << "Your Result is: " << x << endl;
};
C calculate(){
getInput();
performOperation(mX,Operation,mY);
printResult(result);
};
};
|