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;
}

相关推荐
挥剑决浮云 -11 分钟前
Linux 之 安装软件、GCC编译器、Linux 操作系统基础
linux·服务器·c语言·c++·经验分享·笔记
Mephisto.java24 分钟前
【力扣 | SQL题 | 每日四题】力扣2082, 2084, 2072, 2112, 180
sql·算法·leetcode
robin_suli25 分钟前
滑动窗口->dd爱框框
算法
丶Darling.27 分钟前
LeetCode Hot100 | Day1 | 二叉树:二叉树的直径
数据结构·c++·学习·算法·leetcode·二叉树
labuladuo52037 分钟前
Codeforces Round 977 (Div. 2) C2 Adjust The Presentation (Hard Version)(思维,set)
数据结构·c++·算法
wjs202442 分钟前
XSLT 实例:掌握 XML 转换的艺术
开发语言
萧鼎1 小时前
Python第三方库选择与使用陷阱避免
开发语言·python
安冬的码畜日常1 小时前
【D3.js in Action 3 精译_029】3.5 给 D3 条形图加注图表标签(上)
开发语言·前端·javascript·信息可视化·数据可视化·d3.js
jiyisuifeng19911 小时前
代码随想录训练营第54天|单调栈+双指针
数据结构·算法
小柯J桑_1 小时前
C++:STL简介
c++·stl