关于派生的问题 求指教
#include <iostream>#include <math.h>
using namespace std;
class point
{
protected:
double x1;
double y1;
double x2;
double y2;
//int color; //颜色属性
//int width; //线宽属性
public:
point(double,double,double,double);
void display(); //显示坐标
double distance(point &a); //计算两点间距离
double getx(){return x1;}
double gety(){return y1;} //返回x,y的值
};
double point::distance(point &a)
{
double v;
v=sqrt((x1- x2)* (x1- x2)+( y1- y2)* ( y1- y2));
cout<<"两点距离:"<<v<<endl;
return 0;
}
void point::display()
{
cout<<x1<<","<<y1<<endl<<x2<<","<<y2<<endl;
}
point::point(double xn1,double yn1,double xn2,double yn2)
{
cout<<"调point构造函数"<<endl;
x1=xn1;
y1=yn1;
x2=xn2;
y2=yn2;
}
class line:public point //由点类派生的线段类
{
protected:
double x;
double y;
public:
line(double,double, double,double);
void display(); //显示线的信息
double distance(); //计算两点间距离
};
line::line(double q,double w, double e,double r):point(double xn1,double yn1,double xn2,double yn2){};
{
cout<<"调line构造函数"<<endl;
}
void main()
{
point a(7.8,9.8,34.5,67.8);
a.distance(a);
point b(7.8,9.8,34.5,67.8);
line c();
//a.display();
}
唉。。。我不会写了
最后要实现这个: