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;
}
相关推荐
longlongzihan6 分钟前
LeetCode 41. 缺失的第一个正数:从基础解法到原地哈希
c++·算法·leetcode
Lhan.zzZ42 分钟前
Qt/QML:业务记录单展示、签名确认与 PDF 导出开发
c++·qt·pdf
傲世仙尊44 分钟前
类和对象上-class与struct实例化内存对齐与this指针
c++
C++ 老炮儿的技术栈1 小时前
C++ const 的3个核心作用
服务器·c语言·c++·算法·c
小黄人软件1 小时前
粘贴助手C++版 支持 Windows 7 / 10 / 11 不会出现缺少api-ms-win-core-path-11-1-0.dll
开发语言·c++·windows
有毒的教程1 小时前
Dev-C++ 避免爆栈(Stack Overflow)完整方案
c++·算法·深度优先
程序员老陆1 小时前
从汇编层面理解 C++ 多线程
开发语言·c++·程序设计
IOT-Power1 小时前
模板方法 + 策略模式
开发语言·c++
fpcc10 小时前
c++编程实践—堆和栈越界调试
c++
weiabc12 小时前
MSYS2 UCRT64 + g++ C++ 中文输出乱码 完整全过程
c++