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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#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);
float medianatoMin(float,float,float);
bool isRight();
double GetLen(int);
//double GetLen(int) { return a; return b; return c; }
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];
}
/*
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));}
*/
float triangle::medianatoMin(float a,float b,float c){
float r;r=min(a,min(b,c));
cout<<r<<endl;
if(a==r)
return 0.5*sqrt((2*b*b)+(2*c*c)-(a*a));
if(b==r)
return 0.5*sqrt((2*a*a)+(2*c*c)-(b*b));
if(c==r)
return 0.5*sqrt((2*a*a)+(2*b*b)-(c*c));
}
int main() {
triangle trg(1.0, 2.0, 4.0, 1.0, 1.0, 5.0);
float q,w,e,k;
q=trg.GetLen(0);
w=trg.GetLen(1);
e=trg.GetLen(2);
std::cout<<"a:"<<q<<"\t"<<"b:"<<w<<"\t"<<"c:"<<e<<endl;
// k=min(q,min(w,e));
std::cout<<"mediana_Min:"<<trg.medianatoMin(q,w,e)<<endl;
//cout<<k;
/*
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;
*/
return 0;
}