c++基本应用

/*利用点、线、面的基本知识,声明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;
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值