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;
}
相关推荐
郝学胜-神的一滴4 小时前
中级OpenGL教程 013:渲染器类架构设计与逐帧渲染流程详解
开发语言·c++·unity·游戏引擎·图形渲染·opengl·unreal
小小龙学IT5 小时前
C++ 并发编程深度解析:从内存模型到无锁数据结构
数据结构·c++
凯瑟琳.奥古斯特5 小时前
力扣1013三等分解法与C++实现
开发语言·c++·算法·leetcode·职场和发展
一拳一个呆瓜6 小时前
【STL】iostream 编程:缓冲区的作用
c++·stl
我不是懒洋洋6 小时前
从零实现一个分布式任务调度器:XXL-JOB的核心设计
c++
凯瑟琳.奥古斯特7 小时前
力扣1012数位DP解法详解
开发语言·c++·算法·leetcode·职场和发展
chh5637 小时前
C++--string
java·开发语言·网络·c++·学习
J_yyy8 小时前
基于Reactor的文件管理服务开发笔记
c++·笔记·reactor·多线程编程·muduo
李小小钦8 小时前
D. Storming Arasaka(Codeforces 2238)
c语言·开发语言·数据结构·c++·算法