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;
}
相关推荐
智者知已应修善业2 小时前
【51单片机89C51及74LS273、74LS244组成】2022-5-28
c++·经验分享·笔记·算法·51单片机
Byron Loong5 小时前
【c++】为什么有了dll和.h,还需要包含lib
java·开发语言·c++
坚果派·白晓明5 小时前
【鸿蒙PC三方库移植适配框架解读系列】第一篇:Lycium C/C++ 三方库适配 — 概述与环境配置
c语言·开发语言·c++·harmonyos·开源鸿蒙·三方库·c/c++三方库
咩咦6 小时前
C++学习笔记02:cin 和 cout 输入输出
c++·学习笔记·cin·输入输出·cout
咩咦7 小时前
C++学习笔记05:引用和常引用
c++·学习笔记·引用·const·常引用
香蕉鼠片7 小时前
算法过程中不会的
开发语言·c++
阿旭超级学得完7 小时前
C++11包装器(function和bind)
java·开发语言·c++·算法·哈希算法·散列表
li星野7 小时前
位运算 & 数学 & 高频进阶九题通关(Python + C++)
c++·python·学习·算法
磊 子8 小时前
多态类原理+四种类型转换+异常处理
开发语言·c++·算法
王老师青少年编程8 小时前
csp信奥赛C++高频考点专项训练之字符串 --【回文字符串】:回文拼接
c++·字符串·csp·高频考点·信奥赛·字符串回文·回文拼接