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
相关推荐
郝学胜-神的一滴几秒前
Qt 高级编程 045:坐标体系深度实战
开发语言·c++·windows·python·qt·程序人生
码匠许师傅10 分钟前
【设计模式精讲】22.中介者模式(Mediator)
c++·设计模式·软件工程·uml·中介者模式
dsyyyyy110119 分钟前
JS复习,难点,易错点总结
开发语言·javascript·ecmascript
a187927218311 小时前
【算法】动态规划第四篇:背包收官——min 哨兵、计数世界与组合排列分水岭
算法·leetcode·动态规划·dp·01背包·算法讲解·决策合并
2601_962297481 小时前
在python3中、下列输出变量a的正确写法是_2020超星大数据Python免费答案
数据结构·python·算法·编程·字符串操作
“AI国潮设计-小江”1 小时前
Python实战 | SDXL精准控制“普宁英歌舞×星空蛋糕”IP落地,附核心Prompt与商用授权思路
开发语言·人工智能·python·prompt·aigc
辰烨chenye2 小时前
LeetCode Hot 100 题解 · 子串篇
算法·leetcode·职场和发展
辰烨chenye2 小时前
LeetCode Hot 100 题解 · 堆篇
java·算法·leetcode
手写码匠2 小时前
华为云Flexus+DeepSeek征文|DeepSeek 应用监控告警体系实战:从“用户投诉才知道“到“故障前就发现“
人工智能·深度学习·算法·aigc
shehuiyuelaiyuehao3 小时前
算法29,前缀和,除自身以外的数组的乘积
java·数据结构·算法