-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathTriangleShape.cpp
More file actions
85 lines (67 loc) · 1.45 KB
/
Copy pathTriangleShape.cpp
File metadata and controls
85 lines (67 loc) · 1.45 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
#include<iostream>
using namespace std;
class Shape{
public:
virtual void draw(){
cout<<"Shape Base Class"<<endl;
}
};
class Triangle: public Shape{
public:
virtual void draw(){
cout<<"Drawing Triangle...."<<endl;
}
void print(){
cout<<"This is Triangle.."<<endl;
}
};
class Rectangle: public Shape{
public:
virtual void draw(){
cout<<"Drawing Rectangle...."<<endl;
}
};
class Square: public Shape{
public:
virtual void draw(){
cout<<"Drawing Square...."<<endl;
}
};
class Circle: public Shape{
public:
virtual void draw(){
cout<<"Drawing Circle...."<<endl;
}
};
int main(){
Shape *sp[10];
Triangle t; //Derived class object
//t.draw();
Shape s; //Base class object
//s.draw();
Triangle *tptr; //Derived class Pointer
//tptr->draw();
Shape *sptr; //Base class Pointer
//sptr->draw();
sptr = &s; //Aim base class pointer at the base class object
//sptr->draw();
tptr = &t; //Aim derived class pointer at the derived class object
//tptr->draw();
sptr = &t; //Aim base class pointer at the derived class object
//sptr->draw();
// sptr->print();
// tptr = &s; //Aim derived class pointer at the base class object
// tptr->draw();
sp[0] = tptr;
// sp[0]->draw();
sp[1] = &t;
// sp[0]->draw();
sp[2] = new Triangle();
// sp[2]->draw();
sp[3] = new Square();
sp[4] = new Rectangle();
sp[5] = new Circle();
for(int i=0; i<6; i++){
sp[i]->draw();
}
}