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;
}
相关推荐
syagain_zsx12 小时前
BRpc 二次封装:Channel 管理、服务管理与回调工厂
c++·学习·程序人生·rpc·谷歌
fpcc13 小时前
计算机原理—如何高效的操作文件
c++·计算机原理
Rabitebla13 小时前
【系统性学习笔记】Linux 权限篇(二):文件属性、权限修改与目录权限的底层逻辑
linux·c++·笔记·学习·算法
system_error_x13 小时前
C++ 编程基础入门教程
开发语言·c++
布莱克60515 小时前
A* 算法详解:从原理到实现
开发语言·c++·算法
多弗朗皮卡丘15 小时前
C++ 智能指针
开发语言·c++·c++11·智能指针
进化中的刀盾兽16 小时前
从零实现 C++ AI 大模型接入 SDK(十):SessionManager 会话管理与多轮对话实现
c++
小成2023032026516 小时前
C++~02运算符重载
开发语言·c++
郑同学的笔记17 小时前
【c++随笔30】C++ 注册回调函数
开发语言·c++
lengxuenong17 小时前
树状数组 · 信息学学习手册2-离散化与逆序对
c++·学习·算法