2012年度第三周作业

来源:互联网 发布:七天网络教师登录 编辑:程序博客网 时间:2024/06/09 16:56
计算长方柱的体积、
#include <iostream>using namespace std;class square{public: void cin_date(); void volume( ); void show_volume( ); void areas( );  void show_areas();private:   int length1; int width1; int heigth1; int length2; int width2; int heigth2; int length3; int width3; int heigth3; int volume1; int volume2; int volume3; int areas1; int areas2; int areas3;};int main( ){ square s1; s1.cin_date(); s1.volume( ); s1.show_volume( );  s1.areas( ); s1.show_areas(); system("PAUSE"); return 0;}void square::cin_date( ) {  char c1,c2,c3,c4,c5,c6; cout<<"请输三个长方柱的长宽高(格式:长1:宽1:高1  长2:宽2:高2  长3:宽3:高3)"<<endl; while(1) {  cin>>length1>>c1>>width1>>c2>>heigth1>>length2>>c3>>width2>>c4>>heigth2>>length3>>c5>>width3>>c6>>heigth3;    if(c1!=':'||c2!=':'||c3!=':'||c4!=':'||c5!=':'||c6!=':')   cout<<"格式不正确,请重新输入"<<endl;  else    break; }  return; }void square::volume( ){ volume1=length1*width1*heigth1; volume2=length2*width2*heigth2; volume3=length3*width3*heigth3; return; }void square::show_volume( )      { cout<<"第一个长方柱的体积为:"<<volume1<<endl; cout<<"第二个长方柱的体积为:"<<volume2<<endl; cout<<"第三个长方柱的体积为:"<<volume3<<endl; return;}void square::areas( ){ areas1=2*(length1*width1+length1*heigth1+width1*heigth1); areas2=2*(length2*width2+length2*heigth2+width2*heigth2); areas3=2*(length3*width3+length3*heigth3+width3*heigth3); return;}void square::show_areas( )      { cout<<"第一个长方柱的表面积为:"<<areas1<<endl; cout<<"第二个长方柱的表面积为:"<<areas2<<endl; cout<<"第三个长方柱的表面积为:"<<areas3<<endl; return;}


原创粉丝点击