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;
}
相关推荐
星恒随风31 分钟前
C++11 加餐(4)并发支持库——condition_variable 条件变量与生产者消费者模型
开发语言·c++
你不知道我是谁?1 小时前
GESP C++ 补充知识:浮点数格式化输出(%f/%e/%g)与 fmod 浮点余数实战
开发语言·c++
Rabitebla2 小时前
【Linux】 文件系统(五):挂载与软硬链接,多个文件系统怎样组成统一目录树
linux·运维·服务器·c++·笔记·学习·算法
WL学习笔记4 小时前
继承(C++)
c++·继承
lcj25115 小时前
【日志系统实战】同步/异步日志系统:手写日志等级模块,吃透enum class与7大分级,面试不慌
c++·设计模式·面试·c++11·日志系统
zmzb01035 小时前
C++课后习题训练记录Day216
数据结构·c++·算法
西西弗Sisyphus6 小时前
C++ 最小 Agentic Loop 实现 - 开始实现 完整的内容
开发语言·c++
天威?*7 小时前
团体程序设计天梯练习集L3-001 凑零钱
数据结构·c++
充值内卷8 小时前
Varsar:一个 5.7 MB 的免安装文件对比工具
c++·比较工具
wo_jack9 小时前
C++ 入门笔记(二十):stack / queue 的模拟实现 —— 适配器与 deque 底层
c++·stl·deque·queue·stack