展开全部
#include <iostream.h>
#include<math.h>
class Point{
public:
int x, y;
Point(){
x=1;
y=1;
}
Point(int a,int b)
{
x=a;
y=b;
}
};
class Triangle{
private:
Point p1,p2,p3;
double p;
public:
Triangle(){
p1=Point(1,1);
p2=Point(3,1);
p3=Point(2,2);
}
void premeter(){
p=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y))+sqrt((p1.x-p3.x)*(p1.x-p3.x)+(p1.y-p3.y)*(p1.y-p3.y))+sqrt((p3.x-p2.x)*(p3.x-p2.x)+(p3.y-p2.y)*(p3.y-p2.y));
}
void display(){
cout<<"三角形的周长="<<p<<endl;
}
};
void main(){
Triangle *t= new Triangle();
t->premeter();
t->display();
}
#include<math.h>
class Point{
public:
int x, y;
Point(){
x=1;
y=1;
}
Point(int a,int b)
{
x=a;
y=b;
}
};
class Triangle{
private:
Point p1,p2,p3;
double p;
public:
Triangle(){
p1=Point(1,1);
p2=Point(3,1);
p3=Point(2,2);
}
void premeter(){
p=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y))+sqrt((p1.x-p3.x)*(p1.x-p3.x)+(p1.y-p3.y)*(p1.y-p3.y))+sqrt((p3.x-p2.x)*(p3.x-p2.x)+(p3.y-p2.y)*(p3.y-p2.y));
}
void display(){
cout<<"三角形的周长="<<p<<endl;
}
};
void main(){
Triangle *t= new Triangle();
t->premeter();
t->display();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询