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;
}
相关推荐
hPw0eKIqD6 小时前
C++ 模板参数推导问题小记(非推导上下文)
开发语言·c++
程序员爱德华6 小时前
Python与C++:异同点对比
c++·python
888CC++10 小时前
C语言与C++的区别:从面向过程到面向对象
java·c语言·c++
Darkwanderor11 小时前
Linux系统编程实战项目:模拟实现shell
linux·c++
himobrinehacken11 小时前
揭秘Windows程序启动的神秘之旅
c++·安全
库玛西12 小时前
C++ 运行时多态 :核心总结与原理图解
c语言·c++·笔记
Byron Loong13 小时前
【C++】重定向是什么
开发语言·c++
hansang_IR13 小时前
【题解】LC:Z 算法(Z Algorithm)
c++·算法·字符串
霍霍的袁15 小时前
【C++】模板从入门到进阶(函数模板 + 类模板 + 特化 + 分离编译)
开发语言·c++·visual studio
海清河晏11115 小时前
Qt 实战:信号与槽+事件系统
开发语言·c++·qt