早教吧作业答案频道 -->其他-->
c++求三角形面积定义一个三角形类triangle,数据成员包含三角形的三条边,成员函数有:构造函数;判断是否能构成三角形的函数;求三角形面积的函数.编写主函数:输入三角形的三条边,判断能
题目详情
c++ 求三角形面积
定义一个三角形类triangle,数据成员包含三角形的三条边,成员函数有:构造函数;判断是否能构成三角形的函数;求三角形面积的函数.
编写主函数:输入三角形的三条边,判断能否构成三角形,如果能构成,则打印出面积(保留小数点后4位小数);否则打印出“no triangle”.
输入格式:测试输入包含若干测试用例,每个测试用例占一行.当读入0 0 0时输入结束,相应的结果不要输出.
Sample Input
3 4 5
6 3 5
20 13 0
0 0 0
Sample Output:
6.0000
7.4833
no triangle
Sample Input:
1 2 3
5 3 6
0 0 0
Sample Input
no triangle
7.4833
#include
#include
#include
using namespace std;
class triangle{
public:
\x05 float a[3];
\x05 int judge();
\x05 float s();
\x05 triangle(){}
private:
int i;
\x05 float t,p;
}tr;
int triangle ::judge(){
\x05 for(i=0;ia[i+1]){
\x05\x05\x05 t=a[i];
\x05\x05\x05 a[i]=a[i+1];
\x05\x05\x05 a[i+1]=t;
\x05\x05 }
\x05 }
\x05 if(a[0]+a[1]>a[2])
\x05\x05 return 1;
\x05 else return 0;
}
float triangle ::s(){
\x05 p=(a[0]+a[1]+a[2])/2;
\x05 return sqrt(p*(p-a[0])*(p-a[1])*(p-a[2]));
}
int main(){
\x05 while(1){
\x05\x05 cin>>tr.a[0]>>tr.a[1]>>tr.a[2];
\x05\x05 if(tr.a[0]==0&&tr.a[1]==0&&tr.a[2]==0)
\x05\x05\x05 return 0;
\x05\x05 if(tr.a[0]!=0&&tr.a[1]!=0&&tr.a[2]!=0){
\x05\x05\x05 if(tr.judge()==1)
\x05\x05\x05\x05 cout
定义一个三角形类triangle,数据成员包含三角形的三条边,成员函数有:构造函数;判断是否能构成三角形的函数;求三角形面积的函数.
编写主函数:输入三角形的三条边,判断能否构成三角形,如果能构成,则打印出面积(保留小数点后4位小数);否则打印出“no triangle”.
输入格式:测试输入包含若干测试用例,每个测试用例占一行.当读入0 0 0时输入结束,相应的结果不要输出.
Sample Input
3 4 5
6 3 5
20 13 0
0 0 0
Sample Output:
6.0000
7.4833
no triangle
Sample Input:
1 2 3
5 3 6
0 0 0
Sample Input
no triangle
7.4833
#include
#include
#include
using namespace std;
class triangle{
public:
\x05 float a[3];
\x05 int judge();
\x05 float s();
\x05 triangle(){}
private:
int i;
\x05 float t,p;
}tr;
int triangle ::judge(){
\x05 for(i=0;ia[i+1]){
\x05\x05\x05 t=a[i];
\x05\x05\x05 a[i]=a[i+1];
\x05\x05\x05 a[i+1]=t;
\x05\x05 }
\x05 }
\x05 if(a[0]+a[1]>a[2])
\x05\x05 return 1;
\x05 else return 0;
}
float triangle ::s(){
\x05 p=(a[0]+a[1]+a[2])/2;
\x05 return sqrt(p*(p-a[0])*(p-a[1])*(p-a[2]));
}
int main(){
\x05 while(1){
\x05\x05 cin>>tr.a[0]>>tr.a[1]>>tr.a[2];
\x05\x05 if(tr.a[0]==0&&tr.a[1]==0&&tr.a[2]==0)
\x05\x05\x05 return 0;
\x05\x05 if(tr.a[0]!=0&&tr.a[1]!=0&&tr.a[2]!=0){
\x05\x05\x05 if(tr.judge()==1)
\x05\x05\x05\x05 cout
▼优质解答
答案和解析
#include
#include
using namespace std;
int main()
{
double a,b,c,m,s;
coutb>>c;
m=(a+b+c)/2;
if((a+b>c)||(a+c>b)||(b+c>a))
{
s=sqrt(m*(m-a)*(m-b)*(m-c));
cout
#include
using namespace std;
int main()
{
double a,b,c,m,s;
coutb>>c;
m=(a+b+c)/2;
if((a+b>c)||(a+c>b)||(b+c>a))
{
s=sqrt(m*(m-a)*(m-b)*(m-c));
cout
看了c++求三角形面积定义一个三角...的网友还看了以下:
设A为n阶矩阵,证明:R(A+I)+R(A-I)>=n已知R(A)=R(kA),k≠0;R(A+B 2020-05-14 …
求直线簇的方程及其包络线的方程给定n,在x轴上取点Pi(i/n,0),在y轴上取点Qi(0,i/n 2020-07-01 …
C语言冒泡排序法,疑问啊~~~~~~~~~~~~~~~~~#include<stdio.h>#de 2020-07-23 …
(A/P,i,n)=(A/F,i,n)+i或(A/F,i,n)=(A/P,i,n)-i我已经知道怎 2020-07-23 …
数列极限lim{((1³+2³+...n³)/n³)-4/n},n趋于无穷的极限?(1³+2³+.. 2020-11-01 …
设f(i,k)=i•2(k-1)(i∈N*,k∈N*),如f(2,3)=2×2(3-1)=8.对于正 2020-11-01 …
Y|I|N|U|O开头的英文单词组成的句子.另外一题是Y|I|N|U|O开头的英文单词组成的句子这个 2020-11-03 …
若n属于不包括零的自然数,则[(1+i)^n+(1-i)^n]/[(1+i)^n-(1-i)^n]的 2020-11-18 …
在资金时间价值计算时,i和n给定,下列等式中正确的有().A.(F/A,i,n)=[(P/F,i,n 2021-01-14 …
1、在资金时间价值计算时,i和n给定,下列等式中正确的有?为什么?1、A(F/A,i,n)=[(P/ 2021-01-14 …