-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.cpp
67 lines (53 loc) · 1.17 KB
/
1.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
#include<iostream>
#include<Cmath>
#include<cstdlib>
using namespace std;
class Ctriangle
{
private:
double A,B,C; //设三条边
public:
Ctriangle(double a=0,double b=0,double c=0) //创建一个构造函数初始化
{
A=a,B=b,C=c;
}
void Set_func(double a,double b,double c) //把形参传入私有数据元素中
{
if(a+b>c&&a+c>b&&b+c>a)
{
A=a;
B=b;
C=c;
}
else
{
cout<<"输入三边值无法构成三角形"<<endl;
exit(0);
}
}
double Area(double a,double b,double c)
{
double p=(a+b+c)/2; //在函数内新建一个p变量用于存放周长
return sqrt(p*(p-a)*(p-b)*(p-c));
}
double Circle(double a,double b,double c)
{
return a+b+c;
}
};
int main()
{
Ctriangle delta;
double x,y,z;
cout<<"请输入三角形三边值:"<<endl;
cout<<"A=";
cin>>x;
cout<<"B=";
cin>>y;
cout<<"C=";
cin>>z;
delta.Set_func(x,y,z);
cout<<"C:"<<delta.Circle(x,y,z)<<endl;
cout<<"S:"<<delta.Area(x,y,z)<<endl;
return 0;
}