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

相关推荐
东鹏特饮35 分钟前
系统运维(传统/通用运维)面试题
开发语言·php
其实防守也摸鱼36 分钟前
个人学习 Pwn 思路:从基础到漏洞利用的进阶路径
大数据·前端·人工智能·chrome·算法·安全·网络安全
今天要早睡_1 小时前
C++01_入门基础复习
开发语言·c++
Nuanyt1 小时前
LeetCode Hot 100 链表专题(五)· 2 题(Java)
java·算法·leetcode·链表
黑马程序员毕设2 小时前
基于 Java 的餐饮点餐系统设计与应用报告
java·开发语言
1-1=03 小时前
C# 委托与事件
开发语言·c#
Fuyo_11194 小时前
C++ 运行时多态与虚函数机制全面剖析【面试重点】
开发语言·c++·面试
w_zero_one4 小时前
递归算法(一)
java·开发语言·算法
Julien20045 小时前
管理机密(一)
运维·服务器·开发语言·学习方法
Chen_harmony5 小时前
七、STL与string类
开发语言·c++