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;
}
相关推荐
tankeven几秒前
HJ147 最大 FST 距离
c++·算法
ALex_zry2 分钟前
物联网OTA升级系统设计:从固件分发到版本管理
c++·经验分享·物联网·跨平台
_MyFavorite_6 分钟前
JAVA重点基础、进阶知识及易错点总结(8)List 接口(ArrayList、LinkedList、Vector)
java·开发语言·list
第二层皮-合肥9 分钟前
基于C#的工业测控软件-依赖库
java·开发语言
橘子1313 分钟前
C++11 lambda表达式
开发语言·c++
2401_8579182914 分钟前
分布式系统安全通信
开发语言·c++·算法
C^h14 分钟前
RTthread消息队列学习
开发语言·算法·嵌入式
openallzzz16 分钟前
【面经分享】Java实习
java·开发语言
青瓦梦滋19 分钟前
Linux进程间通信(IPC)——system V
linux·服务器·c++·文件
鬼蛟29 分钟前
Spring Boot
java·开发语言