阅读背景:

定义一个三角形类,求三角形面积和周长(c++)

来源:互联网 
#include<iostream>
using namespace std;
#include<Cmath>
class Ctriangle
{
private:
    float a,b,c;
    float s,l;
public:
    Ctriangle(float a=0,float b=0,float c=0)
    {
        this->a=a;
        this->b=b;
        this->c=c;
    }
    void setCtringle(float a,float b,float c)
    {
        this->a=a;
        this->b=b;
        this->c=c;
    }
    float area()
    {
        int p=(a+b+c)/2;
        s=sqrt(p*(p-a)*(p-b)*(p-c));
        return s;
    }
    float length()
    {
        l=a+b+c;
        return l;
    }
};
int main()
{
    float a,b,c;
    cin>>a>>b>>c;
    Ctriangle tringle(a,b,c);
    cout<<"面积:"<<tringle.area()<<" "<<"周长:"<<tringle.length()<<endl;
    return 0;
}
#include<iostream>
using namespace std;
#includ



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: