-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlateBinding.cpp
82 lines (75 loc) · 1.18 KB
/
lateBinding.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
#include <iostream>
using namespace std;
class Numbers
{
protected:
int a,b;
public:
Numbers(int a, int b)
{
this->a = a;
this->b = b;
}
virtual int calculate()=0;
virtual ~Numbers(){}
};
class Add : public Numbers
{
public:
Add(int a,int b) : Numbers(a,b){}
int calculate()
{
return a+b;
}
~Add(){}
};
class Subtract : public Numbers
{
public:
Subtract(int a, int b) : Numbers(a,b){}
int calculate()
{
return a-b;
}
~Subtract(){}
};
class Product : public Numbers
{
public:
Product(int a, int b) : Numbers(a,b){}
int calculate()
{
return a*b;
}
~Product(){}
};
int main()
{
Numbers *bptr;
int a, b;
cout << "Enter 2 numbers: ";
cin >> a >> b;
cout << "Enter following keys for calculation: " << endl;
cout << "1 for addition" << endl << "2 for subtraction" << endl << "3 for product" << endl;
int n;
cin >> n;
switch(n)
{
case 1:
bptr = new Add(a,b);
cout << bptr->calculate() << endl;
break;
case 2:
bptr = new Subtract(a,b);
cout << bptr->calculate() << endl;
break;
case 3:
bptr = new Product(a,b);
cout << bptr->calculate() << endl;
break;
default:
cout << "Sorry wrong input" << endl;
}
delete bptr;
return 0;
}