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;
}
相关推荐
小魏每天都学习14 小时前
【算法——c/c++]
c语言·c++·算法
lly20240614 小时前
jQuery Mobile 表格
开发语言
智码未来学堂14 小时前
探秘 C 语言算法之枚举:解锁解题新思路
c语言·数据结构·算法
惊讶的猫14 小时前
探究StringBuilder和StringBuffer的线程安全问题
java·开发语言
Halo_tjn15 小时前
基于封装的专项 知识点
java·前端·python·算法
春日见15 小时前
如何避免代码冲突,拉取分支
linux·人工智能·算法·机器学习·自动驾驶
副露のmagic15 小时前
更弱智的算法学习 day59
算法
m0_7482331715 小时前
30秒掌握C++核心精髓
开发语言·c++
Fleshy数模15 小时前
从数据获取到突破限制:Python爬虫进阶实战全攻略
java·开发语言
Duang007_15 小时前
【LeetCodeHot100 超详细Agent启发版本】字母异位词分组 (Group Anagrams)
开发语言·javascript·人工智能·python