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;
}
相关推荐
YaoYuan93232 小时前
C++ 类型推导(第一部分)
c++
HAH-HAH2 小时前
【Python 入门】(2)Python 语言基础(变量)
开发语言·python·学习·青少年编程·个人开发·变量·python 语法
递归不收敛2 小时前
一、Java 基础入门:从 0 到 1 认识 Java(详细笔记)
java·开发语言·笔记
夜猫逐梦3 小时前
【VC】 error MSB8041: 此项目需要 MFC 库
c++·mfc
纪元A梦3 小时前
贪心算法应用:配送路径优化问题详解
算法·贪心算法
zhangfeng11333 小时前
win7 R 4.4.0和RStudio1.25的版本兼容性以及系统区域设置有关 导致Plots绘图面板被禁用,但是单独页面显示
开发语言·人工智能·r语言·生物信息
姓刘的哦4 小时前
Qt中的QWebEngineView
数据库·c++·qt
C_player_0014 小时前
——贪心算法——
c++·算法·贪心算法
SundayBear4 小时前
QT零基础入门教程
c++·qt
子午5 小时前
Python的uv包管理工具使用
开发语言·python·uv