-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleFactory.cpp
65 lines (57 loc) · 1.12 KB
/
SimpleFactory.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
#include <iostream>
using namespace std;
class Operation{
public:
Operation(double a=0, double b=0):numberA(a), numberB(b){}
void setA(double a){
numberA = a;
}
void setB(double b){
numberB = b;
}
double getA(){
return numberA;
}
double getB(){
return numberB;
}
virtual double getResult(){
return result;
}
private:
double result = 0;
double numberA = 0;
double numberB = 0;
};
class Plus: public Operation{
public:
double getResult(){
double a = getA();
double b = getB();
return a + b;
}
};
class Minus: public Operation{
public:
double getResult(){
double a = getA();
double b = getB();
return a - b;
}
};
class Mul: public Operation{
public:
double getResult(){
double a = getA();
double b = getB();
return a * b;
}
};
int main(){
Operation* op = new Minus();
op->setA(10);
op->setB(20);
double res = op->getResult();
printf("%d", res);
return 0;
}