c++刷题

17.电话号码的组合

来源于题解思路:

继承

CC14 KiKi设计类继承

复制代码
#include <iostream>
#include <memory>
using namespace std;
class Shape{
private:
    int x;
    int y;
};

class Rectangle:public Shape
{
public:
    Rectangle(int length,int width)
        :Shape()
        ,_length(length)
        ,_width(width)
        {}
    void GetArea()
    {
        cout<<_length*_width<<endl;
    }
protected:
    int _length;
    int _width;
};
class Circle:public Shape{
public:
    Circle(int r)
        :Shape()
        ,_r(r)
        {}
    void GetArea()
    {
        cout<<3.14*_r*_r<<endl;
    }
private:
    int _r;
};
class Square:public Rectangle
{
public:
    Square(int len)
        :Rectangle(len,len)
        {}
    void GetArea()
    {
        cout<<_length*_length<<endl;
    }

};
int main() {
    int length=0,width=0;
    cin>>length>>width;
   Rectangle ret(length,width);
   ret.GetArea();
   int r;
   cin>>r;
   Circle cir(r);
   cir.GetArea();

   int len;
   cin>>len;
   Square le(len);
   le.GetArea();
}
// 64 位输出请用 printf("%lld")

双指针算法

283.移动零

相关推荐
zym大哥大15 分钟前
C++多线程函数介绍
c++
向宇it20 分钟前
【零基础入门unity游戏开发——2D篇】SortingGroup(排序分组)组件
开发语言·unity·c#·游戏引擎·材质
旺代22 分钟前
JavaScript日期对象
开发语言·javascript·ecmascript
nlog3n25 分钟前
Java 桥接模式 详解
java·开发语言·桥接模式
PownShanYu31 分钟前
RainbowDash 的 Robot
算法
军训猫猫头34 分钟前
87.在线程中优雅处理TryCatch返回 C#例子 WPF例子
开发语言·ui·c#·wpf
yuanpan37 分钟前
如何将python项目打包成Windows环境的exe应用提供给客户使用
开发语言·windows·python
njsgcs1 小时前
python getattr调用当前文件引用的模块内的方法,实例
开发语言·python
Phoebe鑫1 小时前
数据结构每日一题day11(链表)★★★★★
数据结构·算法
lly2024061 小时前
R 列表:深入解析及其在数据分析中的应用
开发语言