java编写point类line类_定义⼀个点类Point,有横坐标x和纵坐标
y,定义构造
公告: 为响应国家净⽹⾏动,部分内容已经删除,感谢读者理解。
话题:定义⼀个点类Point,有横坐标x和纵坐标y,定义构造函数初始化点,回答:#include class Point{private:double x;double
y;public:Point(): x(0.0), y(0.0) {};Point(double x, double y){this-x = x;this-y = y;}double getX() { return x; }double getY() { return y; }};class Line{private:Point p1;Point p2;public:Line(Point p1, Point p2){this-p1 = p1;this-p2 = p2;}double
getDistance(){return sqrt((p1.getX() - p2.getX()) * (p1.getX() - p2.getX()) + (p1.getY() - p2.getY()) * (p1.getY() -
话题:编写⼀个点类Point,包含x,y坐标、相应的获取及设置坐标的⽅法,试回答:public class Point { public double x; public double y; Point(double x, double y) { this.x=x;
this.y=y; } static Point getMiddle(Pointpoint1,Pointpoint2){ double px=(point1.x+point2.x)/2; double py=
(point1.y+point2.y)/2; Point
参考回答:class point{ private int x; private int y public void point(){ this.x=0; this.y=0; } public void point(int x,int y)
{this.x=x;this.y=y; } public void show() { system.out.println("x坐标:"+this.x); system.out.println("y坐标:"+this.y); } }话题:设计⼀个Point类,这个类描述屏幕上⼀个点的位置,即有两个数据成回答:include#include using namespace std;class
Point{public:Point(int a,int b):x(a),y(b){cout~Point(){coutvoid show(){coutdouble distance(Point p){return sqrt((p.y-y)*(p.x-y)+ (p.x-x)*(p.x-x));}private:int x;int y;};int main(){ Point a(0,0);Point b(1,1);coutreturn 0;}随便给你写了个,友元函数什么的估计你也没学,估计你刚学到类和对象
参考回答:很简单的,还是⾃⼰做吧。如果你明⽩类是怎么回事,就⼀定会做
话题:定义⼀个Point类,平⾯上的⼀个点,横坐标和纵坐标分别⽤x和y表回答:定义⼀个点类(Point),其数据成员包含横坐标和纵坐标;再定义⼀个距离类(Distance),⽤于描述两点之间的距离,其数据成员为两个点类对象和表⽰两点之间距离的变量。请完成以下程序,结果如下图所⽰。#include #include using
namespa
参考回答:展开全部 定义⼀个点类(Point),其数据成员包含横坐标和纵坐标;再定义⼀个距离类(Distance),⽤于描述两点之间的距离,其数据成员为两个点类对象和表⽰两点之间距离的变量。请完成以下程序,结果如下图所⽰。#include #include using namespace std;class Point { int x,y; //横坐标x和纵坐标ypublic: Point(int x=0,int y=0); //带有默认值的构造函数Point(Point p); //拷贝构造函数int getx(); //获取横坐标x的值int gety(); //获取纵坐标y的值}; //在此添加Point类的实现码class Distance { public:
Distance(Point q1,Point q2); //构造函数double getdist(); //获取点p1和点p2之间的距离private: Point p1,p2; //点p1和点
p2double dist; //表⽰点p1和点p2之间的距离}; //在此添加Distance类的实现码int main() { Point p1(5,3);Point *p; //在此添加相应的码Point p2(*p);//在此添加相应的码return 0;}
话题:Java⾯向对象程序设计回答:atch⽤于捕获initProperties()和init()这两个⽅⾏时候的异常,⾄于initProperties()和init()这两个⽅法为何会出异常,就看你具体的业务逻辑了。try中的码块⼉如果⼀旦出现异常则在catch中进⾏捕获,showMessageDialog是JOptionPane封装或者说提供的⼀个显⽰⼀个带有确定按钮的模态对话框的⽅法。⼏个参数中"Failed to init.\n" + ex 也就是第⼆个参数是框出的内容。"BinaryRain 也就是第三个参数是框的标题。JOptionPane.ERROR_MESSAGE 也就是第四个参数,是框的类型,表⽰错误提⽰,出来的框有个红⾊的叉叉标识,如JOptionPane.WARNING_MESSAGE,表⽰提⽰,出来的框有个叹号标识。
参考回答:测试类:public class MyPointTest {public static void main(String[] args) {MyPoint m=new
MyPoint(2,3);System.out.println(m.distance(3, 4));}}MyPoint类public class MyPoint {private int x;private int y;public
MyPoint(){}public MyPoint(int x,int y){this.x=x;this.y=y;}public void setX(int x){this.x=x;}public int getx(){return x;}public void setY(int y){this.y=y;}public int getY(){return y;}public double distance(int x,int y){return Math.sqrt((this.x-x)*(this.x-x)+(this.y-y)*(this.y-y));}}
话题:java编程 定义⼀个类Point,⼀个
点,public属有x和y,⽅法有显
话题:设计⼀个点类Point,其中包含点的坐标x和y两个数据成员,并设计两回答:#includeusing namespace std;class Point;//先声明类型Pointint horizontalDistance(const Point first, const Point second);//⽔平距离函数声明int verticalDistance(const Point first, const Point second);//垂直距离函数声明class Point{private:int x;//横坐标int y;//纵坐标public:Point(int x=0, int y = 0)//构造函数{this-x = x;this-y = y;}friend int horizontalDistance(const Point first, const Point second);friend int verticalDistance(const Point first, const Point second);};//⽔平距离函数定义int horizontalDistance(const Point first, const Point second){if(first.x -second.x =0)return first.x-second.x;
elsereturn second.x-first.x;}//垂直距离函数定义int verticalDistance(const Point first, const Point second){if(first.y -second.y =0)return first.y-second.y;elsereturn second.y-first.y;}//测试int main(){ Point a(1,2);//定义三个Point对象Point b(0,0);Point c(-1,-1);//测试coutcoutcoutcoutreturn 0;}
java怎么编写参考回答:#include lt;math.hgt;class point{public;point(double a,double b){ x=a;y=b};fiend double square(point amp;a,point amp;b);private:double x,y;};double square(point amp;a,point amp;b) { return sqr((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))};void main(){point p1(x1,y1),p2(x2,y2);double l;l=square(p1,p2);}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论