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;
}
相关推荐
kyle~9 分钟前
原子性与原子操作
运维·服务器·开发语言·c++
前路不黑暗@15 分钟前
Java:继承与多态
java·开发语言·windows·经验分享·笔记·学习·学习方法
第七序章16 分钟前
【C + +】C++11 (下) | 类新功能 + STL 变化 + 包装器全解析
c语言·数据结构·c++·人工智能·哈希算法·1024程序员节
voice67016 分钟前
西电现代密码学实验一
开发语言·python·密码学
AA陈超27 分钟前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-29 属性信息委托
c++·游戏·ue5·游戏引擎·虚幻
Theodore_102234 分钟前
深度学习(10)模型评估、训练与选择
人工智能·深度学习·算法·机器学习·计算机视觉
五条凪39 分钟前
Verilog-Eval-v1基准测试集搭建指南
开发语言·人工智能·算法·语言模型
初学小白...40 分钟前
反射概述and获得反射对象
开发语言·python
是店小二呀1 小时前
从“算法思维”到“算子思维”:我在昇腾AI开发中的认知跃迁
人工智能·算法
后藤十八里1 小时前
2025python学习笔记Part2
开发语言·python