c++day2

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
private:
    int width;
    int hight;
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)
{
    width = w;
    hight = h;
}

void Rect::set_w(int w)
{
    width = w;
}

void Rect::set_h(int h)
{
    hight = h;
}

void Rect::show()
{
    cout << "width = " << width << "\t hight = " << hight << "\t周长 = " << 2*(width+hight) << endl;
    cout << "width = " << width << "\t hight = " << hight << "\t面积 = " << width*hight << endl;
}
int main()
{
    Rect re;
    re.init(4, 5);
    re.show();
    re.set_h(10);
    re.show();
    re.set_w(10);
    re.show();
    return 0;
}
相关推荐
fai厅的秃头姐!2 小时前
C语言03
c语言·数据结构·算法
life_time_2 小时前
C语言(22)
c语言·开发语言
lisanndesu2 小时前
动态规划
算法·动态规划
Minner-Scrapy2 小时前
DApp 开发入门指南
开发语言·python·web app
myprogramc2 小时前
十大排序算法
数据结构·算法·排序算法
记得早睡~3 小时前
leetcode150-逆波兰表达式求值
javascript·算法·leetcode
修己xj3 小时前
算法系列之贪心算法
算法
qy发大财3 小时前
跳跃游戏(力扣55)
算法·leetcode
BingLin-Liu3 小时前
蓝桥杯备考:搜索算法之排列问题
算法·职场和发展·蓝桥杯