-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.cpp
More file actions
71 lines (67 loc) · 1.24 KB
/
inheritance.cpp
File metadata and controls
71 lines (67 loc) · 1.24 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
#include <iostream>
#include <string>
using namespace std;
class Shape {
private:
int x;
int y;
public:
Shape(int X = 0, int Y = 0)
:x(X), y(Y) {
cout << "Shape Constructor..." << endl;
}
void setCoord(int X, int Y) {
x = X;
y = Y;
}
void print() {
cout << "(" << x<<"," << y << ")";
}
};
class Circle :public Shape {
float radius;
public:
Circle(int X = 0, int Y = 0, float r = 0)
:Shape(X, Y), radius(r) {
cout << "Circle Constructor..." << endl;
}
void setRadius(float r) {
radius = r;
}
void print() {
Shape::print();
cout <<", "<<radius;
}
};
class ColoredCircle :public Circle {
string color;
public:
ColoredCircle(int X = 0, int Y = 0, float r = 0,string c="red")
:Circle(X, Y,r), color(c) {
cout << "ColoredCircle Constructor..." << endl;
}
void setColor(string c) {
color = c;
}
void print() {
Circle::print();
cout << ", " << color;
}
};
int main() {
Circle c1(1, 2, 5.0);
c1.setCoord(3, 2);
c1.setRadius(7);
c1.print();
cout << endl;
ColoredCircle cc(1, 2, 5.0,"blue");
cc.setCoord(3, 2);
cc.setRadius(7);
cc.setColor("yellow");
cc.print();
Shape shape;
shape.setCoord(1, 2);
shape.print();
cout << endl;
return 0;
}