c++day2

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
private:
    int width;
    int hight;
public:
    void init(int w, int h);
    void set_w(int w);
    void set_h(int h);
    void show();
};

void Rect::init(int w, int h)
{
    width = w;
    hight = h;
}

void Rect::set_w(int w)
{
    width = w;
}

void Rect::set_h(int h)
{
    hight = h;
}

void Rect::show()
{
    cout << "width = " << width << "\t hight = " << hight << "\t周长 = " << 2*(width+hight) << endl;
    cout << "width = " << width << "\t hight = " << hight << "\t面积 = " << width*hight << endl;
}
int main()
{
    Rect re;
    re.init(4, 5);
    re.show();
    re.set_h(10);
    re.show();
    re.set_w(10);
    re.show();
    return 0;
}
相关推荐
啊阿狸不会拉杆13 小时前
《机器学习导论》第 2 章-监督学习
数据结构·人工智能·python·学习·算法·机器学习·监督学习
乌萨奇也要立志学C++13 小时前
【洛谷】记忆化搜索 原理剖析与经典例题详解
算法·深度优先
Code9200713 小时前
洛谷P3514 [POI 2011] LIZ-Lollipop(思维题)
算法
独自破碎E13 小时前
【BISHI11】变幻莫测
android·java·开发语言
Gavin在路上13 小时前
SpringAIAlibaba之短期记忆与长期记忆实现原理(十一)
开发语言·人工智能
m0_7066532313 小时前
C++中的解释器模式
开发语言·c++·算法
王老师青少年编程13 小时前
2022信奥赛C++提高组csp-s复赛真题及题解:数据传输
c++·数据传输·真题·csp·信奥赛·csp-s·提高组
We་ct13 小时前
LeetCode 202. 快乐数:题解+思路拆解
前端·算法·leetcode·typescript
lsx20240613 小时前
命令模式:深入理解与实战应用
开发语言
hetao173383713 小时前
2026-01-29~02-03 hetao1733837 的刷题记录
c++·笔记·算法