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;
}
相关推荐
八解毒剂11 分钟前
数据结构-平衡二叉树——对二叉搜索树的优化
数据结构·c++·算法
起床困难户57540 分钟前
条款20:协助完成返回值优化
c++
啦啦啦啦啦zzzz1 小时前
算法总结(二分查找、双指针)
c++·算法
不负岁月无痕2 小时前
C++ 模板核心内容与高频面试题汇总
java·开发语言·c++
无限进步_3 小时前
从零实现一个迷你Shell——深入理解Linux命令行解释器
linux·运维·服务器·开发语言·c++·chrome
fpcc3 小时前
工具使用——CMake中的函数和宏
c++·cmake
乐观勇敢坚强的老彭3 小时前
C++信息学奥赛lesson1
java·开发语言·c++
Irissgwe4 小时前
C++ STL关联式容器详解:set、multiset、map、multimap
开发语言·c++·stl·set·map·multiset·关联式容器
Irissgwe4 小时前
string类的模拟实现
c++·string
郝亚军4 小时前
Visual Studio 2022安装for C++桌面开发
c++·ide·visual studio