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;
}
相关推荐
im_AMBER6 小时前
Leetcode 74 K 和数对的最大数目
数据结构·笔记·学习·算法·leetcode
t198751287 小时前
电力系统经典节点系统潮流计算MATLAB实现
人工智能·算法·matlab
暮乘白帝过重山7 小时前
ArkTS ForEach 参数解析:组件与键值生成器
开发语言·数据库
断剑zou天涯7 小时前
【算法笔记】蓄水池算法
笔记·算法
LiamTuc7 小时前
Java构造函数
java·开发语言
三途河畔人7 小时前
Pytho基础语法_运算符
开发语言·python·入门
长安er7 小时前
LeetCode 206/92/25 链表翻转问题-“盒子-标签-纸条模型”
java·数据结构·算法·leetcode·链表·链表翻转
Benmao⁢7 小时前
C语言期末复习笔记
c语言·开发语言·笔记·leetcode·面试·蓝桥杯
adsadswee7 小时前
Qt 样式与 QLinearGradient 渐变详解
开发语言·qt·qt样式表·qlineargradient·qss渐变效果
唯道行7 小时前
计算机图形学·23 Weiler-Athenton多边形裁剪算法
算法·计算机视觉·几何学·计算机图形学·opengl