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;
}
相关推荐
有点。24 分钟前
C++认识数
开发语言·c++
2023自学中1 小时前
Qt 简易聊天室(第二篇),单线程 改为 多线程,方便后续增加文件传输功能
c++·qt
Tyler_TXZ2 小时前
C++C语言之——二叉树
c语言·开发语言·数据结构·c++·二叉树
有点。2 小时前
C++二叉树二(练习题)
数据结构·c++·算法·图论
不会代码的小猴2 小时前
C++新增关键字
开发语言·c++·笔记
liulilittle3 小时前
并发与内存安全术语:定义、分类与关联
c++·安全·并发·术语
_wyt0013 小时前
从图到树:9道洛谷基础题带你入门树形结构
c++·
Titan20244 小时前
Linux网络基础知识
linux·服务器·网络·c++·学习
Titan20246 小时前
Linux网络学习:套接字、UDP的封装与应用
linux·服务器·开发语言·网络·c++
Felven6 小时前
C2. Potions (Hard Version)
c++