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;
}
相关推荐
CoovallyAIHub2 分钟前
一文读懂大语言模型家族:LLM、MLLM、LMM、VLM核心概念全解析
深度学习·算法·计算机视觉
代码or搬砖6 分钟前
Collections和Arrays
java·开发语言
吴名氏.17 分钟前
电子书《Java程序设计与应用开发(第3版)》
java·开发语言·java程序设计与应用开发
于慨29 分钟前
dayjs处理时区问题、前端时区问题
开发语言·前端·javascript
范纹杉想快点毕业33 分钟前
嵌入式C语言实战开发详解
linux·运维·算法
listhi52039 分钟前
基于MATLAB的LTE系统仿真实现
开发语言·matlab
闲看云起1 小时前
LeetCode day3-最长连续序列
算法·leetcode
ss2731 小时前
ScheduledThreadPoolExecutor异常处理
java·开发语言
ejjdhdjdjdjdjjsl1 小时前
Winform初步认识
开发语言·javascript·ecmascript
随意起个昵称1 小时前
【题解学习】序列题
学习·算法