哪里有错误啊?#includeusing 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 r1r1.r
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/05 13:39:00
![哪里有错误啊?#includeusing 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 r1r1.r](/uploads/image/z/11764310-14-0.jpg?t=%E5%93%AA%E9%87%8C%E6%9C%89%E9%94%99%E8%AF%AF%E5%95%8A%3F%23includeusing+namespace+std%3Bclass+Rectangle%7Bpublic%3A%7Bint+width%2Cheight%3B%7Dprivate%3A%7B+void+r2%28int+w%2Cint+h%29int+area%28%29%7D%3Bvoid+Rectangle%3A%3Ar2%28int+w%2Cint+h%29%7Bwidth%3Dw%3Bheight%3Dh%3B%7DRectangle%3A%3Aarea%28%29+%7Breturn+width+%2A+height%3B%7Dint+main%28%29%7BRectangle+r1r1.r)
哪里有错误啊?#includeusing 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 r1r1.r
哪里有错误啊?
#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
哪里有错误啊?#includeusing 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 r1r1.r
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