0
点赞
收藏
分享

微信扫一扫

Problem D: Base与Derived


Home

Web Board

ProblemSet

Standing

Status

Statistics


Problem D: Base与Derived


Time Limit: 1 Sec   Memory Limit: 128 MB

Submit: 767  

Solved: 657

[Submit][Status][Web Board]


Description



定义Base和Derived类,Derived类是Base类的子类,两个类都只有1个int类型的属性。定义它们的构造函数和析构函数,输出信息如样例所示。



Input



输入2个整数。



Output



见样例。



Sample Input



100200



Sample Output



Base 100 is created.Base 100 is created.Derived 200 is created.Derived 200 is created.Base 100 is created.Base 100 is created.



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>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
class Base
{
private:
    int bs;
public:
    Base(int b = 0):bs(b) { cout << "Base " << bs << " is created." << endl; }
    ~Base() { cout << "Base " << bs << " is created." << endl;}
};
class Derived:public Base
{
private:
    int de;
public:
    Derived(int x, int y):Base(x),de(y) { cout << "Derived " << de << " is created." << endl; }
    ~Derived(){ cout << "Derived " << de << " is created." << endl; }
};
int main()
{
    int a, b;
    cin>>a>>b;
    Base base(a);
    Derived derived(a, b);
    return 0;
}



举报

相关推荐

0 条评论