1、类中要有公有成员、私有成员。数据成员要有子对象、静态数据成员。成员函数要有至少二个普通成员函数,一个静态成员函数,一个友元函数,一个常成员函数。
2、构造函数要重载无参、有参、复制构造函数,析构函数。
3、要实现单继承或多继承。
4、在程序中要对子对象、静态数据成员初始化,要调用普通成员函数、静态成员函数、友元函数、常成员函数。
怎么不是类得继承呀 不过你的答案很好了 要是没有更好的我就把分给你 非常感谢
追答这是时间问题啦,我是现场写的,非要继承吧POSITION改成类,再稍微改下就可以了,我这是为了显示更高级的东西嘛,你要得话我给你改改吧.
今晚没时间了,如果需要,明晚看又没有时间.
恩 非常感谢 我等你的回答
追答//完全按你要求的版本
#include
using namespace std;
class Position{
int x;
int y;
public:
Position(int x=0,int y=0):x(x),y(y){}
void setxy(int a,int b){x=a;y=b;}
const int getx()const{return x;}
const int gety()const{return y;}
};
class Point:public Position{
Position p;
static int total;
public:
Point(){++total;}
Point(int tx,int ty,int px,int py):Position(tx,ty),p(px,py){++total;}
Point(const Point& pt){
setxy(pt.getx(),pt.gety());
p.setxy(pt.p.getx(),pt.p.gety());
++total;
}
~Point(){--total;}
static void showtotal(){cout<<"total:"<<total<<endl;}
void showxy(){
cout<<"x="<<getx()<<'\t'
<<"y="<<gety()<<endl;
}
void showxy()const{
cout<<"x="<<getx()<<'\t'
<<"y="<<gety()<<endl;
}
void showpoint(){
cout<<"p.x="<<p.getx()<<'\t'
<<"p.y="<<p.gety()<<endl;
}
void showpoint()const{
cout<<"p.x="<<p.getx()<<'\t'
<<"p.y="<<p.gety()<<endl;
}
void setxy(int a,int b){Position::setxy(a,b);}
void setp(int a,int b){p.setxy(a,b);}
void setp(Position po){p.setxy(po.getx(),po.gety());}
friend ostream& operator<<(ostream& os,const Point& pt){
os<<"x="<<pt.getx()<<'\t'
<<"y="<<pt.gety()<<endl;
os<<"p.x="<<pt.p.getx()<<'\t'
<<"p.y="<<pt.p.gety()<<endl;
return os;
}
};
int Point::total=0;
int main()
{
Point p1,p2(2,4,3,8);
const Point cp(4,6,6,10);
cout<<"p1:"<<endl<<p1
<<"p2:"<<endl<<p2<<endl;
p1.showpoint();
p2.showpoint();
cout<<"cp:"<<endl;
cp.showxy();
cp.showpoint();
Position posi(15,13);
p1.setp(posi);
cout<<"p1:"<<endl<<p1<<endl;
Point::showtotal();
Point* pptr=new Point;
Point* pptr1=new Point(1,2,3,4);
Point::showtotal();
delete pptr;
delete pptr1;
Point::showtotal();
return 0;
}
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;...
c++程序定义一个点类Point
double gety() { return y;} double Distance(Point &p) { return sqrt( pow((p.getx()-x), 2) + pow((p.gety()-y),2));} };
定义一个Point类,其属性包括点的坐标,提供计算两点之间的距离_百度知 ...
c++#include include include using namespace std;class Point {double x,y;friend class Rectangle;public:Point(){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...
简单c++题。定义一个类Point,并定义成员函数doubleDistance(const& Po...
void main(){ Point p1(2,-3.5),p2(-2.1,3);cout<<"距离为:"<<p1.Distance(p2)<<endl;}
C++\/\/\/定义一个点类(Point) 。
include <stdio.h>#include <stdlib.h>class Point{private: int _x; int _y;public: Point(int x,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 ...
c++编写平面点类Point,含数据成员x,y。完成以下要求:
;\/\/有参数构造函数void show();};Point::Point() :x(0), y(0) { cout << "默认构造" << endl; }Point::Point(double x_, double y_) : x(x_), y(y_) { cout << "有参数构造" << endl; }void Point::show() { cout << '(' << x << ',' << y << ')';...
c++建立一个Point(点)类,包含数据成员x,y(坐标点)。
area() {return a*a;}double circumference() {return 4 * a;}};class Cylinder :public Circle, public Square {public:double surface() {return 2 * Circle::area() + Square::area();}};不知道为什么要用线段类来派生Circle和Square,我觉得用Point更好吧?随便写写,不要在意细节 ...
求编程大佬,c++定义点Point类,内含实数类型成员x,y,编程实现对两个点...
class Point { private:double x;double y;public:Point(double dx = 0.0, double dy = 0.0):x(dx),y(dy) {} friend double Distance(Point const &a, Point const &b);friend double Distance(Point const &a); \/\/ 到原点的距离 friend double Area(const Point &a,const Point &b...
用C++定义一个点类Point,由此派生出一个圆类
class Circle:public Point { public:Circle(int a,int b,int c):Point(a,b){change(c);} void change(int a){r = a;} double area(){return pi * r * r;} void disp(){ cout << "圆心坐标: ";Point::disp();cout << "\\n圆半径为: " << r << "\\n圆面积为: " <<...
C++:编写一个点类Point,再由它派生线段类Line。
Point(Point& a);float Distance(Point b);};Point::Point(Point& a){ x=a.x;y=a.y;} float Point::Distance(Point b){ return sqrt((x-b.x)*(x-b.x)+(y-b.y)*(y-b.y));} class Line:public Point { private:Point a,b;public:Line(float x1,float y1,float x2,float...