This repository has been archived by the owner on Jun 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTRIANGLE.CPP
86 lines (62 loc) · 1.93 KB
/
TRIANGLE.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
#include "TRIANGLE.H"
#include <iostream>
#include <cmath>
Triangle::Triangle() : side_a(0), side_b(0), side_c(0) {
}
Triangle::Triangle(size_t i, size_t j, size_t k) : side_a(i), side_b(j), side_c(k) {
//std::cout << "Triangle created: " << side_a << ", " << side_b << ", " << side_c << std::endl;
}
Triangle::Triangle(const Triangle& orig) {
//std::cout << "Triangle copy created" << std::endl;
side_a = orig.side_a;
side_b = orig.side_b;
side_c = orig.side_c;
}
Triangle::Triangle(std::istream &is) {
is >> side_a;
is >> side_b;
is >> side_c;
}
double Triangle::Square() {
double p = double(side_a + side_b + side_c) / 2.0;
return sqrt(p * (p - double(side_a))*(p - double(side_b))*(p - double(side_c)));
}
void Triangle::Print() {
std::cout << "Ňđĺóăîëüíčę:" << std::endl;
std::cout << "a=" << side_a << ", b=" << side_b << ", c=" << side_c << std::endl;
}
Triangle::~Triangle() {
//std::cout << "Triangle deleted" << std::endl;
}
Triangle& Triangle::operator=(const Triangle& right) {
if (this == &right) return *this;
//std::cout << "Triangle copied" << std::endl;
side_a = right.side_a;
side_b = right.side_b;
side_c = right.side_c;
return *this;
}
/*
Triangle& Triangle::operator++() {
side_a++;
side_b++;
side_c++;
return *this;
}
Triangle operator+(const Triangle& left, const Triangle& right) {
return Triangle(left.side_a + right.side_a, left.side_b + right.side_b, left.side_c + right.side_c);
}
*/
std::ostream& operator<<(std::ostream& os, const Triangle& obj) {
os << "a=" << obj.side_a << ", b=" << obj.side_b << ", c=" << obj.side_c;
return os;
}
std::istream& operator>>(std::istream& is, Triangle& obj) {
is >> obj.side_a;
is >> obj.side_b;
is >> obj.side_c;
return is;
}
bool Triangle::operator==(const Triangle& obj) const {
return ((side_a == obj.side_a) && (side_b == obj.side_b) && (side_c == obj.side_c));
}