-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRECTANGLE.CPP
92 lines (73 loc) · 1.32 KB
/
RECTANGLE.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
83
84
85
86
87
88
89
90
91
#include<iostream>
using namespace std;
class triangle
{
float base, height;
public:
triangle(float m = 0, float k = 0)
{
base = m;
height = k;
}
float getbase(){return base;}
float geth(){return height;}
void takesides(float m, float n)
{
base = m;
height = n;
}
virtual float area()
{
return ( base * height / 2 );
}
};
class square:public triangle
{
public:
square(float m = 0 , float k = 0 ):triangle(m,k)
{
}
float are()
{
return ( area() * 2 );
}
};
class rectangle:public triangle
{
public:
rectangle(float m = 0, float k = 0):triangle(m,k)
{
}
rectangle operator + (square & sq)
{
rectangle local;
local.takesides(sq.getbase() + this->getbase() , sq.geth() + this->geth());
return local;
}
rectangle operator + (rectangle &rec)
{
rectangle local;
local.takesides(rec.getbase() + this->getbase() , rec.geth() + this->geth());
return local;
}
float are()
{
return ( area() * 2 );
}
};
int main()
{
triangle Tfirst(10,6.5);
square Sfirst(10,10);
rectangle Rfirst(10,6.5);
rectangle RRfirst(10,3.5);
rectangle rockrec;
rockrec = Rfirst + RRfirst;
cout<<Tfirst.area()<<endl;
cout<<Sfirst.are()<<endl;
cout<<Rfirst.are()<<endl;
cout<<rockrec.are()<<endl;
rockrec = rockrec + Sfirst;
cout<<rockrec.are()<<endl;
return 0;
}