今年多少岁

Description

定义类Date,用于表示日期,拥有:

1. 3个int类型属性,分别表示年、月、日。

2. 构造函数、析构函数。要输出一些样例所示的信息。

3. void show方法,用于输出日期值。格式见样例。

定义类Person,包括

1. 一个Date类的对象用于表示生日,一个字符串表示其姓名(假定不含有空白符)。

2. 构造函数和析构函数。要输出一些样例所示的信息。

3. int getAge(Date& now)方法,求在当前日期now时的周岁年龄。日期now一定大于birthday。

4. void show()方法,用于显示Person的信息,格式见样例。

5. getName()方法,用于返回其名字。

 

Input

输入3行。第1行包括1个合法的日期的年、月、日三个数据。

第2行是一个不含空白符的字符串,是一个人的名字。

第3行是当前日期,包括年、月、日三个数据。

 

Output

见样例。

 

Sample Input

1999 2 2

Tom

2014 5 8

Sample Output

Date 1999-2-2 is created.

Person Tom is created.

Tom's birthday is 1999-2-2.

Date 2014-5-8 is created.

Now, Tom is 15.

Date 2014-5-8 is erased.

Person Tom is erased.

Date 1999-2-2 is erased.

#include<bits/stdc++.h>
using namespace std;
class Date
{
    friend class Person;
private:
    int y,m,d;
public:
    Date(int year,int month,int day):y(year),m(month),d(day)
    {
        cout << "Date " << y << "-" << m << "-" << d << " is created." << endl;
    }
    ~Date()
    {
        cout << "Date " << y << "-" << m << "-" << d << " is erased." << endl;
    }
    void show()
    {
 
    }
};
class Person
{
    friend class Date;
private:
    Date b;
    string n;
public:
    Person(int yy,int mm,int dd,string nn):b(yy,mm,dd),n(nn)
    {
        cout << "Person " << n << " is created." << endl;
    }
    ~Person()
    {
        cout << "Person " << n << " is erased." << endl;
    }
    void show()
    {
        cout << getName() << "'s birthday is " << b.y << "-" << b.m << "-" << b.d << "." << endl;
    }
    string getName()
    {
        return n;
    }
    int getAge(Date& p)
    {
        int a;
        a=p.y-b.y;
        return a;
    }
};

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值