第三周 任务四

来源:互联网 发布:java工程师是什么 编辑:程序博客网 时间:2024/04/27 22:36

#include <iostream>  
using namespace std; 
class Bulk 

public: 
    void get_value(); 
    void display(); 
private: 
    float lengh; 
    float width; 
    float height; 
}; 
 
void Bulk::get_value() 
{  
    cout<<"请输入长、宽、高:"; 
    cin>>lengh; 
    cin>>width; 
    cin>>height; 

 
void Bulk::display() 
{  
    cout<<"体积为: "<<lengh*width*height<<endl; 
    cout<<"表面积为: "<<2*(lengh*width+lengh*height+width*height)<<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; 

原创粉丝点击