C++Day2

cpp 复制代码
#include <iostream>

using namespace std;


class Rect
{
private:
    int width;
    int height;
public:
    void init(int w,int h)
    {
        width = w;
        height = h;
    }
    void set_w(int w)
    {
        width = w;
    }
    void set_h(int h)
    {
        height = h;
    }
    void show()
    {
        cout << "矩形的周长为:" << (width + height) * 2 << endl;
        cout << "矩形的面积为:" << width * height << endl;
    }
};
int main()
{
   Rect r1;
   r1.init(15,20);
   r1.show();
   r1.set_h(5);
   r1.set_w(8);
   r1.show();
    return 0;
}
相关推荐
青少儿编程课堂11 分钟前
第十八届蓝桥杯青少组图形化真题:校园分形雪花绘制解析(全国青少年信息素养大赛·电子学会图形化考级冲刺)
c++·python·算法·bfs·信息学竞赛
ClkLog-开源埋点用户分析30 分钟前
【产品说明】【埋点分析】ClkLog 商业版 Java 运行环境安全更新说明
java·开发语言
yuzhiboyouye1 小时前
《阿里巴巴 Java 开发手册》的 MySQL 核心规范
java·开发语言·mysql
郝学胜-神的一滴2 小时前
Effective STL 条款12:对容器线程安全性的现实期望
c语言·开发语言·c++·qt·网络协议·rpc·numpy
geovindu2 小时前
python: KNeighborsClassifier K
开发语言·后端·python·算法
让我们一起加油好吗4 小时前
【数据结构】线段树详解
数据结构·c++·算法·线段树·洛谷
时间的情敌4 小时前
Three.js 射线拾取进阶:hover 高亮、点击弹窗、多物体过滤、穿透拾取
开发语言·javascript·three.js
Amumu121384 小时前
TypeScript学习: 基本类型(一)
开发语言·前端·typescript
sul.i4 小时前
浅析 · 分治
c++
让我们一起加油好吗5 小时前
【数据结构】ST 表
数据结构·c++·算法·动态规划·洛谷·st表