三角形类锥形
2016-04-03 10:58
204 查看
#include <iostream>
#include<cmath>
using namespace std;
class Triangle
{
public:
void setABC(double x,double y,double z);
double perimeter();
double area();
void setA(double x);
{
a=x;
}
void setB(double y);
{
b=y;
}
void setC(double z);
{
c=z;
}
bool isTriangle()
{
if(a+b>c&&a+c>b&&c+b>a)
{
return true;
}
else
return false;
}
private:
double a,b,c;
};
double Triangle::perimeter()
{
return a+b+c;
}
double Triangle::area()
{
double n;
n=(1.0/2)*(a+b+c);
return sqrt(n*(n+a)*(n-b)*(n-c));
}
int main()
{
Triangle tri1;
double x,y,z;
cin>>x>>y>>z;
tri1.setA(x);
tri1.setB(y);
tri1.setC(z);
if(tri.isTriangle())
{
cout<<"周长:"<<tri1.perimeter()<<'\t'<<"面积:"<<tri1.area()<<endl;
}
else
{
cout<<"不能构成三角形"<<endl;
}
return 0;
}
#include<cmath>
using namespace std;
class Triangle
{
public:
void setABC(double x,double y,double z);
double perimeter();
double area();
void setA(double x);
{
a=x;
}
void setB(double y);
{
b=y;
}
void setC(double z);
{
c=z;
}
bool isTriangle()
{
if(a+b>c&&a+c>b&&c+b>a)
{
return true;
}
else
return false;
}
private:
double a,b,c;
};
double Triangle::perimeter()
{
return a+b+c;
}
double Triangle::area()
{
double n;
n=(1.0/2)*(a+b+c);
return sqrt(n*(n+a)*(n-b)*(n-c));
}
int main()
{
Triangle tri1;
double x,y,z;
cin>>x>>y>>z;
tri1.setA(x);
tri1.setB(y);
tri1.setC(z);
if(tri.isTriangle())
{
cout<<"周长:"<<tri1.perimeter()<<'\t'<<"面积:"<<tri1.area()<<endl;
}
else
{
cout<<"不能构成三角形"<<endl;
}
return 0;
}
相关文章推荐
- Java 中无参无返回值方法的使用
- 【追求进步】腾讯实习生面试题
- 描述复数
- python中的operator库
- 求平面上两点距离
- android TextView中文字的阴影效果
- 项目中的一些轶事
- 声明式编程和命令式编程的比较(转)
- 通用PE u盘装Ghost Win7系统
- 在Spring中使用自定义的Annotation
- MySQL 查询缓存
- ++ function、bind以及lamda表达式
- java中缓存的使用
- IOS开发新的一天
- 求输入字母的总数
- 1122: 【C语言训练】亲密数
- Eclipse中格式化代码快捷键Ctrl+Shift+F失效的解决办法
- Request对象的主要方法
- lintcode:数字组合III
- [mysql] 报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost