下面是我编的一个求两点间距离,采用的是组合类的方式实现,由于刚接触C++,能力有限,望高人指点迷津。(最好还是用组合类帮我修改一下)-----能够得到你的指点是我的荣幸
//sdgsdg.cpp
# include <iostream.h>
# include <cmath>
//lei
class point
{
public:
point(int x1,int y1);
point(point &p);
int getx() {return x;}
int gety() {return y;}
private:
int x,y;
};
point::point(int x1,int y1)
{x=x1;y=y1;}
point::point(point &p)
{x=p.x;y=p.y;}
//zuhelei
class line
{
public:
line (point pc1,point pc2);
line (line &q);
double getend() {return end;}
private:
point p1,p2;
double end;
};
line::line (point pc1,point pc2)
{
P1=PC1;
P2=PC2;
int zz=p1.getx()-p2.getx();
int yy=p1.gety()-p2.gety();
end=sqrt(zz*zz+yy*yy);
}
line ::line(line &q)
{
p1=q.p1;
p2=q.p2;
end=q.end;
cout<<q.getend()<<endl;
}
//zhuhaishu
void main()
{
point a(1,2);
point b(4,6);
line c(a,b);
line h (c);
}