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;
}
相关推荐
Navigator_Z2 小时前
LeetCode //C - 1089. Duplicate Zeros
c语言·算法·leetcode
在繁华处2 小时前
Java从零到熟练(四):面向对象基础
java·开发语言
Unbelievabletobe2 小时前
解决了股票api接口盘后数据更新慢的问题
大数据·开发语言·python
cany10002 小时前
C++ -- 可变参数模板
c++
不会C语言的男孩3 小时前
C++ Primer 第2章:变量和基本类型
开发语言·c++
在繁华处4 小时前
Java从零到熟练(三):流程控制
java·开发语言·python
云泽8084 小时前
C++ 可调用对象通关指南:深度解析 Lambda 表达式、function 包装器与 bind 绑定器
开发语言·c++·算法
wlsh155 小时前
Go 迭代器
算法
Tri_Function5 小时前
简单图论大学习
c++
语戚5 小时前
力扣 3161. 块放置查询:线段树解法(Java 实现)
java·算法·leetcode·面试·线段树·力扣·