长方柱

来源:互联网 发布:上海市政务数据服务网 编辑:程序博客网 时间:2024/04/27 17:09

* /

* Copyright (c) 2011, 烟台大学计算机学院

 * All rights reserved.

* 作 者: 孙培培

* 完成日期:2013 年 3月27日

* 版 本 号:v1.0

 * 输入描述:输入长方体的长宽高,求表面积和体积

* 问题描述:求表面积和体积

*/


#include <iostream>  using namespace std;  class Bulk  {  public:      void get_value();      void display();  private:      float l;      float w;      float h;  };    void Bulk::get_value()  {       cout<<"请输入长方体的 长 宽 高:"<<endl;      cin>>l;      cin>>w;      cin>>h;  }    void Bulk::display()  {       cout<<"长方体体积为: "<<l*w*h<<endl;      cout<<"长方体表面积为: "<<2*(l*w+l*h+w*h)<<endl;  }    int main()  {      Bulk b1,b2,b3;        b1.get_value();      cout<<"第一个长方体: "<<endl;      b1.display();        b2.get_value();      cout<<"第二个长方体: "<<endl;      b2.display();        b3.get_value();      cout<<"第三个长方体: "<<endl;      b3.display();      return 0;  }  


原创粉丝点击