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;
}
相关推荐
bubiyoushang888几秒前
MATLAB实现雷达恒虚警检测
数据结构·算法·matlab
wu_asia4 分钟前
编程技巧:如何高效输出特定倍数数列
c语言·数据结构·算法
yaoxin5211236 分钟前
289. Java Stream API - 从字符串的字符创建 Stream
java·开发语言
清 澜11 分钟前
c++高频知识点总结 第 1 章:语言基础与预处理
c++·人工智能·面试
AlenTech12 分钟前
207. 课程表 - 力扣(LeetCode)
算法·leetcode·职场和发展
癫狂的兔子14 分钟前
【Python】【Flask】抽奖功能
开发语言·python·flask
你怎么知道我是队长15 分钟前
C语言---无名位域
c语言·开发语言
fqbqrr30 分钟前
2601C++,模块基础
c++
带土130 分钟前
6. C++智能指针(1)
开发语言·c++
海南java第二人38 分钟前
SpringBoot启动流程深度解析:从入口到容器就绪的完整机制
java·开发语言