| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 513 人关注过本帖
标题:请各位看看,谢谢
只看楼主 加入收藏
longyou2011
Rank: 2
等 级:论坛游民
帖 子:46
专家分:19
注 册:2011-1-12
结帖率:88.24%
收藏
已结贴  问题点数:20 回复次数:4 
请各位看看,谢谢
#include<iostream>
using namespace std ;
class Box
{
public :
    Box ()
    {
        length = 1 ; width = 1 ; height = 1 ;

    }
    Box ( float L , float w , float h )
    {
        length = L ; width = w ; height = h ;
    }
    float Surface { return ( length * width + length * height + width * height ) / 2 ; }
    float Volume { return ( length * width * height ) ; }
private :
    float length , width , height ;

} ;
int main ()
{
    Box box1 ( 1 , 2 , 2 ) ;
    Box box2 ( 1 , 2 , 2 ) ;
    cout << " Sourface of box1 is " << box1.Sourface << endl ;
    cout << " Volume of box2 is " << box2.Volume << endl ;
    return 0 ;
}错在了那里
搜索更多相关主题的帖子: private include public return 
2011-01-30 18:27
zqmillet
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:41
专家分:108
注 册:2008-7-20
收藏
得分:20 
错一:成员函数没形参也要打括号
float Surface { return ( length * width + length * height + width * height ) / 2 ; }
float Volume { return ( length * width * height ) ; }

改成
float Surface () { return ( length * width + length * height + width * height ) / 2 ; }
float Volume () { return ( length * width * height ) ; }


错二:调用成员函数的时候没形参也要打括号
cout << " Sourface of box1 is " << box1.Sourface << endl ;
cout << " Volume of box2 is " << box2.Volume << endl ;

改成
cout << " Sourface of box1 is " << box1.Sourface() << endl ;
cout << " Volume of box2 is " << box2.Volume() << endl ;


错三:单词和上次一样又拼错了
cout << " Sourface of box1 is " << box1.Sourface() << endl ;

改成
cout << " Sourface of box1 is " << box1.Surface() << endl ;


错四:表面积不是(ab+bc+ac)/2而是(ab+bc+ac)*2
逻辑错误是编译器没办法提示的,也是最难发现的,希望LZ认真
float Surface() { return ( length * width + length * height + width * height ) / 2 ; }

改成
float Surface() { return ( length * width + length * height + width * height ) * 2 ; }


除此之外没有问题,编译通过
图片附件: 游客没有浏览图片的权限,请 登录注册
2011-01-30 20:02
zqmillet
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:41
专家分:108
注 册:2008-7-20
收藏
得分:0 
汗,所有的Surface都错了……
2011-01-30 20:04
longyou2011
Rank: 2
等 级:论坛游民
帖 子:46
专家分:19
注 册:2011-1-12
收藏
得分:0 
谢谢你的回答
2011-01-30 22:53
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
嗯,2 楼还挺认真的。值得大家学习~~
2011-01-30 23:02
快速回复:请各位看看,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013350 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved