C++ day2

1.xmind
2.

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
private:
    int  width;
    int height;
public:
    void init(int width,int height );
    void set_width(int width);
    void set_height(int height);
    void show();
};
void Rect :: init (int width,int height)
{
    this->width=width;
    this->height=height;
}
void Rect :: set_width(int width)
{
    this->width=width;
}
void Rect :: set_height(int height)
{
    this->height=height;
}
void Rect :: show()
{
    cout << "周长: " << 2*height+2*width << "  面积: " << height*width << endl ;
}

int main()
{
    int width = 10;
    int height =10 ;
    Rect r1;
    r1.init(width,height);
    r1.show();

    cout << "please enter width : " ;
    cin >> width ;
    r1.set_width(width);
    cout << "please enter height : ";
    cin >> height;
    r1.set_height(height);
    r1.show();

    return 0;
}
相关推荐
OPEN-F3 小时前
C++进阶教程:继承与多态
开发语言·c++
luj_17685 小时前
大律师考核应重能力与科技素养
c语言·开发语言·c++·经验分享·算法
刃神太酷啦6 小时前
Linux 系统 MySQL 完整安装配置教程:从卸载 MariaDB 到优化 my.cnf----《Hello MySQL!》(1)
android·linux·c语言·c++·mysql·leetcode·mariadb
汉克老师9 小时前
CSP-J 初赛(以满分为目标):第十五课《结构体、排序与自定义比较——从“给数字排队”到“给一群人排队”》
c++·csp-j·小学生·学c++编程
HugoStudio_SWAN10 小时前
C++ CMD 互动动画:按键触发爆炸效果
开发语言·c++·学习·程序人生
水饺编程10 小时前
第5章,[Win32 章节] :Polygon 函数和多边形填充模式
c语言·c++·windows·visual studio
wuminyu10 小时前
Java FFM处理网络读写事件源码剖析
java·linux·c语言·jvm·c++
一木 之林10 小时前
C/C++ 面向对象编程(OOP)(进阶)
java·c语言·c++
千谦阙听12 小时前
C++篇:类和对象(上)
开发语言·c++
_Narcissus_12 小时前
分治&递归
数据结构·c++·笔记·算法·leetcode·递归·分治