定义一个表示点的类Point,类中有两个私有成员变量x和y;使用成员函数

作者&投稿:陈寇 (若有异议请与网页底部的电邮联系)
定义一个表示点的类point,类中有两个私有成员变量x和y,使用成员函数和友元函数两种方法,为该类~

#include
using namespace std;

template
class Point
{
public:
Point(numtype a,numtype b=0);
void print();
private:
numtype x,y;
};

template
Point::Point(numtype a,numtype b)
{
x=a;
y=b;
}

template
void Point::print()
{
cout<<x<<" "<<y<<endl;
}

int main()
{
Point p(2);
p.print();
return 0;

}

现存的CPoint ;类就可以

#include<iostream> using namespace std; class Point;//先声明类型Point int 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; else return second.x-first.x; } //垂直距离函数定义 int verticalDistance(const Point& first, const Point& second) { if(first.y -second.y >=0) return first.y-second.y; else return second.y-first.y; } //测试 int main() { Point a(1,2);//定义三个Point对象 Point b(0,0); Point c(-1,-1); //测试 cout<< horizontalDistance(a,b) <<endl; cout<< horizontalDistance(a,c) <<endl; cout<< verticalDistance(a,b) <<endl; cout<< verticalDistance(a,c) <<endl; return 0; }


Java定义一个Point(点)类
public class Point { public static void main(String[] args){ Point p1=new Point();Point p2=new Point(1,2);p1.show();p1.move(3,4);p1.show();p2.show();p2.move(5,6);p2.show();} Point(){ this(0,0);} Point(float x,float y){ this.x=x;this.y=y;} void...

定义一个“点”(Point)类,用来表示三维空间上的点,有三个坐标。
Point p = new Point();p.setXYZ(1,1,1);int dist = p.getPODTO();System.out.println(dist);} }

C++\/\/\/定义一个点类(Point) 。
int y) { this->_x=x; this->_y=y; } int getX() { return this->_x; } int getY() { return this->_y; }};class Rectangle:public Point{private: int _width; int _height;

定义一个点类Point 包括x坐标和y坐标(int)。定义一个圆类Circle,
首先,类一般是有默认的无参构造函数的,但是因为定义了Circle的有参构造函数,Circle(Point pp,int rr),所以系统不会在生成默认的无参构造函数 然后因为在main函数中有: Circle c1(p1,7),c2;其中的c2并没有给它参数,系统会认为它使用的是无参构造函数 所以这就原因了。如果不加上Circle(){}...

定义一个点类Point,有横坐标x和纵坐标y,定义构造函数初始化点,定义displ...
classPoint{public:Point(inta,intb):x(a),y(b){cout~Point(){coutvoidshow(){coutdoubledistance (Pointp){returnsqrt((p.y-y)*(p.x-y)+(p.x-x)*(p.x-x));}private:intx;inty;};intmain(){Pointa(0,0);Pointb(1,1);cout...

定义一个点类(Point),其数据成员包含横坐标和纵坐标;再定义一个距离类...
public class Point { double x,y;double d;Point(double a,double b){ x = a;y = b;} void TestPoint(Point p1,Point p2){ x = (p1.x + p2.x)\/2;y = (p1.y + p2.y)\/2;System.out.println("(" + x + ","+ y + ")");} void Distance(Point p1,Point p2){ ...

c++程序定义一个点类Point
<< "(x,y)=(" << x << "," << y << ")" << endl;void move(double x1, double y1) {x=x1;y=y1} double getx() {return x;} double gety() { return y;} double Distance(Point &p) { return sqrt( pow((p.getx()-x), 2) + pow((p.gety()-y),2));} };

定义一个点类Point
public class Point{ private int x,y; public Point(){ this.x=0; this.y=0; } public Point(int x, int y){ this.x=x; this.y=y; } public void moveTo(int x, int y){ this.x=x; this.y=y; } @Override public String toSt...

java编程 定义一个类Point,代表一个点,public属性有x和y,方法有显示点...
public class Test{ public static void main(String[] args){ MyPoint p1 = new MyPoint(); MyPoint p2 = new MyPoint(6.0,8.0); MyPoint p = MyPoint.getMiddle(p1,p2); System.out.print("点1:"); p1.show(); System.out.print("点2:"); p2.sh...

定义一个Point类,其属性包括点的坐标,提供计算两点之间的距离
using namespace std;class Point {double x,y;<br>friend class Rectangle;<br>public:<br>Point()<br>{x=y=0;} Point(double a,double b){x=a;y=b;} double distance(Point& p1,Point& p2){return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));<...

邵武市13556738033: c++程序定义一个点类Point -
牢时四物: class Point { private: double x; double y; public: Point(); Point(double x1, double y1) {x=x1;y=y1} void set(double x1, double y1) {x=x1;y=y1} void Display() {cout << "(x,y)=(" << x << "," << y << ")" << endl; void move(double x1, double y1) {x=x1;...

邵武市13556738033: JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point类中要定义它的三个构造函数定义一个Point类 它的对象是指一个平面上的点(x,... -
牢时四物:[答案] 我帮你

邵武市13556738033: 定义一个点Point类用来表示三维空间中的点(有三个坐标) -
牢时四物:[答案] return x = (x-p.x)(x-p.x)+(y-p.y)(y-p.y)+(z-p.z)(z-p.z); 各括号之间差乘号*

邵武市13556738033: 定义一个point类,其对象表示平面坐标上的一个点(x,y),并通过该类成员方式对该类重载二目运算符“+”和 -
牢时四物:[答案] 这么基础,网上一搜一大片,自己试着写写吧,写错了你就赚了,为什么那样写是错误的 初学者往往怕出错,可是以我过来人的经验告诉你吧,我是从错误中走过来的.

邵武市13556738033: 首先定义一个点类 POINT ,有两个 double 型的 保护 数据成员 x ,y 表示该类对象在二维坐标系中的坐标位首先定义一个点类 POINT ,有两个 double 型的 保护... -
牢时四物:[答案] 修改如下,调试无误:#include "iostream"#include "cmath"using namespace std;//实现POINT类class POINT{protected://private: double x; ...

邵武市13556738033: 定义二维坐标系中的点类(Point) -
牢时四物: public class point{ private float x; private float y; public point(){ this.x=0.0; this.y=0.0; } public void point(float x,float y){ this.x=x; this.y=y; } public void printPoint(){ System.out.println(this.x+","+this.y); } public float getDistance(Point anotherPoint){ ...

邵武市13556738033: 定义一个表示点的类point,类中有两个私有成员变量x和y,使用成员函数和友元函数两种方法,为该类 -
牢时四物: #include using namespace std;template class Point{ public: Point(numtyp...

邵武市13556738033: 用C++写一个简单的点(Point)类 -
牢时四物: d main() };中的函数名main不对,应该是display(),即:#include<iostream> using namespace std; struct point{ void setxy(double a,double b) //你这里有打错字了是void不是viod void display( ) double x,y; }; void main(){ point a; a.setxy(10.6,18....

邵武市13556738033: 定义一个Point(点)类,其中包含数据有x和y用于表示该点坐标值,包含有一个无参构造函数和一个有参构造 -
牢时四物: #includeclass Point{ private: int x; int y; public: Point(); Point(int x1,int y1){ x = x1; y = y1; } Point operator ++(); //前置 Point operator ++(int); //后置 void show(void); }; Point Point::operator ++(){ ++x; ++y; return *this; } Point Point::operator ++(int)...

邵武市13556738033: 定义一个点类Point,它的私有数据成员为横坐标x和纵坐标y,用类的构造函数给横坐标x和 -
牢时四物: #include <cmath>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:...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网