首页 > 教育

c版。考研题

更新时间2018-12-04 17:49:30

定义一个类Point.要求如下所述。(1)用构造函数初始化类Point的对象。(2)定义函数Distantce,计算平面上两点之间的距离。

(1)用构造函数初始化类Point的对象

//

#include 

#include 

using namespace std;

class Point

{

public:

Point(double _x = 0, double _y = 0) : 

x(_x), y(_y) { cout


(2)定义函数Distantce,计算平面上两点之间的距离

#include<stdio.h>

#include<math.h>

double dist(double x1,double y1,double x2,double y2)

{

double s;

s=sqrt(pow((x2-x1),2)+pow((y2-y1),2));

return s;

}

int main()

{

double x1,y1,x2,y2,s;

scanf("%lf%lf",&x1,&y1);

scanf("%lf%lf",&x2,&y2);

s=dist(x1,y1,x2,y2);

printf("%.2lf",s);

return 0;

}


上一篇:在滕州市中学有哪些

下一篇:技校老师想整学生怎么办?