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;
}
相关推荐
跃龙客12 分钟前
atomic笔记
笔记·算法
iameyama20 分钟前
Amazon Redshift 和 BigQuery 数据类型区别
java·开发语言
智驱力人工智能22 分钟前
地铁隧道轨道障碍物实时检测方案 守护城市地下动脉的工程实践 轨道障碍物检测 高铁站区轨道障碍物AI预警 铁路轨道异物识别系统价格
人工智能·算法·yolo·目标检测·计算机视觉·边缘计算
-孤存-25 分钟前
Spring Bean作用域与生命周期全解析
java·开发语言·前端
陈天伟教授25 分钟前
人工智能应用- 预测化学反应:05. AI 预测化学反应类型
人工智能·深度学习·学习·算法·机器学习
LYS_061829 分钟前
C++学习(7)(输入输出)
c++·学习·算法
仰泳的熊猫31 分钟前
蓝桥杯算法提高VIP-种树
数据结构·c++·算法·蓝桥杯·深度优先·图论
Remember_99333 分钟前
SpringCloud:Nacos注册中心
java·开发语言·后端·算法·spring·spring cloud·list
几何心凉1 小时前
AI时代结合Haystack实现自定义数据抓取工具
开发语言
Trouvaille ~1 小时前
【动态规划篇】专题(一):斐波那契模型——从数学递推到算法思维
c++·算法·leetcode·青少年编程·面试·动态规划·入门