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;
}
相关推荐
开心星人24 分钟前
Leetcode hot100 Java刷题(二)
java·算法·leetcode
liulilittle30 分钟前
CPU亲和性深度实践:从基础原理到Intel大小核架构优化
c++·线程·进程·cpu·量化·高频·亲核性
曲鸟31 分钟前
用Python和MediaPipe实现实时手指识别
开发语言·python
hn小菜鸡35 分钟前
LeetCode 153.寻找旋转排序数组中的最小值
数据结构·算法·leetcode
weixin_3077791344 分钟前
破解遗留数据集成难题:基于AWS Glue的无服务器ETL实践
开发语言·云原生·云计算·etl·aws
毕设源码-钟学长1 小时前
【开题答辩全过程】以 基于Java的相机专卖网的设计与实现为例,包含答辩的问题和答案
java·开发语言
Albert Edison1 小时前
【项目设计】基于正倒排索引的Boost搜索引擎
linux·网络·c++·后端·http·搜索引擎
简单点好不好1 小时前
大恒相机-mono12-python示例程序
开发语言·python·数码相机
DeniuHe1 小时前
逻辑回归(Logistic Regression)详细解释与公式推导
算法·机器学习·逻辑回归
迅量科技资讯分享1 小时前
手机拍照明晰度评估:传感器尺寸像素数量与处理器算法解析
算法·三星·像素