iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Problem A: 还会用继承吗?
  • 279
分享到

Problem A: 还会用继承吗?

sedWeb构造函数 2023-05-25 21:05:49 279人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

HomeWEB BoardProblemSetStandingStatusStatisticsProblem A: 还会用继承吗?Time Limit: 1 Sec    Memory Limit: &n

Home

WEB Board

ProblemSet

Standing

Status

Statistics


Problem A: 还会用继承吗?


Time Limit: 1 Sec    Memory Limit:  128 MB  

Submit: 1756  

Solved: 1255  

[ Submit][Status][Web Board]


Description



定义一个Base类,包括1个int类型的属性,以及满足输出格式要求的构造函数、拷贝构造函数和析构函数。

定义Base类的子类Derived,包括1个int类型的属性, 以及满足输出格式要求的构造函数、拷贝构造函数和析构函数。



Input



第1行N>0表示测试用例个数。

每个测试包括2个int类型的整数。



Output



见样例。



Sample Input



110 20



Sample Output



Base = 10 is created.Base = 10 is copied.Base = 10 is created.Derived = 20 is created.Base = 10 is copied.Derived = 20 is copied.Derived = 20 is erased.Base = 10 is erased.Derived = 20 is erased.Base = 10 is erased.Base = 10 is erased.Base = 10 is erased.



HINT

Append Code



append.cc,


[  Submit][Status][Web Board]


한국어<  中文 فارسی English ไทย All Copyright Reserved 2010-2011  SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin


#include <iOStream>
using namespace std;
class Base
{
protected:
    int x_;
public:
    Base(int x = 0) : x_(x){ cout << "Base = " << x_ << " is created." << endl;}
    Base(const Base & b) : x_(b.x_) { cout << "Base = " << x_ << " is copied." << endl; }
    ~Base(){ cout << "Base = " << x_ << " is erased." << endl; }
};
class Derived :public Base
{
private:
    int y_;
public:
    Derived(int x, int y) : Base(x),y_(y) { cout << "Derived = " << y_ << " is created." << endl; }
    Derived(const Derived & d) : Base(d),y_(d.y_) { cout << "Derived = " << y_ << " is copied." << endl; }
    ~Derived(){ cout << "Derived = " << y_ << " is erased." << endl; }
 
};
int main()
{
    int cases, data1, data2;
    cin>>cases;
    for (int i = 0; i < cases; i++)
    {
        cin>>data1>>data2;
        Base base1(data1), base2(base1);
 
        Derived derived1(data1, data2), derived2(derived1);
    }
}

--结束END--

本文标题: Problem A: 还会用继承吗?

本文链接: https://www.lsjlt.com/news/218563.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作