UJN_C++_1544 [C++ Objects and Classes] Rectangle class

 

//
#include<bits/stdc++.h>
using namespace std;

class rectangle
{
    private:
        double a,b,c,s;
    public:
        rectangle() { a=b=(double)0; }
        rectangle( double x,double y ) { a=x; b=y; }

        void assign( double x,double y ) { a=max( x,y ); b=min( x,y ); }
        void f_c() { c=2*( a+b ); }
        void f_s() { s=a*b; }
        void out() { cout<<fixed<<setprecision(2)<<a<<","<<b<<","<<c<<","<<s<<endl; };
};

int main()
{
    rectangle c1,c2( 2.0,1.0 ),c3;
    double x,y; cin>>x>>y;

    c3.assign(x,y);
    c1.f_c(); c1.f_s(); c1.out();
    c2.f_c(); c2.f_s(); c2.out();
    c3.f_c(); c3.f_s(); c3.out();

    return 0;
}

Guess you like

Origin blog.csdn.net/qq_63173957/article/details/123844301