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;
}
相关推荐
碧海蓝天202227 分钟前
新版双向链表,添加了at, front, back, insert, emplace等为了兼容std.
数据结构·c++·链表
WZF-Sang35 分钟前
STL——map和set【map和set的介绍和使用】【multimap和multiset】
开发语言·数据结构·c++·b树·学习·leetcode·visual studio
m0_689087073 小时前
9.26 C++杂项
开发语言·c++
边疆.3 小时前
C++入门基础 (超详解)
c语言·开发语言·c++
菲杰克PhyJack3 小时前
C++指针等于地址加偏移量
c++
码力码力我爱你3 小时前
C++软件试用期检测
java·服务器·c++·软件开发·软件试用
John_ToDebug3 小时前
设计模式之备忘录模式
c++·设计模式·备忘录模式
jyl_sh3 小时前
CMake教程:第一步:一个基本的起点
开发语言·c++·客户端·cmake
忘梓.4 小时前
C嘎嘎入门篇:类和对象(2)
c++·面向对象
源代码•宸4 小时前
小米2025届软件开发工程师(C/C++/Java)(编程题AK)
c语言·c++·经验分享·算法·动态规划