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 分钟前
springmvc文件上传
java·开发语言
Hat_man_9 分钟前
虚拟机Ubuntu22.04交叉编译Qt5.15.2(ARM64)
开发语言·qt
Boop_wu10 分钟前
[Java 面试] 多线程1
java·开发语言
专注于大数据技术栈11 分钟前
java学习--main方法
java·开发语言·学习
2501_9418024822 分钟前
C++高性能并发编程实战:从多线程管理到内存优化与任务调度全流程解析
java·开发语言·c++
zzzsde26 分钟前
【C++】哈希表实现
数据结构·c++·哈希算法·散列表
无敌最俊朗@37 分钟前
力扣hot100-环形链表(2)142
算法·leetcode·链表
Creeper.exe1 小时前
【C语言】函数
c语言·开发语言
Elias不吃糖1 小时前
C++ 中“编译器自动帮我传参”和“我自己写初始化”的本质区别
c++
wjs20241 小时前
C++ 数据结构
开发语言