作业帮 > 综合 > 作业

哪里有错误啊?#includeusing namespace std;class Rectangle{public:{i

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/17 21:09:58
哪里有错误啊?
#include
using namespace std;
class Rectangle
{
public:
{int width,height;}
private:
{ void r2(int w,int h)
int area()
};
void Rectangle::r2(int w,int h)
{width=w;height=h;}
Rectangle::area() {return width * height;}
int main()
{
Rectangle r1
r1.r2(3,5) ;
cout
1、我实在搞不懂,你都已经会写类了,居然还会忘了写分号
很多地方,我就不一一列举了
2、属性设为私有,方法设有公有.你却恰好相反,另外公有私有不要用大括号括起来,放在后面系统就会分辨.
3、 Rectangle::area() {return width * height;}前面少了函数类型int
编程要细心.
最后完整的代码如下:
#include
using namespace std;
class Rectangle
{
private:
int width, height;
public:
void r2(int w, int h);
int area();
};
void Rectangle::r2(int w, int h)
{
width=w;
height=h;
}
int Rectangle::area()
{
return width * height;
}
int main()
{
Rectangle r1;
r1.r2(3,5) ;
cout