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;
}
相关推荐
三品吉他手会点灯2 小时前
C语言学习笔记 - 50.流程控制4 - 流程控制为什么非常非常重要
c语言·开发语言·笔记·学习
一只旭宝4 小时前
【C++入门精讲22】常见设计模式
c++·设计模式
JAVA面经实录9174 小时前
Java 数据结构与算法 (终极完整学习文档)
java·数据结构·算法
在放️5 小时前
Python 爬虫 · 第三方代理接入与合规使用
开发语言·爬虫·python
KANGBboy5 小时前
java知识五(继承)
java·开发语言
c++之路5 小时前
Bazel C++ 构建系列文档(三):构建第一个 C++ 项目
开发语言·c++
AI人工智能+电脑小能手5 小时前
【大白话说Java面试题 第117题】【并发篇】第17题:线程有几种状态,之间如何转换?
java·开发语言·面试
开源Z6 小时前
LeetCode 42 · 接雨水:从暴力到双指针的三步优化
算法·leetcode
旖-旎6 小时前
《LeetCode 695 岛屿的最大面积 FloodFill DFS 解法》
c++·算法·力扣·深度优先遍历·floodfill
森G6 小时前
61、信号与槽机制在 TCP 编程中的应用---------网络编程
网络·c++·qt·网络协议·tcp/ip