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

相关推荐
黄雪超15 分钟前
JVM——对象模型:JVM对象的内部机制和存在方式是怎样的?
java·开发语言·jvm
爱coding的橙子26 分钟前
每日算法刷题Day27 6.9:leetcode二分答案2道题,用时1h20min
算法·leetcode·职场和发展
爱学习的capoo33 分钟前
matlab自控仿真【第一弹】❀传递函数和输出时域表达式
开发语言·matlab
GalaxyPokemon37 分钟前
LeetCode - 3. 无重复字符的最长子串
算法·哈希算法·散列表
EverBule43 分钟前
Python 训练 day46
开发语言·python
a.3021 小时前
C++ 时间处理指南:深入剖析<ctime>库
数据结构·c++·算法
亮亮爱刷题1 小时前
算法刷题-回溯
算法
Neil今天也要学习1 小时前
永磁同步电机无速度算法--自适应龙贝格观测器
算法
Dave_Young2 小时前
上位机开发过程中的设计模式体会(1):工厂方法模式、单例模式和生成器模式
c++·设计模式
蓝婷儿2 小时前
6个月Python学习计划 Day 18 - 项目实战 · 学生成绩管理系统(OOP版)
开发语言·python·学习