weixin_71426357 2022-06-03 18:01 采纳率: 100%
浏览 385
已结题

c++创建长方体类,计算体积与表面积

创建一个长方体类,数据成员至少包括长、宽、高,分别命名为length width height.要求用成员函数完成如下功能:
(1)从键盘上输入长、宽、高。
(2)计算长方体的体积与表面积。
(3)输出长方体的体积与表面积。
例:
1.1 2.2 3.3
area=26.62,volume=7.986
请注意;main()函数必须按如下所示编写:
int main()

Cuboid cc; float a,b,c;
cin>>a>b>c;
cc. set value(a,b,c);
cc. count area();
cc. count volume();
cc. show();
return 0;

  • 写回答

1条回答 默认 最新

  • ...404 Not Found 2022-06-03 18:19
    关注
    #include<iostream>
    using namespace std;
    class Cuboid
    {
    public:
        void setvalue(float a, float b, float c)
        {
            this->length = a;
            this->width = b;
            this->height = c;
        }
        void countarea()
        {
            this->area = 2 * (this->height*this->length + this->height*this->width + this->length*this->width);
        }
        void countvolume()
        {
            this->volume = this->height*this->length*this->width;
        }
        void show()
        {
            cout << "area=" << this->area << "," << "volume=" << this->volume;
        }
    private:
        float length;
        float width;
        float height;
        float area;
        float volume;
    };
    int main()
    {
        Cuboid cc; float a, b, c;
        cin >> a >> b >> c;
        cc.setvalue(a, b, c);
        cc.countarea();
        cc.countvolume();
        cc.show();
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 6月11日
  • 已采纳回答 6月3日
  • 创建了问题 6月3日

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题