函数继承
#include<iostream>using namespace std;
class Dot
{
private:
float x,y;
public:
Dot(float a,float b):x(a),y(b){};
float getsx()
{
return (x);
}
float getsy()
{
return (y);
}
void Show(){cout<<"x="<<getsx()<<" "<<"y="<<getsy()<<endl;}
};
class Line:public Dot
{
Dot d1,d2;
public:
float x,y;
Line(Dot dot1,Dot dot2):d1(dot1),d2(dot2)
{
x=(d1.getsx()+d2.getsx())/2;
y=(d1.getsy()+d2.getsy())/2;
}
void Showl()
{
cout<<"Dot1:";
d1.Show();
cout<<"Dot2:";
d2.Show();
cout<<"Center:"<<"x="<<x<<" "<<"y="<<y<<endl;
}
};
int main()
{ float a,b;
cout<<"Input Dot1:"<<endl;
cin>>a>>b;
Dot dot1(a,b);
cout<<"Input Dot2:"<<endl;
cin>>a>>b;
Dot dot2(a,b);
Line line(dot1,dot2);
line.Showl();
return 0;
}