| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2354 人关注过本帖
标题:试编写一个基于对象的程序,求3个长方体的体积。
只看楼主 加入收藏
小然然
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2010-3-15
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:2 
试编写一个基于对象的程序,求3个长方体的体积。
试编写一个基于对象的程序,求3个长方体的体积。长方体对象名为rectangle,数据成员包括:length,width,height。要求用成员函数实现以下功能:
①有键盘分别输入3个长方体的长、宽、高;
②计算其长方体之体积;
③输出3个长方体的体积。
搜索更多相关主题的帖子: 编写 对象 体积 长方体 
2010-03-21 16:49
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1487
专家分:9072
注 册:2010-3-16
收藏
得分:8 
直接写了

程序代码:
class rectangle
{
    private:
        int length,width,height;
    public:
        void input();
        long volume();
        void print();
}
void rectangle::input()
{
    cout <<"input length,width,height:";
    cin >> length >> width >> height;
}
long rectangle::volume()
{
    return length*width*height;
}
void rectangle::print()
{
    cout << "V=" << rectangle()<< endl;
}

int main()
{
    rectangle rect;
    rect.input();
    rect.print();

    return 0;
}
2010-03-21 22:46
qlc00
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:157
专家分:540
注 册:2007-11-26
收藏
得分:7 
#include<iostream>
using namespace std;
class rectangle
{
    private:
        int length,width,height;
    public:
        void input();
        long volume();
        void print();
};
void rectangle::input()
{
    cout <<"input length,width,height:";
    cin>>length>>width>>height;
}
long rectangle::volume()
{
    return length*width*height;
}
void rectangle::print()
{
    cout<<"长方体的体积为:"<<volume()<<endl;
}

int main()
{
    rectangle R[3];
    for(int i=0;i<3;i++)
    {
    R[i].input();
    R[i].print();
    }

    return 0;
}
这个是对楼上的补充!

Anything is possible!
2010-03-22 11:20
快速回复:试编写一个基于对象的程序,求3个长方体的体积。
数据加载中...
 
   



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

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