C++第四章课后习题选做

#include <iostream>
using namespace std;
class Date{
    private:
        int year,month,day;
    public:
        Date(int year=1,int month=1,int day=1)
        {
            this->year=year;
            this->month=month;
            this->day=day;
        }
        Date(Date &d)
        {
            year=d.year;
            month=d.month;
            day=d.day;
        }
        void show()
        {
            cout<<year<<"/"<<month<<"/"<<day;
        }
        ~Date(){
        }
};
class Person{
    private:
        int number;
        char sex;
        Date date;
        long int id;
    public:
        Person(){
        }
        Person(int n,char s,Date d,long int i)
        {
            number=n;
            sex=s;
            date=d;
            id=i;
        }
        void show()
        {
            cout<<"编号"<<number<<"性别"<<sex<<" 出生日期";
            date.show();
            cout<<" 身份证号"<<id<<endl; 
        } 
        Person(Person &p)
        {
            number=p.number;
            sex=p.sex;
            date=p.date;
            id=p.id;
        }
        ~Person(){
        }
};
int main()
{
    Date D(2004,9,16);
    Person P(1,'f',D,130582);
    Person P0;
    P0=P;
    P.show();
    P0.show();
}

 

posted @ 2023-04-24 20:57  新晋软工小白  阅读(22)  评论(0)    收藏  举报