- #include <iostream>
- using namespace std;
- int n=0;
- class square
- {
- public:
- void cin_date();
- void volume( );
- void show_volume( );
- void areas( );
- void show_areas();
- private:
- int length;
- int width;
- int heigth;
- };
- int main( )
- {
- square s1,s2,s3;
- ++n;
- s1.cin_date();
- s1.volume( );
- s1.areas( );
- ++n;
- s2.cin_date();
- s2.volume( );
- s2.areas( );
- ++n;
- s3.cin_date();
- s3.volume( );
- s3.areas( );
- system("PAUSE");
- return 0;
- }
- void square::cin_date( )
- {
- char c1,c2;
- double length1,width1,heigth1;
- cout<<"请输入"<<"第"<<n<<"个长方柱的长宽高(格式:长:宽:高 )"<<endl;
- while(1)
- {
- cin>>length1>>c1>>width1>>c2>>heigth1;
- length=length1;
- width=width1;
- heigth=heigth1;
- if(c1!=':'||c2!=':')
- cout<<"格式不正确,请重新输入"<<endl;
- else
- break;
- }
- return;
- }
- void square::volume( )
- {
- double volume;
- volume=length*width*heigth;
- cout<<"第"<<n<<"个长方柱的体积为:"<<volume<<endl;
- return;
- }
- void square::areas( )
- {
- double areas;
- areas=2*(length*width+length*heigth+width*heigth);
- cout<<"第"<<n<<"个长方柱的表面积为:"<<areas<<endl;
- return;
- }

- 上一篇:第三周实验报告任务 3