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;
}
相关推荐
誰能久伴不乏4 分钟前
Qt C++ 解析 JSON 完全指南:从核心概念到工业级实战
c++·qt·json
郝学胜-神的一滴5 分钟前
力扣 144:二叉树前序遍历的优雅实现
java·数据结构·c++·python·算法·leetcode·职场和发展
枕星而眠10 分钟前
C++面向对象核心:类间关系与继承深度解析
运维·开发语言·c++·后端
比企谷八幡25 分钟前
数据库 Page 内部是什么样:Page Header、Slot 和 Line Pointer
数据库·c++·postgresql·数据库架构
代码地平线27 分钟前
C++ 入门篇类和对象·上篇:从本质深剖类与对象与C++基本用法
c语言·开发语言·数据结构·c++·笔记·算法
十五年专注C++开发35 分钟前
C++17之类模板实参自动推导CTAD
开发语言·c++·聚合初始化·catd
星马梦缘1 小时前
ACM笔记 学习版本
数据结构·c++·算法
Brilliantwxx1 小时前
【算法从零到千】【1-7】 双指针算法
开发语言·c++·笔记·算法·leetcode·推荐算法
Irissgwe1 小时前
一、Qt 概述
c++·qt·gui·qt creator