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;
}
相关推荐
炸薯条!20 分钟前
从零开始学C++ (内存管理)
java·jvm·c++
cpp_25012 小时前
P6625 [省选联考 2020 B 卷] 卡牌游戏
数据结构·c++·算法·前缀和·贪心·洛谷题解·省选
旖-旎5 小时前
《LeetCode 416 分割等和子集》
c++·算法·leetcode·动态规划·背包问题
Mortalbreeze5 小时前
深入理解 Linux 线程机制(四):线程同步——条件变量与信号量
linux·运维·服务器·开发语言·c++
郝学胜-神的一滴6 小时前
中级OpenGL教程 020:巧用数组与循环实现多点点光源渲染,告别冗余代码重构方案
c++·unity·游戏引擎·godot·图形渲染·unreal
zmzb01036 小时前
C++课后习题训练记录Day160
开发语言·c++
沫璃染墨7 小时前
现代C++⊂C++11篇(一)列表初始化全解 & std::initializer_list
开发语言·c++
阿米亚波7 小时前
【C++ STL】std::forward_list
开发语言·c++·笔记·stl·visual studio·forward_list
十五年专注C++开发7 小时前
qobject_cast转换失败原因分析
c++·qt·dynamic_cast·qobject_cast
小保CPP8 小时前
OCR C++ Tesseract按单词识别字符
c++·人工智能·ocr·模式识别·光学字符识别