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;
}
相关推荐
星恒随风30 分钟前
C++11详解(一):统一初始化——列表初始化与 initializer_list
c++·笔记·学习·list·状态模式
jimy137 分钟前
右值大类rvalue的xvalue,和 左值大类glvalue的xvalue的区别
开发语言·c++
影视飓风TIM43 分钟前
C++哈希表:unordered_set / unordered_map底层原理
c++·算法·哈希算法·散列表
OPEN-F1 小时前
C++工程化:编译链接、调试与性能优化
开发语言·c++
邪修king2 小时前
Re:Linux 系统篇(十七):进程篇(六):环境变量深度解析|命令行参数、环境变量表、4 种获取方式与继承机制万字详解
linux·服务器·c++
张小姐的猫2 小时前
【C++开发脚手架】 —— Jsoncpp上手
java·linux·开发语言·网络·c++·tcp/ip·udp
OPEN-F2 小时前
C++并发编程:异步任务与线程池实战
开发语言·c++·算法
水饺编程3 小时前
第5章,[Win32 章节] :练习程序,BigFontPic
c语言·c++·windows·visual studio
恋恋西风11 小时前
C++ 理解 std::thread 在单核和多核上的行为差异
开发语言·c++
Brilliantwxx11 小时前
【Linux】 进程(9)程序与进程地址空间(基础+进阶+面试题)
linux·运维·服务器·开发语言·c++