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;
}
相关推荐
luj_17683 分钟前
心形曲线轨迹控制三大关键技术
c语言·开发语言·c++·经验分享·算法
取地址符13 分钟前
C++学习笔记(基于learn-cxx)(1)
c++·经验分享·笔记·学习
思麟呀1 小时前
C++17(三)if constexpr+折叠表达式
开发语言·c++
ysa0510301 小时前
【板子】ST表
c++·笔记·算法·板子
CHHH_HHH2 小时前
【C++11】深入解析C++可变参数模板
开发语言·c++·算法·stl·c++11
十五年专注C++开发2 小时前
fatal error C1189: #error: WinSock.h has already been included 的解决方案
c++·socket·boost
旖-旎5 小时前
《LeetCode 53 最大子数组和 || LeetCode 918 环形子数组的最大和》
c++·算法·leetcode·动态规划
qeen876 小时前
〖C++〗STL简介:发展历史、六大组件与简单应用
c++·学习·stl·模板
c238566 小时前
《动态规划:从“傻傻穷举”到“过目不忘”的修仙之路》
c++·算法·动态规划
王老师青少年编程7 小时前
csp信奥赛C++高频考点专项训练:【二分答案】案例2:木材加工
c++·二分答案·csp·高频考点·信奥赛·木材加工