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;
}
相关推荐
不当菜虚困几秒前
JAVA设计模式——(四)门面模式
java·开发语言·设计模式
ruyingcai666666几秒前
用python进行OCR识别
开发语言·python·ocr
BB_CC_DD4 分钟前
四. 以Annoy算法建树的方式聚类清洗图像数据集,一次建树,无限次聚类搜索,提升聚类搜索效率。(附完整代码)
深度学习·算法·聚类
YHY_13s7 分钟前
访问者模式
c++·访问者模式
m0Java门徒8 分钟前
面向对象编程核心:封装、继承、多态与 static 关键字深度解析
java·运维·开发语言·intellij-idea·idea
liuweidong080211 分钟前
【Pandas】pandas DataFrame radd
开发语言·python·pandas
我也不曾来过136 分钟前
list底层原理
数据结构·c++·list
A charmer42 分钟前
C++ 日志系统实战第三步:熟悉掌握各种设计模式
c++·日志系统
农民也会写代码43 分钟前
dedecms织梦arclist标签noflag属性过滤多个参数
开发语言·数据库·sql·php·dedecms
Ethon_王1 小时前
STL容器适配器详解:queue篇
c++