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;
}
相关推荐
是立不是利11 分钟前
大文件导致请求被拒的连锁反应
开发语言·前端·javascript
OYYHXPJR19 分钟前
【算法】区间重叠模板和矩形重叠模板
算法
shehuiyuelaiyuehao21 分钟前
算法46,分治快排,排序数组
java·算法·排序算法·排序
東隅已逝,桑榆非晚26 分钟前
vector(模拟实现)
c++·笔记·学习
野生技术架构师29 分钟前
1200 道 JAVA 面试题(各大企业常见面试题及答案)
java·开发语言
远航计算机37 分钟前
GEO 选题从哪来?用一份 Query 词库把一年内容排出来
大数据·人工智能·算法·aigc
宣宣猪的小花园.37 分钟前
【机器学习】神经网络与表征:为什么深度学习能自动提取特征
人工智能·嵌入式硬件·算法·机器学习
“AI国潮设计-小江”39 分钟前
【Python/SDXL实战】潮汕国潮IP视觉落地:普宁美食猫IP & 创意甜品设计(附ComfyUI工作流思路)
开发语言·人工智能·python·prompt·aigc
mmmmath_31 小时前
LeetCode.018.四数之和
数据结构·算法·leetcode
AIGCmagic社区1 小时前
腾讯混元 AuK 技术报告拆读:1.5B 统一语音生成与编辑,蒸馏后 4 步无 CFG 提速 4.5 倍
人工智能·算法·aigc·ai多模态