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;
}
相关推荐
Chase_______4 分钟前
【JAVA基础指南(四)】快速掌握类和对象
java·开发语言
KiefaC6 分钟前
【C++11】包装器及其应用
开发语言·c++
weixin_470740366 分钟前
python生成环境部署
开发语言·python
环黄金线HHJX.6 分钟前
【QuantumTuan:Qt】
开发语言·qt
Eiceblue6 分钟前
Python 实现 CSV 转 TXT 格式 (单文件 + 批量处理)
开发语言·python·visual studio code
柳鲲鹏7 分钟前
关于#pragma pack(push, 8),DeepSeek回答错误
算法
settingsun122518 分钟前
【AI-算法-01】ResNet (残差网络) & Skip Connections
人工智能·算法
lsx20240629 分钟前
C 标准库 - `<time.h>`
开发语言
橘颂TA38 分钟前
【剑斩OFFER】算法的暴力美学——两数之和
数据结构·算法·leetcode·力扣·结构与算法
福楠1 小时前
C++ STL | vector
开发语言·c++·算法