-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticing_poly.cpp
More file actions
85 lines (66 loc) · 1.02 KB
/
practicing_poly.cpp
File metadata and controls
85 lines (66 loc) · 1.02 KB
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
// compile time polymorphism
// overloading
/*
#include<iostream>
using namespace std;
class add
{
public:
int sum(int a, int b)
{
cout<<"sum of integers is ="<<a+b<<endl;
}
int sum(int a, int b,int c)
{
cout<<"sum of 3 integers is ="<<a+b+c<<endl;
}
double sum(double a, double b)
{
cout<<"sum of float variables is ="<<a+b<<endl;
}
};
int main()
{
add d;
d.sum(5,5);
d.sum(0.5,2.0);
d.sum(1,2,3);
return 0;
}
*/
// run time polymorphism
// overriding
#include<iostream>
using namespace std;
class shape
{
public:
virtual void draw()
{
cout<<"general drawing"<<endl;
}
};
class circle:public shape
{
void draw()
{
cout<<"circle is drawing"<<endl;
}
};
class rectangle:public shape
{
void draw()
{
cout<<"rectangle is drawing"<<endl;
}
};
int main()
{
shape *s;
rectangle r;
circle c;
s=&c;
s->draw();
s=&r;
s->draw();
}