首页 > 其他 > 详细

使用内联函数设计一个类,用来表示直角坐标系中的任意一条直线并输出它的属性

时间:2019-11-19 14:39:44      阅读:91      评论:0      收藏:0      [点我收藏+]

源程序:

//2.使用内联函数设计一个类,用来表示直角坐标系中的任意一条直线并输出它的属性。

#include < iostream.h >

#include < math.h >

class Line

{

private:

  int x1, y1, x2, y2;

public :

  //Line();

  Line(int =0, int =0, int =0, int=0 );

  void printPoint();

  double getLength();

};

inline Line::Line(int a, int b, int c, int d)

{

  x1 = a;

  y1 = b;

  x2 = c;

  y2 = d;

}

inline void Line::printPoint()

{

  cout<<"A:"<< x1 <<", "<< y1 << endl;

  cout<<"B:"<< x2 <<", "<< y2 << endl;

}

inline double Line::getLength()

{

  double length;

  length = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) );

  return length;

}

void main()

{

  Line line(10,80,-10,12);

  line.printPoint();

  cout<< line.getLength() << endl;

}

 运行结果:

技术分享图片

使用内联函数设计一个类,用来表示直角坐标系中的任意一条直线并输出它的属性

原文:https://www.cnblogs.com/duanqibo/p/11889257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!