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;
}
相关推荐
diediedei10 分钟前
模板编译期类型检查
开发语言·c++·算法
穿过锁扣的风19 分钟前
零基础入门 Python 爬虫:从基础到实战,爬取虎扑 / 豆瓣 / 图片全掌握
开发语言·爬虫·python
阿杰学AI21 分钟前
AI核心知识78——大语言模型之CLM(简洁且通俗易懂版)
人工智能·算法·ai·语言模型·rag·clm·语境化语言模型
mmz120728 分钟前
分治算法(c++)
c++·算法
一切尽在,你来43 分钟前
C++多线程教程-1.2.1 C++11/14/17 并发特性迭代
开发语言·c++
睡一觉就好了。1 小时前
快速排序——霍尔排序,前后指针排序,非递归排序
数据结构·算法·排序算法
80530单词突击赢1 小时前
C++入门指南:从零到精通
开发语言·c++
小突突突1 小时前
浅谈Java中的反射
java·开发语言
csbysj20201 小时前
JSP 发送邮件教程
开发语言
Tansmjs1 小时前
C++编译期数据结构
开发语言·c++·算法