我想计算矩形、圆、正方形的面积,但是得出的结果是个地址?#includeusing namespace std;class Shape{public:\x05Shape()\x05{width=0.0;height=0.0;}\x05Shape(double w,double h)\x05{w=width;h=height;}\x05virtual Shape(){}\x05virtual d
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 20:10:30
我想计算矩形、圆、正方形的面积,但是得出的结果是个地址?#includeusing namespace std;class Shape{public:\x05Shape()\x05{width=0.0;height=0.0;}\x05Shape(double w,double h)\x05{w=width;h=height;}\x05virtual Shape(){}\x05virtual d
我想计算矩形、圆、正方形的面积,但是得出的结果是个地址?
#include
using namespace std;
class Shape{
public:
\x05Shape()
\x05{width=0.0;height=0.0;}
\x05Shape(double w,double h)
\x05{w=width;h=height;}
\x05virtual Shape(){}
\x05virtual double Getarea()=0;
\x05virtual void display()=0;
protected:
\x05double width,height;
};
class Rectangle:public Shape{
public:
\x05Rectangle()
\x05{}
\x05Rectangle(double w,double h):Shape(w,h)
\x05{}
\x05~Rectangle(){}
\x05double Getarea()
\x05{return (width*height);}
\x05void display()
\x05{
\x05\x05cout
我想计算矩形、圆、正方形的面积,但是得出的结果是个地址?#includeusing namespace std;class Shape{public:\x05Shape()\x05{width=0.0;height=0.0;}\x05Shape(double w,double h)\x05{w=width;h=height;}\x05virtual Shape(){}\x05virtual d
程序绝大多数地方都是对的.
只有这里写错了:
你写的是
Shape(double w,double h)
{w=width;h=height;}
而应该是
Shape(double w,double h)
{width=w;height=h;}
改过之后我试了一下,程序的输出是这样的:
shape is a rectangle.
Area is:14.88
Shape is circle.
Area is:52.7834
Shape is square.
Area is:660.49
是对的.
什么乱七八糟的