我想计算矩形、圆、正方形的面积,但是得出的结果是个地址?#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/07/04 13:09:08
![我想计算矩形、圆、正方形的面积,但是得出的结果是个地址?#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](/uploads/image/z/14337441-9-1.jpg?t=%E6%88%91%E6%83%B3%E8%AE%A1%E7%AE%97%E7%9F%A9%E5%BD%A2%E3%80%81%E5%9C%86%E3%80%81%E6%AD%A3%E6%96%B9%E5%BD%A2%E7%9A%84%E9%9D%A2%E7%A7%AF%2C%E4%BD%86%E6%98%AF%E5%BE%97%E5%87%BA%E7%9A%84%E7%BB%93%E6%9E%9C%E6%98%AF%E4%B8%AA%E5%9C%B0%E5%9D%80%3F%23includeusing+namespace+std%3Bclass+Shape%7Bpublic%3A%5Cx05Shape%28%29%5Cx05%7Bwidth%3D0.0%3Bheight%3D0.0%3B%7D%5Cx05Shape%28double+w%2Cdouble+h%29%5Cx05%7Bw%3Dwidth%3Bh%3Dheight%3B%7D%5Cx05virtual+Shape%28%29%7B%7D%5Cx05virtual+d)
我想计算矩形、圆、正方形的面积,但是得出的结果是个地址?#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
是对的.
什么乱七八糟的