第三周实验报告4修改版

来源:互联网 发布:软件开发项目进度表 编辑:程序博客网 时间:2024/04/30 13:14

#include <iostream>

using namespace std;

class Cfz
{

public:

 void get_data();
 void display();

private:

 int lengh;
 int width;
 int height;
 int volume;
 int acreage;
};

void Cfz::get_data()
{
 cout<<"请输入长宽高:";
 cin>>lengh;
 cin>>width;
 cin>>height;
}

void Cfz::display()
{
 volume=lengh*width*height;
 cout<<"长方柱体积为:"<<" "<<volume<<"    ";
 acreage=2*(lengh*height+width*height+lengh*width);
 cout<<"长方柱表面积为:"<<acreage<<endl;
}

int main()
{
 Cfz c1,c2,c3;

 c1.get_data();
 cout<<"第一个长方柱:"<<endl;
 c1.display();

 
 c2.get_data();
 cout<<"第二个长方柱:"<<endl;
 c2.display();

 
 c3.get_data();
 cout<<"第三个长方柱:"<<endl;
 c3.display();

 return 0;
}

 

 

 

原创粉丝点击