#include <iostream.h>
class point
{private:
double x,y;
public:double getx(){return x;}
double gety(){return y;}
void setx(double a){x=a;}
void sety(double b){y=b;}
point(double x=0,double y=0){}
};
class circle
{private:
point o;double r;
public:
//void seto(point oo){0.setx(oo.getx()),o.sety(oo.sety);}
void setr(double rr){r=rr;}
point geto(){return o;}
double getr(){return r;}
// void moveto(point oo){0.setx(oo.getx()),o.sety(oo.sety);}
void display(){cout<<"圆心为"<<o.getx()<<","<<o.gety()<<"半径为"<<o.getr()<<endl;}
circle(double rr=0,double a=0,double b=0):o(a,b){r=rr;}
};
系统显示标有//的两行程序有问题但我找不到啊
还有circle类的构造函数为什么要这么写我也不太清楚,望高手解释一下哈
#include <iostream.h>
class point
{
private:
double x,y;
public:
double getx(){return x;}
double gety(){return y;}
void setx(double a){x=a;}
void sety(double b){y=b;}
point(double x=0,double y=0){}
};
class circle
{
private:
point o;double r;
public:
void seto(point oo){o.setx(oo.getx()),o.sety(oo.gety());}
void setr(double rr){r=rr;}
point geto(){return o;}
double getr(){return r;}
void moveto(point oo){o.setx(oo.getx()),o.sety(oo.gety());}
void display(){cout<<"圆心为"<<o.getx()<<","<<o.gety()<<"半径为"<<getr()<<endl;}
circle(double rr=0,double a=0,double b=0){o.setx(a);o.sety(b);r=rr;}
};
修改的地方用粗体字表示出。
circle类的构造函数写成circle(double rr=0,double a=0,double b=0):o(a,b){r=rr;}
其中的o(a,b)是类point的构造函数point(double x=0,double y=0){}所致,相当于调用了这个函数,将它写在里面也是一样的。不过得写成o(a,b);
void seto(point oo){0.setx(oo.getx()),o.sety(oo.sety);}
void moveto(point oo){0.setx(oo.getx()),o.sety(oo.sety);}
里面的【,】改成【;】即可
void seto(point oo){0.setx(oo.getx());o.sety(oo.sety);}
void moveto(point oo){0.setx(oo.getx());o.sety(oo.sety);}
circle类的构造函数的写法你仔细看看教科书,这只是其中一种形式,就是先对变量o进行赋初值,再对其他变量赋值。。。。
还是7年前在学校的时候学了点c++,只能给你解释这么多了,不然就需要找书出来才能给个比较完善的答案了。