c++day2

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
    int width;
    int height;
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)
{
    this->width = w;
    this->height = h;
}
void Rect::set_w(int w)
{
     this->width = w;
}
void Rect::set_h(int h)
{
     this->height = h;
}
void Rect::show()
{
    cout << "周长为 " << width*2+height*2 << endl;
    cout << "面积为 " << width*height << endl;
}
int main()
{
    Rect s1;
    s1.init(1,2);
    s1.set_w(2);
    s1.set_h(4);
    s1.show();
    return 0;
}

相关推荐
仰泳的熊猫几秒前
题目1432:蓝桥杯2013年第四届真题-剪格子
数据结构·c++·算法·蓝桥杯·深度优先·图论
深蓝电商API3 分钟前
异步爬虫中代理池的并发管理
开发语言·爬虫·python
hhy_smile3 分钟前
Special method in class
java·开发语言
沐知全栈开发7 分钟前
Bootstrap5 轮播
开发语言
有一个好名字7 分钟前
力扣-电话号码组合
算法·leetcode·职场和发展
闻缺陷则喜何志丹11 分钟前
【数论 快速指数幂 龟速乘】P8652 [蓝桥杯 2017 国 C] 小数第 n 位|普及+
c++·蓝桥杯·数论·快速指数幂·龟速乘
鱼跃鹰飞12 分钟前
Leetcode会员尊享面试100题:1086:前五科的均分
算法·leetcode·职场和发展
༾冬瓜大侠༿12 分钟前
C++string
c语言·开发语言·c++·算法
雨季66613 分钟前
Flutter 三端应用实战:OpenHarmony “极简文本字符计数器”——量化表达的尺度
开发语言·flutter·ui·交互·dart
Lethehong14 分钟前
探索高效工作流的秘密:GLM-4.7 与 Dify 平台深度集成实践
大数据·人工智能·算法