设计Point、Line、Circle类分别代表坐标系中的点、线段、圆。其中Point有两个double成员表示坐标值;Line有两个Point成员对象表示两个端点;Circle有一个Point成员对象表示中点,有一个double对象表示半径。
三个类都有void draw()函数来画出自己(实际就是打印自己的信息)。
main函数中为这三个类至少声明一个对象,并调用draw函数输出这个对象的信息。
【输入形式】
输入一行5个double浮点数,
分别是:第一个点x坐标,第一个点y坐标,第二个点x坐标,第二个点y坐标,圆的半径r
【输出形式】
输出第一个点的信息,
输出以第一和第二个点组成的线段信息,
输出以第二个点为圆心,以r为半径的圆信息
【样例输入】
1 1 2 2 5
【样例输出】
Point:x=1,y=1
Line:(Point:x=1,y=1;Point:x=2,y=2)
Circle:(radius:5;orgin:Point:x=2,y=2)
以下是我编的程序,但在类的设计上出错了,不知道怎么改。
#include
using namespace std;
class Point
{private:
double a1,b1;
public:
Point(double a,double b)
{a1=a;b1=b;
}
void draw()
{cout<<"Point:x="<<a1<<",y="<<b1;
}};
class Line
{private:
Point *f1,*f2;
public:
Line(Point p1,Point p2)
{f1=&p1;f2=&p2;
}
void draw()
{cout<<"Line:("<draw()<<","<draw()<<")"<<endl;}
};
class Circle
{private:
double m;Point *f;
public:
Circle(Point p2,double r):
{f=&p2;
m=r;}
void draw()
{
cout<<"Circle:(radius:"<<m<<";orgin:"<draw()<<")";}};
int main()
{
double x1,y1,x2,y2,r;
cin>>x1>>y1>>x2>>y2>>r;
Point p1(x1,y1);
Point p2(x2,y2);
Line L(p1,p2);
Circle c(p2,r);
p1.draw();
cout<<endl;
L.draw();
c.draw();
return 0;
}
具体哪一行能直接指出来吗?
class Point
{
...
Point(const Point& p) {a1 = p.geta();b1 = p.getb();}
double geta(return a1;}
double getb(return b1;}
...
}
class Circle
{
private:
double m;Point *f;
public:
Circle(Point p2,double r):
{ f= new Point(p2);
m=r;}
class Line
{private:
Point *f1,*f2;
public:
Line(Point p1,Point p2)
{f1 = new Point(p1);
f2 = new Point(p2);
}
?