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

相关推荐
2401_881244403 分钟前
P3808 AC 自动机(简单版)
算法
进击的圆儿22 分钟前
【学习笔记05】C++11新特性学习总结(下)
c++·笔记·学习
dlraba80225 分钟前
用 Python+OpenCV 实现实时文档扫描:从摄像头捕捉到透视矫正全流程
开发语言·python·opencv
Jayden_Ruan28 分钟前
C++十进制转二进制
数据结构·c++·算法
Haooog41 分钟前
98.验证二叉搜索树(二叉树算法题)
java·数据结构·算法·leetcode·二叉树
一人の梅雨1 小时前
1688 店铺商品全量采集与智能分析:从接口调用到供应链数据挖掘
开发语言·python·php
小何好运暴富开心幸福1 小时前
C++之日期类的实现
开发语言·c++·git·bash
威风的虫1 小时前
JavaScript中的axios
开发语言·javascript·ecmascript
老赵的博客2 小时前
c++ 是静态编译语言
开发语言·c++
Terio_my2 小时前
Python制作12306查票工具:从零构建铁路购票信息查询系统
开发语言·python·microsoft