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;
}
相关推荐
eggwyw7 小时前
C++ union 的一种妙用法
开发语言·c++
ShineWinsu9 小时前
对于Qt:QHBoxLayout常见属性以及方法的解析
c++·qt·面试·gui·客户端·布局管理器·水平布局器
小七在进步10 小时前
string的实现(1)
c++·笔记·visual studio
敲上瘾12 小时前
Qt核心机制:信号与槽详解
开发语言·c++·qt·ui·qt6.3
牢姐与蒯13 小时前
cpp算法之哈希
c++·算法·哈希算法
lcj251115 小时前
[C++] C++11
开发语言·c++·笔记
小小bugbug18 小时前
带工作窃取的线程池
c++·线程池
南风84111 天前
C++ 四种强制类型转换详解
c++
微笑星河q1 天前
C++STL【vector】常用接口函数使用和迭代器失效问题
开发语言·c++
HaiXCoder2 天前
C++ 表达式怎么读:从一行代码到类型、值类别和生命周期
c++