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;
}
相关推荐
前端 贾公子2 小时前
v-if 与 v-for 的优先级对比
开发语言·前端·javascript
嗯嗯=3 小时前
python学习篇
开发语言·python·学习
TonyLee0175 小时前
LLVM安装(ubuntu22)
c++
不会c嘎嘎5 小时前
QT中的常用控件 (二)
开发语言·qt
weixin_445054725 小时前
力扣热题51
c++·python·算法·leetcode
是一个Bug6 小时前
50道核心JVM面试题
java·开发语言·面试
她和夏天一样热6 小时前
【观后感】Java线程池实现原理及其在美团业务中的实践
java·开发语言·jvm
lkbhua莱克瓦246 小时前
进阶-索引3-性能分析
开发语言·数据库·笔记·mysql·索引·性能分析
郑州光合科技余经理6 小时前
技术架构:上门服务APP海外版源码部署
java·大数据·开发语言·前端·架构·uni-app·php
篱笆院的狗6 小时前
Java 中的 DelayQueue 和 ScheduledThreadPool 有什么区别?
java·开发语言