关于类的一个小问题 目的:求三角行的周长

来源:百度知道 编辑:UC知道 时间:2024/05/31 18:52:12
#include<iostream>
#include <cmath>
using namespace std;
class point
{float X,Y;
public: point (float xx,float yy) {X=xx;Y=yy;}
~point() {cout<<"析够函数被调用。"<<endl;};
float getX() {return X ;};
float getY() {return Y ;};
};
class straight
{float lenth;point a,b,c;
public:straight(point A,point B,point C);
float getlenth() {return lenth;};
};
straight::straight(point A,point B,point C):a(A),b(B),c(C)
{ double lenth1=sqrt((a.getX-b.getX)*(a.getX-b.getX)+(a.getY-b.getY)*(a.getY-b.getY));
double lenth2=sqrt((a.getX-c.getX)*(a.getX-c.getX)+(a.getY-c.getY)*(a.getY-c.getY));
double lenth3=sqrt((b.getX-c.getX)*(b.getX-c.getX)+(b.getY-c.getY)*(b.getY-c.getY));
lenth=lenth1+lenth2+lenth3;
};
void main()
{ point A(2,3),B(2,2),C(3,2);
straight stri(A,B,C);
cout<<"请输出三角形的周长:"<<s

#include<iostream>
#include <cmath>
using namespace std;
class point
{float X,Y;
public: point (float xx,float yy) {X=xx;Y=yy;}
~point() {cout<<"析够函数被调用。"<<endl;};
float getX() {return X ;};
float getY() {return Y ;};
};
class straight
{float lenth;point a,b,c;
public:straight(point A,point B,point C);
float getlenth() {return lenth;};
};
straight::straight(point A,point B,point C):a(A),b(B),c(C)
{
double lenth1=sqrt((a.getX()-b.getX())*(a.getX()-b.getX())+(a.getY()-b.getY())*(a.getY()-b.getY()));
double lenth2=sqrt((a.getX()-c.getX())*(a.getX()-c.getX())+(a.getY()-c.getY())*(a.getY()-c.getY()));
double lenth3=sqrt((b.getX()-c.getX())*(b.getX()-c.getX())+(b.getY()-c.getY())*(b.getY()-c.getY()));
lenth=lenth1+lenth2+lenth3;
};
void main()
{
point A(2,3),B(2,2),C(3,2);
straight stri(A,B,C)