请高人指点这个C++程序怎么改?我是新手,先谢了!

来源:百度知道 编辑:UC知道 时间:2024/05/13 10:37:40
题目:
定义一个shape抽象类,在此基础上派生出rectangle和circle类,二者都有getarea()函数计算对象的面积,getperim()函数计算对象的周长.使用rectangle派生一个新类square.
#include<iostream.h>
#include<string.h>

class shape //shape类的声明
{
public:
virtual double getarea(float x,float y)=0; //虚函数,用于求图形面积
virtual double getperim(float x,float y)=0; //虚函数,用于求图形周长
void display();
protected:
float x,y;
double area,perim;
};
void shape::display() //shape类成员的实现
{
cout<<"area:"<<area<<endl;
cout<<"perim:"<<perim<<endl;
}

class rectangle:public shape //rectangle类,由公有继承shape类而来
{
public:
double getarea(float x,float y)
{
area=x*y;
return area;
}
double getperim(float x,float y)
{
perim=2*(x+y);
return perim;
}
};

class circle:public shape //circle类由公有继承shape而来
{

少了一个括号,看下面代码最后以行

class circle:public shape //circle类由公有继承shape而来
{
public:
double getarea(float x,float y)
{
area=3.14*x*x;
rerurn area;
}
double getperim(float x,float y)
{
perim=2*3.14*x;
return perim;
} 《--- 这里加一个括号
};