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;
}
相关推荐
new code Boy几秒前
前端核心基础汇总
开发语言·javascript·原型模式
季远迩4 分钟前
73.矩阵置零(中等)
算法
做一个码农都是奢望4 分钟前
计算机控制系统课程CH3:数字控制系统闭环响应分析与 MATLAB 实现
人工智能·算法·matlab
ou.cs5 分钟前
C# params 关键字详解:从入门到精通(保姆级教程)
开发语言·c#·.net
爱玩亚索的程序员11 分钟前
算法入门(三)学会用matplotlib画图
算法·matplotlib
請你喝杯Java12 分钟前
Python 后端开发:从虚拟环境、pip、requirements.txt 到项目启动
开发语言·python·pip
一叶落43812 分钟前
LeetCode 6. Z 字形变换(C语言详解)
c语言·数据结构·算法·leetcode
啊董dong14 分钟前
noi-2026年3月17号作业
数据结构·c++·算法
也曾看到过繁星22 分钟前
初识c++
开发语言·c++
2401_8747325333 分钟前
泛型编程与STL设计思想
开发语言·c++·算法