C++Day2

cpp 复制代码
#include <iostream>

using namespace std;


class Rect
{
private:
    int width;
    int height;
public:
    void init(int w,int h)
    {
        width = w;
        height = h;
    }
    void set_w(int w)
    {
        width = w;
    }
    void set_h(int h)
    {
        height = h;
    }
    void show()
    {
        cout << "矩形的周长为:" << (width + height) * 2 << endl;
        cout << "矩形的面积为:" << width * height << endl;
    }
};
int main()
{
   Rect r1;
   r1.init(15,20);
   r1.show();
   r1.set_h(5);
   r1.set_w(8);
   r1.show();
    return 0;
}
相关推荐
子夜四时歌1 天前
Python详细安装与环境搭建
开发语言·python
Jinkxs1 天前
SkyWalking - Python 应用追踪:基于 skywalking-python 的埋点
开发语言·python·skywalking
大头博士先生1 天前
【3月考】二级Python最新真题及满分代码合集(基本操作题部分)
开发语言·python
xcLeigh1 天前
IoTDB Python原生接口全攻略:从基础读写到高级实战
开发语言·数据库·python·api·iotdb·原生接口·读写数据
User_芊芊君子1 天前
文科生封神!Python+AI 零门槛变现:3 天造 App,指令即收入(附脉脉 AI 沙龙干货)
开发语言·人工智能·python
是Dream呀1 天前
2025年中秋月亮只有94.91%圆?Python告诉你真相
开发语言·python·中秋节
星辰徐哥1 天前
Python开发从入门到精通:异步编程与协程
开发语言·python
AI智能研究院1 天前
Python系列进阶教程(一)Python 面向对象
开发语言·python
郁大锤1 天前
Windows 环境下安装 Python 与环境变量配置
开发语言·windows·python
李德没德1 天前
零基础快速入门Python:从安装到写出第一个程序
开发语言·python·新人首发