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;
}
相关推荐
不会C语言的男孩2 分钟前
C++ Primer Plus 第17章:输入、输出和文件
开发语言·c++
j_xxx404_3 分钟前
Linux 线程同步硬核解析:从条件变量、阻塞队列到信号量环形队列
linux·运维·服务器·c++·人工智能·ai·中间件
Zhang~Ling4 分钟前
二叉搜索树(BST)详解:插入、删除、查找与 Key/Value 实战场景
数据结构·c++·算法
小小de风呀23 分钟前
de风——【从零开始学 C++】(十)vector的模拟实现
开发语言·c++
爱和冰阔落38 分钟前
【Linux系统编程】环境变量深度解析——从 fork 继承到 export 内建命令,两张表打通进程上下文
linux·c++·环境变量·系统调用
流浪00140 分钟前
C++篇:深入理解 C++ 智能指针:从裸指针到 RAII 的蜕变
开发语言·c++
丘山望岳41 分钟前
二叉搜索双壁——map和set
开发语言·数据结构·c++
QiLinkOS43 分钟前
合肥气链科技有限公司创办与未来技术应用
c语言·数据结构·c++·人工智能·单片机·嵌入式硬件·算法
郝学胜-神的一滴1 小时前
Qt 高级开发 016:半内存管理机制
开发语言·c++·qt·程序人生·用户界面
会编程的土豆1 小时前
Go 语言匿名函数详解
c++·golang·xcode