codecamp

实验上机课的程序

#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;
}

const用法详解 (摘抄笔记)
a new c++ program
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }