include iostream include cmath include cstdio using namespace std clas

 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
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
class triangle {
public:
triangle();
triangle(double x1_, double y1_, double x2_, double y2_, double x3_, double y3_) {
x1 = x1_;
y1 = y1_;
x2 = x2_;
y2 = y2_;
x3 = x3_;
y3 = y3_;
a = length(x1, y1, x2, y2);
b = length(x2, y2, x3, y3);
c = length(x3, y3, x1, y1);
}
void operator+(float*);
double length(double, double, double, double);
float medianatoQ(float,float,float);
float medianatoW(float,float,float);
float medianatoE(float,float,float);
bool isRight();
double GetLen(int);
private:
double x1, y1;
double x2, y2;
double x3, y3;
double a, b, c;
};
double triangle::length(double x1_, double y1_, double x2_, double y2_) {
return sqrt((x2_ - x1_) * (x2_ - x1_) + (y2_ - y1_) * (y2_ - y1_));
}
/*
bool triangle::isRight() {
if ((sqrt(a * a + b * b) == c) || (sqrt(a * a + c * c) == b))
return true;
return false;
}
*/
double triangle::GetLen(int k) {
double arr[3] = {a, b, c};
return arr[k - 1];
}
float triangle::medianatoQ(float q,float w,float e){
return 0.5*sqrt((2*w*w)+(2*e*e)-(q*q));}
float triangle::medianatoW(float q,float w,float e){
return 0.5*sqrt((2*q*q)+(2*e*e)-(w*w));}
float triangle::medianatoE(float q,float w,float e){
return 0.5*sqrt((2*q*q)+(2*w*w)-(e*e));}
int main() {
triangle trg(1.0, 0.0, 4.0, 1.0, 1.0, 1.0);
float q,w,e;
q=trg.GetLen(1);
w=trg.GetLen(2);
e=trg.GetLen(3);
std::cout<<"a:"<<q<<"\t"<<"b:"<<w<<"\t"<<"c:"<<e<<endl;
if(q < w && q < e)
std::cout<<"medianaA:"<<trg.medianatoQ(q,w,e)<<endl;
else if(w < q && q < e)
std::cout<<"medianaB:"<<trg.medianatoW(q,w,e)<<endl;
else if(e < w && e < q)
std::cout<<"medianaC:"<<trg.medianatoE(q,w,e)<<endl;
//std::cout << trg.isRight() << " " << trg.GetLen(3);
return 0;
}