实验上机课的程序

来源:互联网 发布:儿童英语培训 知乎 编辑:程序博客网 时间:2024/05/16 05:59

#include"iostream"
#include"cmath"
using namespace std;

class Point
{
private:
 double point_x;
 double point_y; 
public:
 void show_point();
 double back_x();
 double back_y();
 Point(double x,double y);
 Point();
 friend void calculate(Point point_1,Point point_2);
};

void Point::show_point()
{
 cout<<"the coordinates of the point is "
  <<"("<<point_x<<","<<point_y<<")"<<endl;
}

double Point::back_x()
{
 return point_x;
}

double Point::back_y()
{
 return point_y;
}

Point::Point(double x,double y)
{
 point_x=x;
 point_y=y;
}

Point::Point():point_x(0),point_y(0)
{
 //Body intentionnally empty
}

void calculate(Point point_1,Point point_2)
{
 cout<<"the distance between point_1 and point_2 is "<<(sqrt(pow(point_1.point_x-point_2.point_x,2)+pow(point_1.point_y-point_2.point_y,2)))<<endl;
}

int main()
{
 double x1,y1,x2,y2;
 cout<<"Please enter the coordinates of the first point"<<endl;
 cin>>x1>>y1;
 Point point_1(x1,y1),point_2;
 point_1.show_point();
 point_2.show_point();
 x2=point_1.back_x();
 y2=point_1.back_y();
 cout<<"The coordinates of the first point is"<<"("<<x2<<","<<y2<<")"<<endl;
 calculate(point_1,point_2);
 cout<<"success"<<endl;
 return 0;
}

原创粉丝点击