急求 十五分钟内帮我弄正确的必给采纳 调试没有错误,但执行不出结果

/* VC++程序设计

设计三个类:几何形状类(Shape)、圆类(Circle)、矩形类(Rectangle),要求:

1)Shape类设计成抽象类,具有用来计算面面积的纯虚函数getArea;
2)Circle和Rectangle两类都从Shape类公有派生,Circle类的保护成员为半径(Radius),
Rectangle的保护成员为长(length)和宽(width);
3)实现Circle类和Rectangle类的拷贝构造函数、带参构造函数、析构函数;
4)给出具体的Circle和Rectangle的计算面积函数getArea;
5)在函数中,通过Shape抽象类指针方式,输出半径为5的圆对象,以及
长度为3,宽度为4的矩形对象的面积。

*/

#include<iostream.h>
// 几何形状类
class Shape
{
public:
//计算面积
double getArea()
{
return 0.0;
}

};

// 圆类
class Circle : public Shape
{
protected:
double radius; //半径

public:
// 带参构造函数
Circle(double radius);

// 拷贝构造函数
Circle(const Circle& oC)
{
radius = oC.radius;
}

// 析构函数
~Circle()
{

}

// 计算面积
double getArea()
{
return 3.1415926*radius*radius;
}

};

// 矩形类
class Rectangle : public Shape
{
protected:
double length, width;//长度,宽度

public:
// 带参构造函数
Rectangle(double length,double width);

// 拷贝构造函数
Rectangle(const Rectangle& oR)
{
length = oR.length;
width = oR.width;

}

// 析构函数
~Rectangle()
{

}

// 计算面积
double getArea()
{
return length*width;
}

};

void main()
{
Circle oC(5); //定义了一个半径为5的圆对象

cout<<"输出面积为:"<<oC.getArea()<<endl;

Rectangle oR(3,4); //定义了一个长度为3,宽度为4的矩形

cout<<"输出面积为:"<<oR.getArea()<<endl;

}

Circle(double radius);

修改为

Circle(double radius)

{
this.radius = radius;

}

Rectangle(double length,double width);
修改为
Rectangle(double length,double width)

{
this.length = length;

this.width = width;
}
温馨提示:答案为网友推荐,仅供参考
相似回答