第8周项目2-用数组对象操作长方柱类

来源:互联网 发布:c语言程序停止 编辑:程序博客网 时间:2024/05/16 06:02
/*Copyright (c)2016,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:my.cpp *作    者:张瀚文 *完成日期:2016年4月21日 **问题描述:          <img src="http://img.blog.csdn.net/20160424122515298" alt="" />*/#include<iostream>using namespace std;class Bulk{  public:  Bulk(double x=1,double y=1,double z=1):length(x),wideth(y),height(z){};   double get_suface()   {       return suface=(height*length+height*wideth+wideth*height)*2;   }   double get_value()   {       return value=length*wideth*height;   }  private:  double value,suface;  double length,wideth,height;};int main()  { int i;      Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};      b[4].get_value();      for(i=0;i<5;i++)      cout<<"The value is:"<<b[i].get_value()<<' '<<"The suface is:"<<b[i].get_suface()<<endl;      return 0;  }

0 0
原创粉丝点击