m0_59332586 2021-06-26 09:47 采纳率: 50%
浏览 419
已采纳

设计一个名为 Rectangle的类表示矩形

 

  • 写回答

2条回答 默认 最新

  • 关注
    #include<bits/stdc++.h>
    #include<math.h>
    using namespace std;
    class Rectangle
    {
    private:
        float length;
        float width;
    public:
        void Set(float l,float w)
        {
            length=l;
            width=w;
        }
        void getArea()
        {
            float s;
            s=length*width;
            cout<<"该长方形的面积为:"<<s<<endl;
        }
    };
    int main()
    {
        Rectangle r1;
        float l,w;
        cin>>l>>w;
        r1.Set(l,w);
        r1.getArea();
    
    }
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?