计算2点的距离根据这个Point类,计算出距离.写个能运行的.class Point{public:Point(doub
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/08 21:50:46
计算2点的距离
根据这个Point类,计算出距离.写个能运行的.
class Point
{
public:
Point(double nx=0.0,double ny=0.0):x(nx),y(ny){}
Point(Point &np):x(np.x),y(np.y){}
double GetX(){return x;}
double GetY(){return y;}
void SetX(double nx){x=nx;}
void SetY(double ny){y=ny;}
void SetPoint(Point &np){x=np.x;y=np.y;}
private:
double x,y;
};
根据这个Point类,计算出距离.写个能运行的.
class Point
{
public:
Point(double nx=0.0,double ny=0.0):x(nx),y(ny){}
Point(Point &np):x(np.x),y(np.y){}
double GetX(){return x;}
double GetY(){return y;}
void SetX(double nx){x=nx;}
void SetY(double ny){y=ny;}
void SetPoint(Point &np){x=np.x;y=np.y;}
private:
double x,y;
};
该题有好多种写法.我用C++写了其中的一种,代码如下:
#include
#include
using namespace std;
class Point
{
public:
Point(double nx=0.0,double ny=0.0):x(nx),y(ny){}
Point(Point &np):x(np.x),y(np.y){}
double GetX(){return x;}
double GetY(){return y;}
void SetX(double nx){x=nx;}
void SetY(double ny){y=ny;}
void SetPoint(Point &np){x=np.x;y=np.y;}
private:
double x,y;
};
int main(){
double distance;//A,B两点间的距离
Point A(1.5,2.8);
Point B(3.9,4.6);
distance = sqrt((B.GetY()-A.GetY())*(B.GetY()-A.GetY())+(B.GetX()-A.GetX())*(B.GetX()-A.GetX()));
cout
#include
#include
using namespace std;
class Point
{
public:
Point(double nx=0.0,double ny=0.0):x(nx),y(ny){}
Point(Point &np):x(np.x),y(np.y){}
double GetX(){return x;}
double GetY(){return y;}
void SetX(double nx){x=nx;}
void SetY(double ny){y=ny;}
void SetPoint(Point &np){x=np.x;y=np.y;}
private:
double x,y;
};
int main(){
double distance;//A,B两点间的距离
Point A(1.5,2.8);
Point B(3.9,4.6);
distance = sqrt((B.GetY()-A.GetY())*(B.GetY()-A.GetY())+(B.GetX()-A.GetX())*(B.GetX()-A.GetX()));
cout
计算2点的距离根据这个Point类,计算出距离.写个能运行的.class Point{public:Point(doub
已知有如下类的定义:public class Point { private double x,y; public Po
类定义为什么要这样class point{public:double x,y;point(){};point(doubl
class Point{ protected int x,y; public Point(){} public Poin
point
定义点POINT 类,在该类中定义点的坐标,定义线做类,可通过线类中的成员函数计算该类中二点间的距离
设计一个点类Point其属性为其x,y坐标,能计算该点到(0,0)的距离.
设计一个点类Point,并为这个类设置一个友元函数,这个友元函数用来计算两个点之间的距离.要求主函数如下:
class Point { int x_,y_; public:Point():x_(0),y_(0){} Point(
自定义包时出现的问题package com.juj;public class Point{ private int x,
point out point to point at的区别是什么?
point towards和point at 的区别.