继承与派生的程序编译没错误,运行出错,求解
#include<iostream>using namespace std;
const double PI=3.14159;
class Point
{
protected:
double x,y;
public:
Point(double xv,double yv){ x=xv; y=yv;}
double Area(){ return 0;}
void show()
{
cout<<"x="<<x<<' '<<"y="<<y<<endl;
}
};
class Circle:public Point
{
double radius;
public:
Circle(double xv,double yv,double vv):Point(xv,yv)
{
radius=vv;
}
Circle(Circle &Cir):Point(Cir)
{
radius=Cir.radius;
}
double Getradius(){ return radius;}
double Area(){ return PI*radius*radius;}
void show()
{
cout<<"x="<<x<<' '<<"y="<<y<<' '<<"radius="<<radius<<endl;
}
};
class Cylinder:public Circle
{
private:
double h;
public:
Cylinder(double xv,double yv,double vv,double xx):Circle(xv,yv,vv)
{
h=xx;
}
double Area() { return (2*Area()+2*PI*Getradius()*h); }
Cylinder(Cylinder &p):Circle(p) { h=p.h; }
void show()
{
cout<<"x="<<x<<' '<<"y="<<y<<' '<<"radius="<<Getradius()<<' '<<"h="<<h<<endl;
}
};
void main()
{
Point p(1,2);
cout<<"点的面积="<<p.Area()<<endl;
p.show();
Circle c1(1,2,3),c2(c1);
cout<<"圆的面积="<<c2.Area()<<endl;
c2.show();
Cylinder c3(1,2,3,2),c4(c3);
cout<<"圆柱的面积="<<c4.Area()<<endl;
c4.show();
}
运行截图:
[ 本帖最后由 子楠 于 2013-4-9 17:28 编辑 ]