技术栈

C++Day2

Luyee162023-10-08 19:33
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;
}
上一篇:模板方法模式,基于继承实现的简单的设计模式(设计模式与开发实践 P11)
下一篇:Android多线程学习:线程
相关推荐
blasit
18 分钟前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_
1 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星
1 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛
3 天前
delete又未完全delete
c++
端平入洛
4 天前
auto有时不auto
c++
郑州光合科技余经理
5 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo123
5 天前
matlab画图工具
开发语言·matlab
dustcell.
5 天前
haproxy七层代理
java·开发语言·前端
norlan_jame
5 天前
C-PHY与D-PHY差异
c语言·开发语言
哇哈哈2021
5 天前
信号量和信号
linux·c++
热门推荐
01GitHub 镜像站点02OpenClaw 使用和管理 MCP 完全指南03OpenClaw + 飞书(Feishu)环境搭建指南04Clawdbot部署教程:解决‘gateway token missing’授权问题的完整步骤05Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services06【OpenClaw 本地实战 Ep.3】突破瓶颈:强制修改 openclaw.json 解锁 32k 上下文记忆07OpenClaw优化飞书API 额度已耗尽问题08Window 10部署openclaw报错node.exe : npm error code 12809OpenClaw大龙虾机器人完整安装教程10小黑课堂计算机二级WPSoffice题库软件下载安装教程(2026年3月最新版)