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;
}
相关推荐
weixin_395448913 分钟前
main.c_cursor_0202
前端·网络·算法
一起养小猫4 分钟前
Flutter for OpenHarmony 实战:番茄钟应用完整开发指南
开发语言·jvm·数据库·flutter·信息可视化·harmonyos
独自破碎E4 分钟前
总持续时间可被 60 整除的歌曲
java·开发语言
senijusene9 分钟前
数据结构与算法:队列与树形结构详细总结
开发语言·数据结构·算法
杜家老五10 分钟前
综合实力与专业服务深度解析 2026北京网站制作公司六大优选
数据结构·算法·线性回归·启发式算法·模拟退火算法
好好沉淀31 分钟前
Elasticsearch 中获取返回匹配记录总数
开发语言·elasticsearch
xu_yule34 分钟前
网络和Linux网络-13(高级IO+多路转接)五种IO模型+select编程
linux·网络·c++·select·i/o
2301_7657031441 分钟前
C++与自动驾驶系统
开发语言·c++·算法
Ll130452529844 分钟前
Leetcode二叉树 part1
b树·算法·leetcode
轩情吖44 分钟前
Qt的窗口(三)
c++·qt