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;
}
相关推荐
科技道人4 小时前
记录 默认置灰/禁用 app ‘Search Engine Selector‘ 的disable按钮
开发语言·前端·javascript
伊玛目的门徒5 小时前
试用leetcode之典中典 二数之和问题
java·算法·leetcode
Jerry5 小时前
LeetCode 226. 翻转二叉树
算法
想做小南娘,发现自己是女生喵6 小时前
【无标题】
数据结构·算法
逝水无殇7 小时前
C# 异常处理详解
开发语言·后端·c#
Kx_Triumphs8 小时前
HDU4348 To the moon(主席树区间修改模板)
算法·题解
旖-旎8 小时前
《LeetCode647 回文子串 || LeetCode 5 最长回文子串》
c++·算法·leetcode·动态规划·哈希算法
玖玥拾8 小时前
C# 语言进阶(十五)C# 游戏服务端 MySQL 数据库
服务器·开发语言·网络·数据库·mysql·c#
铅笔侠_小龙虾9 小时前
Rust 学习目录
开发语言·学习·rust