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;
}
相关推荐
CS创新实验室13 分钟前
NumPy数组的C风格和Fortran风格
c语言·开发语言·numpy
逝水无殇1 小时前
C# 正则表达式详解
开发语言·后端·正则表达式·c#
朱永博1 小时前
使用Onnruntime实现Padim/Patchcore推理
开发语言·c#
前端H1 小时前
Biome & Rolldown:Rust 工具链接管前端基建
开发语言·前端·rust
天天进步20151 小时前
UI-TARS 源码解析 #4:UI-TARS 与传统 RPA 的区别:为什么它不是简单的坐标点击脚本?
开发语言
运维行者_1 小时前
广域网性能监控:分布式IT架构下的链路质量保障
开发语言·网络·分布式·后端·架构·数据库架构
梅雅达编程笔记1 小时前
零基础学 Python 第7章 | 字典 dict:键值对存储
开发语言·python·beautifulsoup·numpy·pandas
A_humble_scholar1 小时前
Linux(十七)深入多线程编程:同步原语与实战指南
linux·运维·c++
灯澜忆梦1 小时前
GO---map函数
开发语言·前端·后端·golang
hehelm2 小时前
Linux网络编程—HTTP静态文件服务器
linux·服务器·开发语言·网络·c++