/*利用点、线、面的基本知识,声明Point,Line,Friangle,PolyAngle四个类,完成以下功能。
Point类功能:
(1) 移动一个点;
(2) 显示一个点;
(3) 可计算这个点到原点的距离。
Line类功能:
(1) 计算点到直线的距离;
(2) 直线的斜率;
(3) 判断两条直线的关系(平行/相交(交点坐标能够给出来并显示)/垂直);
Friangle类功能:
(1) 判断三点能否构成三角形;
(2) 判断三角形是等边,等腰或者是直角;
(3) 计算三角形的面积。
#include<iostream>
#include<math.h>
using namespace std;
class Line;
class Point
{
public:
void show();
float distance();
void inset();
friend double dist(Point P,Line L);
private:
float x;
float y;
};
class Line
{
public:
Line(int a,int b,int c):aa(a),bb(b),cc(c){};
double straight_slope(Line L);
friend double dist(Point P,Line L);//不是很理解为啥同时出现二次
void position(Line L1,Line L2);
int aa;
int bb;
int cc;
};
class Friangle
{
private:
int a;
int b;
int c;
public:
void inset();
};
void Friangle::inset()
{
cout<<"请输入三边的长度\n";
double s1,s2;
cin>>a>>b>>c;
if(a+b>c&&b+c>a&&a+c>b)
{
cout<<"能构成三角形"<<endl;
if(a==b&&b==c)
cout<<"等边三角形\n";
else if(a==b&&a!=c)
cout<<"等腰三角形\n";
else if(a*a+b*b==c*c||b*b+c*c==a*a||a*a+c*c==b*b)
cout<<"直角三角形\n";
double s1,s2;
s1=(a+b+c)/2;
s2=sqrt(s1*(s1-a)*(s1-b)*(s1-c));
cout<<"三角形的面积是"<<s2<<endl;
}
else
{
cout<<"不能构成三角形"<<endl;
}
}
/*Friangle类功能:
(1) 判断三点能否构成三角形;
(2) 判断三角形是等边,等腰或者是直角;
(3) 计算三角形的面积。
*/
double dist(Point P,Line L)
{
double s;
s=(L.aa*P.x+L.bb*P.y+L.cc)/sqrt(L.aa*L.aa+L.bb*L.bb);
if(s>0)
return s;
else
return -s;
}
double Line:: straight_slope(Line L)
{
double k;
k=-(L.aa/L.bb);
return k;
}
void Line::position(Line L1,Line L2)
{
double x,y;
double s1,s2;
s1=L1.straight_slope(L1);
s2=L2.straight_slope(L2);
if(s1==s2)
cout<<"两条直线位置平行"<<endl;
else if(s1*s2==0)
cout<<"两条直线位置垂直"<<endl;
else
{
if(L1.aa*x+L1.bb*y+L1.cc==0&&L2.aa*x+L2.bb*y+L2.cc==0)
{
cout<<"交点坐标是\n";
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
}
}
void Point ::show()
{
cout<<"坐标:"<<"("<<x<<","<<y<<")"<<endl;
}
float Point ::distance()
{
cout<<"到原点距离:"<<sqrt(x*x+y*y)<<endl;
return sqrt(x*x+y*y);
}
void Point ::inset()
{
cout<<"请输入坐标"<<endl;
cin>>x>>y;
}
int main ()
{
Point A;
A.inset();
A.show();
A.distance();
Line L1(1,1,1),L2(1,1,1),L3(0,0,0);
cout<<"点到直线的距离是:"<<dist(A,L1)<<endl;
cout<<"直线的斜率是:"<<L1.straight_slope(L1)<<endl;
cout<<"直线的斜率是:"<<L2.straight_slope(L2)<<endl;
L1.position(L1,L2);
Friangle s;
s.inset();
return 0;
}
Point类功能:
(1) 移动一个点;
(2) 显示一个点;
(3) 可计算这个点到原点的距离。
Line类功能:
(1) 计算点到直线的距离;
(2) 直线的斜率;
(3) 判断两条直线的关系(平行/相交(交点坐标能够给出来并显示)/垂直);
Friangle类功能:
(1) 判断三点能否构成三角形;
(2) 判断三角形是等边,等腰或者是直角;
(3) 计算三角形的面积。
#include<iostream>
#include<math.h>
using namespace std;
class Line;
class Point
{
public:
void show();
float distance();
void inset();
friend double dist(Point P,Line L);
private:
float x;
float y;
};
class Line
{
public:
Line(int a,int b,int c):aa(a),bb(b),cc(c){};
double straight_slope(Line L);
friend double dist(Point P,Line L);//不是很理解为啥同时出现二次
void position(Line L1,Line L2);
int aa;
int bb;
int cc;
};
class Friangle
{
private:
int a;
int b;
int c;
public:
void inset();
};
void Friangle::inset()
{
cout<<"请输入三边的长度\n";
double s1,s2;
cin>>a>>b>>c;
if(a+b>c&&b+c>a&&a+c>b)
{
cout<<"能构成三角形"<<endl;
if(a==b&&b==c)
cout<<"等边三角形\n";
else if(a==b&&a!=c)
cout<<"等腰三角形\n";
else if(a*a+b*b==c*c||b*b+c*c==a*a||a*a+c*c==b*b)
cout<<"直角三角形\n";
double s1,s2;
s1=(a+b+c)/2;
s2=sqrt(s1*(s1-a)*(s1-b)*(s1-c));
cout<<"三角形的面积是"<<s2<<endl;
}
else
{
cout<<"不能构成三角形"<<endl;
}
}
/*Friangle类功能:
(1) 判断三点能否构成三角形;
(2) 判断三角形是等边,等腰或者是直角;
(3) 计算三角形的面积。
*/
double dist(Point P,Line L)
{
double s;
s=(L.aa*P.x+L.bb*P.y+L.cc)/sqrt(L.aa*L.aa+L.bb*L.bb);
if(s>0)
return s;
else
return -s;
}
double Line:: straight_slope(Line L)
{
double k;
k=-(L.aa/L.bb);
return k;
}
void Line::position(Line L1,Line L2)
{
double x,y;
double s1,s2;
s1=L1.straight_slope(L1);
s2=L2.straight_slope(L2);
if(s1==s2)
cout<<"两条直线位置平行"<<endl;
else if(s1*s2==0)
cout<<"两条直线位置垂直"<<endl;
else
{
if(L1.aa*x+L1.bb*y+L1.cc==0&&L2.aa*x+L2.bb*y+L2.cc==0)
{
cout<<"交点坐标是\n";
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
}
}
void Point ::show()
{
cout<<"坐标:"<<"("<<x<<","<<y<<")"<<endl;
}
float Point ::distance()
{
cout<<"到原点距离:"<<sqrt(x*x+y*y)<<endl;
return sqrt(x*x+y*y);
}
void Point ::inset()
{
cout<<"请输入坐标"<<endl;
cin>>x>>y;
}
int main ()
{
Point A;
A.inset();
A.show();
A.distance();
Line L1(1,1,1),L2(1,1,1),L3(0,0,0);
cout<<"点到直线的距离是:"<<dist(A,L1)<<endl;
cout<<"直线的斜率是:"<<L1.straight_slope(L1)<<endl;
cout<<"直线的斜率是:"<<L2.straight_slope(L2)<<endl;
L1.position(L1,L2);
Friangle s;
s.inset();
return 0;
}