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;
}
相关推荐
小师兄吃牛肉8 分钟前
C++ 与 Lua 的协程交互:从原理到实战
c++·lua·交互
YYYing.18 分钟前
【设计模式系列 (八) 】组合模式
c++·后端·设计模式·组合模式·c/c++
艾莉丝努力练剑25 分钟前
【QT】系统相关:多线程QThread基础
开发语言·网络·c++·qt·学习·大模型
l1t29 分钟前
DeepSeek总结的PIVCO-Huffman编码性能优化
数据结构·c++·算法
王维同学1 小时前
ETW监控-KswordARK功能展示
c++·windows·安全
東隅已逝,桑榆非晚1 小时前
c++模板进阶
开发语言·c++·笔记·学习
左手の明天10 小时前
SLIP 协议封装与解析详解:原理、C 代码与实战案例
linux·c语言·开发语言·c++
青少儿编程课堂10 小时前
后缀自动机解析:本质不同子串与最长重复片段统计
c++·python·算法·bfs·信息学竞赛
朝朝辞暮i10 小时前
C++ 第 12 课:局部变量、作用域、变量生命周期
开发语言·c++·算法