c++day2

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
    int width;
    int height;
public:
    void init(int w,int h);
    void set_w(int w);
    void set_h(int h);
    void show();
};
void Rect::init(int w,int h)
{
    this->width = w;
    this->height = h;
}
void Rect::set_w(int w)
{
     this->width = w;
}
void Rect::set_h(int h)
{
     this->height = h;
}
void Rect::show()
{
    cout << "周长为 " << width*2+height*2 << endl;
    cout << "面积为 " << width*height << endl;
}
int main()
{
    Rect s1;
    s1.init(1,2);
    s1.set_w(2);
    s1.set_h(4);
    s1.show();
    return 0;
}

相关推荐
转调9 分钟前
第九章:内存池的调整与测试
c++·内存池
行路见知35 分钟前
1.5 Go切片使用
开发语言·golang
XY_墨莲伊1 小时前
【算法设计与分析】实验5:贪心算法—装载及背包问题
c语言·数据结构·c++·算法·贪心算法·排序算法
Happy_Traveller2 小时前
三角形的最大周长(976)
数据结构·算法·leetcode
水蓝烟雨2 小时前
[HOT 100] 2824. 统计和小于目标的下标对数目
算法·hot 100
KuaCpp2 小时前
搜索与图论复习2最短路
c++·算法·图论
子燕若水2 小时前
uv 安装包
开发语言·chrome·python
Lenyiin2 小时前
《 C++ 点滴漫谈: 二十五 》空指针,隐秘而危险的杀手:程序崩溃的真凶就在你眼前!
c++·nullptr·lenyiin·c++关键字
咒法师无翅鱼3 小时前
【leetcode详解】T598 区间加法
算法·leetcode·职场和发展
砂糖はいかがですか。3 小时前
关于合并两个有序链表
数据结构·算法·链表