c++ day2

cpp 复制代码
#include <iostream>

using namespace std;
class rectangle{
    int length;
    int width;
public:
    void set_l(){
        cin>>length;
    }
    void set_w(){
        cin>>width;
    }
    int get_l(){
        return length;
    }
    int get_w(){
        return width;
    }
    void show(){
        int peremeter=2*(length+width);
        int space=length*width;
        cout<<"周长= "<<peremeter<<"  面积="<<space<<endl;
    }
};

int main()
{
    rectangle r1;
    r1.set_l();
    r1.set_w();
    cout<<r1.get_l()<<"   "<<r1.get_w()<<endl;
    r1.show();

    return 0;
}

结果

cpp 复制代码
3
5
3   5
周长= 16  面积=15
相关推荐
胡萝卜3.034 分钟前
掌握C++ map:高效键值对操作指南
开发语言·数据结构·c++·人工智能·map
松岛雾奈.2301 小时前
机器学习--PCA降维算法
人工智能·算法·机器学习
电子_咸鱼1 小时前
【STL string 全解析:接口详解、测试实战与模拟实现】
开发语言·c++·vscode·python·算法·leetcode
sweet丶1 小时前
适合iOS开发的一种缓存策略YYCache库 的原理
算法·架构
是宇写的啊2 小时前
算法—滑动窗口
算法
沐知全栈开发2 小时前
ionic 选项卡栏操作详解
开发语言
曹牧2 小时前
C#中,#region和#endregion
开发语言·c#
顾安r2 小时前
11.22 脚本打包APP 排错指南
linux·服务器·开发语言·前端·flask
风筝在晴天搁浅2 小时前
代码随想录 509.斐波那契数
数据结构·算法
落落落sss2 小时前
java实现排序
java·数据结构·算法