注册 登录
编程论坛 C++教室

各位好友,谭浩强书上的题,帮忙看下哪不对啊

唐兵 发布于 2013-03-17 23:19, 560 次点击
#include <iostream>
using namespace std;
class chang
{
public:
    chang(int h ,int w,int l)
    {
        height=h;
        wide=w;
        lon=l;
    }        
    int volume();
   
private:
    int height;
    int wide;
    int lon;

};
   
int chang::volume(4,4,5)
{
        return (height*wide*lon);
}
   

int main()
{
    chang v1;
    vi.volume;
    cout <<"the volume is :"<<v1.volume<<endle
        return 0;
}
6 回复
#2
wp2319572013-03-17 23:20
endle
是不是弄错了啊
#3
azzbcc2013-03-18 12:09
int chang::volume(4,4,5)
#4
唐兵2013-03-18 18:32
长宽高,求体积
#5
伤城112013-03-18 22:29
#include <iostream>
using namespace std;
class chang
{
public:      
    int volume(int height,int wide,int lon);
        int V;
private:
    int height;
    int wide;
    int lon;


};
   
int chang::volume(int height,int wide,int lon)
{
    return (height*wide*lon);
}
   

int main()
{
    int V=0;
    chang v1;

        cout <<"the volume is :"<<v1.volume(4,4,5)<<endl;

        return 0;
}
建议你再学习下C++参数传递的三种方式……
#6
gwcome2013-03-19 17:40
程序代码:
#include <iostream>
using namespace std;
class Chang//类名我用的大写
{
public:
    Chang(int h ,int w,int l)
    {
        height=h;
        wide=w;
        lon=l;
    }        
    int volume();
   
private:
    int height;
    int wide;
    int lon;

};
   
int Chang::volume()//这里是函数声明
{
    return (height*wide*lon);
}


int main()
{
    Chang v1(1,2,3);//构造函数
    cout <<"the volume is :"<<v1.volume()<<endl;
   
        return 0;
}
#7
唐兵2013-03-19 17:47
回复 5楼 伤城11
谢了哈
1