2023 5 24

xuxingkai / 2023-05-24 / 原文

#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;
}