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;
}
相关推荐
Tansmjs3 分钟前
实时数据可视化库
开发语言·c++·算法
WBluuue5 分钟前
Codeforces 1075 Div2(ABC1C2D1D2)
c++·算法
添砖java‘’9 分钟前
线程的互斥与同步
linux·c++·操作系统·线程·信息与通信
我什么都学不会10 分钟前
Python练习作业3
开发语言·python
2401_8384725126 分钟前
C++模拟器开发实践
开发语言·c++·算法
初九之潜龙勿用26 分钟前
C# 操作Word模拟解析HTML标记之背景色
开发语言·c#·word·.net·office
31087487632 分钟前
0005.C/C++学习笔记5
c语言·c++·学习
froginwe1133 分钟前
MySQL UNION 操作详解
开发语言
ruxshui33 分钟前
Python多线程环境下连接对象的线程安全管理规范
开发语言·数据库·python·sql
雨季66634 分钟前
Flutter 三端应用实战:OpenHarmony 简易点击计数器与循环颜色反馈器开发指南
开发语言·flutter·ui·ecmascript·dart