c++-这代码错在哪,我真的找不出来

问题描述

这代码错在哪,我真的找不出来

#include
using namespace std;
class Rectangle
{
private:
int width,length;
public:
Rectangle(int a,int b)
{
width=a;
length=b;
}
void set_rectangle(int w,int l)
{width=w;length=l;}
int area();
int perimeter();
}
int Rectangle::area()
{
return(width*length);
}
int Rectangle::perimeter()
{
return(2*(width+length));
}
int main()
{
Rectangle r(12,4);
cout<<"this rectangle's area is "<<r.area()<<",perimeter is "<<r.perimeter();
r.set_rectangle(2,4);
cout<<"the new rectangle's area is "<<r.area()<<",perimeter is "<<r.perimeter();
return 0;
}

解决方案

 #include <iostream>
using namespace std;
class Rectangle
{
private:
    int width,length;
public:
    Rectangle(int a,int b)
    {
        width=a;
        length=b;
    }
    void set_rectangle(int w,int l)
    {width=w;length=l;}
    int area();
    int perimeter();
};
int Rectangle::area()
{
    return(width*length);
}
int Rectangle::perimeter()
{
    return(2*(width+length));
}
int main()
{
    Rectangle r(12,4);
    cout<<"this rectangle's area is "<<r.area()<<",perimeter is "<<r.perimeter();
    r.set_rectangle(2,4);
    cout<<"the new rectangle's area is "<<r.area()<<",perimeter is "<<r.perimeter();
    return 0;
}

解决方案二:

  1. #include 这个后面没有头文件
  2. 类定义没有结束符 ;

解决方案三:

类定义结束时应该加上分号

解决方案四:

http://codepad.org/uywc4qKZ
this rectangle's area is 48,perimeter is 32the new rectangle's area is 8,perimeter is 12

解决方案五:

class 类名
{
public:
//公共的行为或属性

    private:
        //公共的行为或属性
};

    你的类定义缺少最后的“;”

解决方案六:

就照大家的意见办吧。写代码时的小遗漏。

解决方案七:

要注意细节,头文件,“;”遗漏

解决方案八:

缺少分好,,,,小问题啊

时间: 2024-08-06 06:54:07

c++-这代码错在哪,我真的找不出来的相关文章

数据-matlab 代码错在哪 求解决

问题描述 matlab 代码错在哪 求解决 想要用12个数据去预测1个数据 P=[2.97 3.02 3.29 3.35 5.6 5.41 4.82 3.61 2.92 2.03 1.95 1.94 3.01 3.18 3.45 3.51 5.82 5.58 4.95 3.95 3.01 2.21 2.13 2.13 3.2 3.31 3.56 3.72 6.01 5.73 5.2 4.11 3.21 2.33 2.3 2.3 3.4 3.42 3.8 3.88 6.21 5.88 5.41 4

xmlentities-在xml文档中插入图片总是失败,请大家帮我看看这段代码错在哪里了?

问题描述 在xml文档中插入图片总是失败,请大家帮我看看这段代码错在哪里了? <?xml version="1.0" encoding="GB2312"?> <!DOCTYPE photos[ <!ELEMENT photos (photo*)> <!ELEMENT photo EMPTY> <!ATTLIST photo Sources ENTITIES #REQUIRED> <!ENTITY ic1 S

mysql-求帮我看看代码错在哪里?

问题描述 求帮我看看代码错在哪里? 准备用mysql做一个表,建表语句如下: create table tv_play( name varchar(40) not null, country of origin varchar(40) not null, production company varchar(40) not null, genre varchar(40) not null); 结果显示语法错误,求指明错误所在. 解决方案 country of origin 可以空格吗 解决方案二

springmvc-新手求教、帮我看看这个登录代码错在哪里了、输入的用户名对但就是跳不过去,老是返回到登录页面

问题描述 新手求教.帮我看看这个登录代码错在哪里了.输入的用户名对但就是跳不过去,老是返回到登录页面 public class LoginController extends BaseController { @Resource private LoginService loginService; @RequestMapping("login.do") public String login(HttpServletRequest request, HttpServletResponse

c++-请问我写的C++基于循环数组的队列 代码错在哪里,老是答案错

问题描述 请问我写的C++基于循环数组的队列 代码错在哪里,老是答案错 正常出队列返回success,空队列返回underflow, 满队列返回overflow enum ErrorCode { success, underflow, overflow }; const int maxQueue = 100; template <class QueueEntry> class MyQueue { public: MyQueue(){ front = rear = 0; } // 判断队列是否为

html5-这段代码错在哪,为什么不管点那个选项,评论都会消失

问题描述 这段代码错在哪,为什么不管点那个选项,评论都会消失 <script type=""text/javascript""> function Rdo_Click(v){ var blnShow; if(v==1){ blnShow=false; } else{ blnShow=true; } var strArt=document.getElementById(""art""); strArt.setAttr

这段python代码错在哪里了

问题描述 这段python代码错在哪里了 from datetime import dateimport reclass iRates: def init(selfdayrates): self._day=day self._rates=rates class ratesTable: def init(self): self._icon=[] self._tcon=[] def iadd(selfirates): self._icon.append(irates) def tadd(selftr

编程-这万年历的代码错哪了?

问题描述 这万年历的代码错哪了? #include<iostream> using namespace std; #include<iomanip> int daysofmonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int Isleap_year(int year) { if((year%4==0&&year%100!=0)||year%400==0) return 1; else return 0; } in

c++问题-一道简单的c++题目,求解此段代码错哪了

问题描述 一道简单的c++题目,求解此段代码错哪了 题目是第四题,求解此段代码错哪了 解决方案 你的sum每次枚举完n后,要清0 解决方案二: i在每次循环结束都要置0或1 否则从第二轮循环开始i都是从上次结束的地方开始的 所以没有输出