C++Day2

cpp 复制代码
#include <iostream>

using namespace std;


class Rect
{
private:
    int width;
    int height;
public:
    void init(int w,int h)
    {
        width = w;
        height = h;
    }
    void set_w(int w)
    {
        width = w;
    }
    void set_h(int h)
    {
        height = h;
    }
    void show()
    {
        cout << "矩形的周长为:" << (width + height) * 2 << endl;
        cout << "矩形的面积为:" << width * height << endl;
    }
};
int main()
{
   Rect r1;
   r1.init(15,20);
   r1.show();
   r1.set_h(5);
   r1.set_w(8);
   r1.show();
    return 0;
}
相关推荐
纵有疾風起32 分钟前
C++——多态
开发语言·c++·经验分享·面试·开源
冯诺依曼的锦鲤1 小时前
算法练习:差分
c++·学习·算法
Mr_WangAndy1 小时前
现代C++模板与泛型编程_第4章_remove_all_sequence,integer_sequence,is_union
c++·c++40周年·c++标准库用法
氵文大师1 小时前
A机通过 python -m http.server 下载B机的文件
linux·开发语言·python·http
封奚泽优2 小时前
下降算法(Python实现)
开发语言·python·算法
im_AMBER2 小时前
算法笔记 16 二分搜索算法
c++·笔记·学习·算法
笃行客从不躺平2 小时前
遇到大SQL怎么处理
java·开发语言·数据库·sql
郝学胜-神的一滴2 小时前
Python中常见的内置类型
开发语言·python·程序人生·个人开发
g***B7382 小时前
Kotlin协程在Android中的使用
android·开发语言·kotlin
火白学安全2 小时前
《Python红队攻防零基础脚本编写:进阶篇(一)》
开发语言·python·安全·web安全·网络安全·系统安全