C++ day2

1.xmind
2.

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
private:
    int  width;
    int height;
public:
    void init(int width,int height );
    void set_width(int width);
    void set_height(int height);
    void show();
};
void Rect :: init (int width,int height)
{
    this->width=width;
    this->height=height;
}
void Rect :: set_width(int width)
{
    this->width=width;
}
void Rect :: set_height(int height)
{
    this->height=height;
}
void Rect :: show()
{
    cout << "周长: " << 2*height+2*width << "  面积: " << height*width << endl ;
}

int main()
{
    int width = 10;
    int height =10 ;
    Rect r1;
    r1.init(width,height);
    r1.show();

    cout << "please enter width : " ;
    cin >> width ;
    r1.set_width(width);
    cout << "please enter height : ";
    cin >> height;
    r1.set_height(height);
    r1.show();

    return 0;
}
相关推荐
Let's Chat Coding3 小时前
身份识别、身份认证与授权的区别
c++
鹏易灵4 小时前
C++——8.移动语义初探(移动构造、移动赋值)
开发语言·c++·php
凯瑟琳.奥古斯特4 小时前
力扣1008:前序重建BST
开发语言·c++·算法·leetcode·职场和发展
Alvin's Tech Blog4 小时前
内存泄漏会导致操作系统永久丢失内存吗?它会导致应用程序崩溃吗?
c++·内存管理·内存泄漏
会周易的程序员4 小时前
使用 LuaBridge 封装 C++ 日志库 microLog 为 Lua 模块
c++·物联网·junit·lua·日志·iot·aiot
ysa0510304 小时前
【板子】kmp
c++·笔记·算法·板子
wbs_scy5 小时前
仿 muduo 高并发服务器项目:从 timerfd 到时间轮实现定时任务机制
linux·服务器·c++
Darkwanderor6 小时前
Linux进程优先级操作
linux·运维·c语言·c++
智者知已应修善业6 小时前
【P12159蓝桥杯数组翻转】2025-4-24
c语言·c++·经验分享·笔记·算法·蓝桥杯
盐焗鹌鹑蛋6 小时前
【C++】多态
java·jvm·c++