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;
}
相关推荐
栈与堆1 分钟前
LeetCode 19 - 删除链表的倒数第N个节点
java·开发语言·数据结构·python·算法·leetcode·链表
一路向北·重庆分伦3 分钟前
03-01:MQ常见问题梳理
java·开发语言
txinyu的博客7 分钟前
结合游戏场景理解,互斥锁,读写锁,自旋锁,CAS / 原子变量,分段锁
开发语言·c++·游戏
hugerat13 分钟前
在AI的帮助下,用C++构造微型http server
linux·c++·人工智能·http·嵌入式·嵌入式linux
阿里嘎多学长15 分钟前
2026-01-11 GitHub 热点项目精选
开发语言·程序员·github·代码托管
yuanyikangkang16 分钟前
STM32 lin控制盒
开发语言
-森屿安年-18 分钟前
unordered_map 和 unordered_set 的实现
数据结构·c++·散列表
九久。38 分钟前
手动实现std:iterator/std:string/std::vector/std::list/std::map/std:set
c++·stl
小羊羊Python40 分钟前
Sound Maze - 基于 SFML+C++14 的音效迷宫开源游戏 | MIT 协议
c++·游戏·开源