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 分钟前
ASIO异步通信——服务器网络层和逻辑层设计
开发语言·网络·c++·php
Zhang~Ling4 分钟前
C++ 多态完全指南:虚函数、重写、虚表与动态绑定深度解析
开发语言·c++
BestOrNothing_20155 分钟前
C++零基础到工程实战(5.2.5):函数默认参数和函数重载
c++·函数重载·函数默认参数·nullptr·函数声明与定义
不负岁月无痕5 分钟前
STL-- C++ list类 模拟实现
开发语言·c++·list
江屿风16 分钟前
C++OJ题经验总结(竞赛)3
开发语言·c++·笔记·算法
NiceCloud喜云16 分钟前
Anthropic 发布 Project Glasswing:未公开模型 Mythos 已挖出 10000+ 漏洞,含 OpenBSD 27 年老 bug
android·java·数据库·c++·python·docker·bug
香蕉鼠片27 分钟前
八股C++(二)
开发语言·c++
格发许可优化管理系统29 分钟前
解决Mentor许可冲突,让您的业务无缝运行
运维·服务器·c语言·c++·人工智能
思麟呀31 分钟前
在C++基础上理解CSharp-4
开发语言·jvm·c++·c#
Brilliantwxx34 分钟前
【算法题】 面试级别的二叉树题目OJ复习(上)
数据结构·c++·笔记·算法·面试