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;
}
相关推荐
周小码6 分钟前
Spacedrive:用Rust构建的虚拟分布式文件系统
开发语言·后端·rust
小张成长计划..9 分钟前
【C++】20:set和map的理解和使用
c++
聪明努力的积极向上11 分钟前
【设计】分批查询数据通用方法(基于接口 + 泛型 + 定点复制)
开发语言·设计模式·c#
灰色人生qwer15 分钟前
VS Code 配置Java环境
java·开发语言
yyy(十一月限定版)16 分钟前
C语言——排序算法
c语言·开发语言·排序算法
tgethe16 分钟前
Java 链表(LinkedList)
java·开发语言·链表
小鸡吃米…26 分钟前
Python - 多重继承
开发语言·python
曼巴UE534 分钟前
UE C++ 字符串编码转码
c++·ue5
智驱力人工智能38 分钟前
仓库园区无人机烟雾识别:构建立体化、智能化的早期火灾预警体系 无人机烟雾检测 无人机动态烟雾分析AI系统 无人机辅助火灾救援系统
人工智能·opencv·算法·目标检测·架构·无人机·边缘计算
catchadmin41 分钟前
使用 PHP 和 WebSocket 构建实时聊天应用 完整指南
开发语言·websocket·php