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;
}
相关推荐
kyle~34 分钟前
C++_STL---迭代器失效
开发语言·c++
wuminyu2 小时前
深入剖析 Panama Off-heap 的性能损耗与开销
java·linux·c语言·jvm·c++
rhythm-ring2 小时前
宏定义续行符 \ 的使用与踩坑
c语言·c++
江安下小雨3 小时前
muduo网络库(十六):新增连接池模块
网络·c++
「QT(C++)开发工程师」3 小时前
C++11 std::unique_ptr — 独占所有权的智能指针
c语言·开发语言·c++·qt
不正经学生4 小时前
C语言动态内存管理(上):堆上的自由与责任
c语言·开发语言·c++·算法·面试
zl.rs4 小时前
配置更适合生产环境的coredump
c++
一木 之林5 小时前
三.C++ 内存管理(进阶)(二)
开发语言·arm开发·c++
DLite5 小时前
开源一个静态类型语言——NLang
c++·编译器·nlang
uoKent5 小时前
c++中new和malloc的区别
java·jvm·c++