#include<iostream> using namespace std; class Box{ public: float l; double v,s; Box(){} void seta(float a){ l=a; } void getvolume(){ v=l*l*l; } void getarea(){ s=6*l*l; } void disp(){ cout<<v<<" "<<s<<endl; } }; int main( ){ float ab; cin>>ab; Box obj; obj.seta( ab ); obj.getvolume( ); obj.getarea( ); obj.disp( ); return 0; }
#include<iostream> using namespace std; class CRectangle{ private: float l; float w; double c; public: CRectangle(){} CRectangle(float a=1,float b=1){ l=a; w=b; } void getc(){ c=2*l+2*w; cout<<c<<endl; } }; int main(){ float a,b; cin>>a>>b; if(a>50){ a=1; } if(b>50){ b=1; } CRectangle r1(a,b); r1.getc(); return 0; }
标签:24,Box,CRectangle,disp,void,float,2023,obj From: https://www.cnblogs.com/xuxingkai/p/17429447.html