c#题目,求解答
2个回答
展开全部
50块钱帮写好。12261940717
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//三角形
class Triangle
{
private double _a;
private double _b;
private double _c;
private bool _isTriangle;
private double _perimeter;
private double _area;
public Triangle(double a ,double b,double c)
{
_a = a;
_b = b;
_c = c;
}
public bool isTriangle()
{
if ((_a + _b <= _c) || (_a + _c <= _b) || (_b + _c <= _a))
{
_isTriangle = false;
}
else
{
_isTriangle = true;
}
return _isTriangle;
}
public double calPerimeter()
{
if (_isTriangle)
{
_perimeter = _a + _b + _c;
}
return _perimeter;
}
public double calArea()
{
double p;
if (_isTriangle)
{
p = (_a + _b + _c) / 2;
_area= Math.Sqrt(p * (p - _a) * (p - _b) * (p - _c));
}
return _area;
}
}
//主函数
static void Main(string[] args)
{
double[] a=new double[3];
for(int i=0;i<3;i++)
{
a[i]=Convert.ToDouble( Console.ReadLine());
}
Triangle triangle = new Triangle(a[0],a[1],a[2]);
if (triangle.isTriangle())
{
Console.WriteLine("周长:{0}", triangle.calPerimeter());
Console.WriteLine("面积:{0}", triangle.calArea());
}
else
{
Console.WriteLine("构不成三角形");
}
Console.ReadLine();
}
class Triangle
{
private double _a;
private double _b;
private double _c;
private bool _isTriangle;
private double _perimeter;
private double _area;
public Triangle(double a ,double b,double c)
{
_a = a;
_b = b;
_c = c;
}
public bool isTriangle()
{
if ((_a + _b <= _c) || (_a + _c <= _b) || (_b + _c <= _a))
{
_isTriangle = false;
}
else
{
_isTriangle = true;
}
return _isTriangle;
}
public double calPerimeter()
{
if (_isTriangle)
{
_perimeter = _a + _b + _c;
}
return _perimeter;
}
public double calArea()
{
double p;
if (_isTriangle)
{
p = (_a + _b + _c) / 2;
_area= Math.Sqrt(p * (p - _a) * (p - _b) * (p - _c));
}
return _area;
}
}
//主函数
static void Main(string[] args)
{
double[] a=new double[3];
for(int i=0;i<3;i++)
{
a[i]=Convert.ToDouble( Console.ReadLine());
}
Triangle triangle = new Triangle(a[0],a[1],a[2]);
if (triangle.isTriangle())
{
Console.WriteLine("周长:{0}", triangle.calPerimeter());
Console.WriteLine("面积:{0}", triangle.calArea());
}
else
{
Console.WriteLine("构不成三角形");
}
Console.ReadLine();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询