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;
}
相关推荐
又见野草18 小时前
C++类和对象(中)
开发语言·c++
hellokandy20 小时前
C++ 如何知道程序最多可以申请多少内存
c++·vector·cin·cout
凯子坚持 c21 小时前
Protocol Buffers C++ 进阶数据类型与应用逻辑深度解析
java·服务器·c++
jiunian_cn21 小时前
【C++】IO流
开发语言·c++
CoderCodingNo1 天前
【GESP】C++六级考试大纲知识点梳理, (7) 栈与队列
开发语言·c++
超级大福宝1 天前
【力扣200. 岛屿数量】的一种错误解法(BFS)
数据结构·c++·算法·leetcode·广度优先
Frank_refuel1 天前
C++之继承
开发语言·c++
哪有时间简史1 天前
C++程序设计
c++
%xiao Q1 天前
GESP C++四级-216
java·开发语言·c++
tianyuanwo1 天前
深入浅出SWIG:从C/C++到Python的无缝桥梁
c语言·c++·python·swig