利用点、线、面的基本知识,声明Point,Line,Friangle,PolyAngle四个类,完成以下功能。
Point类功能://实验88888
(1) 移动一个点;
(2) 显示一个点;
(3) 可计算这个点到原点的距离。
Line类功能:
(1) 计算点到直线的距离;
(2) 直线的斜率;
(3) 判断两条直线的关系(平行/相交(交点坐标能够给出来并显示)/垂直);
Friangle类功能:
(1) 判断三点能否构成三角形;
(2) 判断三角形是等边,等腰或者是直角;
(3) 计算三角形的面积。
PolyAngle类功能:
(1) 判断四点能否构成四边形,并判断其是凹的,还是凸的;
(2) 判断四边形是否是等腰梯形;
(3) 判断四边形是否是平行四边形,菱形;
(4) 判断它是否是一个矩形;
(5) 计算四边形的面积和周长。
---恢复内容开始---
#include<iostream>
#include<math.h>
using namespace std;
class point
{
private:
int x;
int y;
public:
point()
{}
void move_point()
{
int i,j;
cout<<"输入位移量"<<endl;
cin>>i>>j;
x=i+x;
y=j+y;
}
void set_point()
{
cin>>x>>y;
}
void show()
{
cout<<"横坐标:"<<x<<" "<<"纵坐标"<<y<<endl;
}
int getx()
{
return x;
}
int gety()
{
return y;
}
void distance()
{
float s;
s=sqrt(x*x+y*y);
cout<<"点到原点的距离"<<s<<endl;
}
};
class line
{
private:
point a1;
point a2;
public:
line()
{}
void set_line()
{
cout<<"输入二个点"<<endl;
a1.set_point();
a2.set_point();
}
void dislinepoint(point &a3)
{
float b,k,d;
k=(a2.gety()-a1.gety())/(float)(a2.getx()-a1.getx());
b = a1.gety() - k*a1.getx();
d = fabs(k*a3.getx()-a3.gety()+b)/sqrt(k*k+1);
cout<<"点到直线的距离:"<<d<<endl;
}
void lineshow()
{
float k, b;
k=(a2.gety()-a1.gety())/((a2.getx()-a1.getx())*1.0);
cout<<"斜率为:"<<endl;
cout<<k<<endl;
b = a1.gety() - k*a1.getx();
cout<<"截距为:"<<endl;
cout<<b<<endl;
}
};
class triangle
{
private:
point a1;
point a2;
point a3;
public:
triangle()
{}
void set_triangle()
{
cout<<"输入三个点"<<endl;
a1.set_point();
a2.set_point();
a3.set_point();
}
void show_triangle()
{
judge_triangle();
}
void judge_triangle()
{
float a,b,c,d,s;
a=sqrt((a1.getx()-a2.getx())*(a1.getx()-a2.getx())+(a1.gety()-a2.gety())*(a1.gety()-a2.gety()));
b=sqrt((a2.getx()-a3.getx())*(a2.getx()-a3.getx())+(a2.gety()-a3.gety())*(a2.gety()-a3.gety()));
c=sqrt((a1.getx()-a3.getx())*(a1.getx()-a3.getx())+(a1.gety()-a3.gety())*(a1.gety()-a3.gety()));
if(((a>b-c)&&(a<b+c)) && ((b>a-c)&&(b<a+c)) && ((c>b-a)&&(c<b+a)))
{
cout<<"可以构成三角形"<<endl;
}
else
cout<<"不可以构成三角形"<<endl;
if((a==b)&&(b==c)&&(c==a))
{
cout<<"可以构成等边三角形"<<endl;
}
else
cout<<"不可以构成对等边三角形"<<endl;
if((a==b)||(b==c)||(c==a))
{
cout<<"可以构成等腰三角形"<<endl;
}
else
cout<<"不可以构成对等腰三角形"<<endl;
if(((a*a-b*b-c*c)>-0.01)&&((a*a-b*b-c*c)<0.01)||((b*b-a*a-c*c)>-0.01)&&((b*b-a*a-c*c)<0.01)||((c*c-a*a-b*b)>-0.01)&&((c*c-a*a-b*b)<0.01))
cout<<"可以构成直角三角形"<<endl;
else
cout<<"不可以构成直角三角形"<<endl;
d=(a+b+c)*1/2.0;
s=sqrt(d*(d-a)*(d-b)*(d-c));
cout<<"三角形的面积"<<s<<endl;
}
};
class polyangle
{
private:
point A;
point B;
point C;
point D;
public:
polyangle()
{}
void set_polyangle()
{
cout<<"输入四个点"<<endl;
A.set_point();
B.set_point();
C.set_point();
D.set_point();
}
void judge_polyangle()
{
float k1,k2,k3,k4;
float a,b,c,d;
float e,f;
float s1,s2,s;
float l,i;
k1=(float)(A.gety()-B.gety())/((A.getx()-B.getx()));
k2=(float)(B.gety()-C.gety())/((B.getx()-C.getx()));
k3=(float)(C.gety()-D.gety())/((C.getx()-D.getx()));
k4=(float)(D.gety()-A.gety())/((D.getx()-A.getx()));
a=sqrt((A.getx()-B.getx())*(A.getx()-B.getx())+(A.gety()-B.gety())*(A.gety()-B.gety()));
b=sqrt((B.getx()-C.getx())*(B.getx()-C.getx())+(B.gety()-C.gety())*(B.gety()-C.gety()));
c=sqrt((C.getx()-D.getx())*(C.getx()-D.getx())+(C.gety()-D.gety())*(C.gety()-D.gety()));
d=sqrt((D.getx()-A.getx())*(D.getx()-A.getx())+(D.gety()-A.gety())*(D.gety()-A.gety()));
e=sqrt((C.getx()-A.getx())*(C.getx()-A.getx())+(C.gety()-A.gety())*(C.gety()-A.gety()));
f=sqrt((D.getx()-B.getx())*(D.getx()-B.getx())+(D.gety()-B.gety())*(D.gety()-B.gety()));
if(((d!=b)&&(k4==k2)&&(a==c))||((a!=c)&&(k1==k3)&&(b==d)))
{
cout<<"是等腰梯形"<<endl;
}
else
cout<<"不是等腰梯形"<<endl;
if((k1==k3)&&(a==c))
{
cout<<"是平行四边形"<<endl;
if(a==b==c==d)
cout<<"该四边形为菱形"<<endl;
else
cout<<"该四边形不为菱形"<<endl;;
}
else
{
cout<<"不是平行四边形"<<endl;
}
if((k1==k3)&&(a==c)&&(k1*k2==-1))
{
cout<<"该四边形为矩形"<<endl;
}
else
cout<<"该四边形不为矩形"<<endl;
i=(a+b+e)*(1/2.0);
s1=sqrt(i*(i-a)*(i-b)*(i-e));
i=(d+c+e)*(1/2.0);
s2=sqrt(i*(i-d)*(i-c)*(i-e));
s=s1+s2;
cout<<"面积"<<s<<endl;
l=a+b+c+d;
cout<<"周长"<<l<<endl;
}
};
int main()
{
point a;
cout<<"输入一个点"<<endl;
a.set_point();
a.show();
a.distance();
line q;
q.set_line();
q.lineshow();
triangle p;
p.set_triangle();
p.show_triangle();
polyangle s;
s.set_polyangle();
s.judge_polyangle();
}