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;
}
相关推荐
fqbqrr1 小时前
2612C++,C++量钢问题
c++
充电zcx2 小时前
C++ 复习:stack、queue 与仿函数——容器适配器、priority_queue 与 deque 的取舍
c++·queue·仿函数·stack·priority_queue
俊俊几年的3 小时前
RK3588 开发板详解:硬件优势与嵌入式 Linux 学习路线
linux·c++·嵌入式
可乐_不渴3 小时前
【C++】 STL篇 哈希表实现
c++·哈希算法·散列表
风落青芜4 小时前
C++入门:类和对象(二)
开发语言·数据结构·c++·算法
风落青芜5 小时前
C++入门:类和对象(三)
开发语言·数据结构·c++·算法
iou_q5 小时前
为什么C++中在构造函数中使用初始化列表更快?
c++
wuminyu6 小时前
OpenJDK学习笔记:Native线程如何回调Java
java·linux·c语言·jvm·c++
杜 硕7 小时前
从零开始的C++生活——第十五讲
开发语言·数据结构·c++·生活
纪念 2298 小时前
C++ 算法模板与错题 模拟(一)
android·c++·算法