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;
}
相关推荐
Tanecious.9 分钟前
蓝桥杯备赛:Day4-P9749 公路
c++·蓝桥杯
AI成长日志13 分钟前
【笔面试算法学习专栏】双指针专题·简单难度两题精讲:167.两数之和II、283.移动零
学习·算法·面试
@insist12315 分钟前
网络工程师-生成树协议(STP/RSTP/MSTP)核心原理与应用
服务器·开发语言·网络工程师·软考·软件水平考试
旖-旎27 分钟前
分治(库存管理|||)(4)
c++·算法·leetcode·排序算法·快速选择算法
青稞社区.30 分钟前
ICLR‘26 Oral | 当 LLM Agent 在多轮推理中迷失时:T3 如何让强化学习重新学会主动推理
人工智能·算法·agi
春花秋月夏海冬雪34 分钟前
代码随想录刷题 - 贪心Part1
java·算法·贪心·代码随想录
野生技术架构师37 分钟前
2026年牛客网最新Java面试题总结
java·开发语言
环黄金线HHJX.38 分钟前
Tuan符号系统重塑智能开发
开发语言·人工智能·算法·编辑器
dog25039 分钟前
对数的大脑应对指数的世界
开发语言·php
Mr_Xuhhh1 小时前
深入理解Java抽象类与接口:从概念到实战
java·开发语言