// Date.h
#ifndef DATE_H
#define DATE_H
class Date{
protected:
int year;
int month;
int day;
public:
Date(int yearv,int monthv,int dayv);
Date(const Date &date);
void Init(int yearv,int monthv,int dayv);
void Init(const Date &date);
void show();
};
#endif
#include"Date.h"
#include<iostream>
using namespace std;
Date::Date(int yearv,int monthv,int dayv)
{
year=yearv;
month=monthv;
day=dayv;
}
Date::Date(const Date &date)
{
year=date.year;
month=date.month;
day=date.day;
}
void Date::Init(int yearv,int monthv,int dayv)
{
year=yearv;
month=monthv;
day=dayv;
}
void Date::Init(const Date &date)
{
year=date.year;
month=date.month;
day=date.day;
}
void Date::show()
{
cout<<"出生日期"<<"\t"<<year<<"."<<month<<"."<<day<<endl;
}
//People.h
#ifndef PEOPLE_H
#define PEOPLE_H
#include "Date.h"
#include<string.h>
class People{
public:
People(long no,string name,string sex,string ident_no,int year,int month,int day);
People(long no,string name,string sex,string ident_no,Date date);
People(const People &p);
void Init(long no,string name,string sex,string ident_no,int year,int month,int day);
void Init(long no,string name,string sex,string ident_no,Date date);
void Init(const People &p);
void show() const;
protected:
Date m_date;
long m_no;
string m_ident_no;
string m_name;
string m_sex;
};
#endif
#include"People.h"
#include "Date.h"
#include<string>
#include<iostream>
using namespace std;
People::People(long no,string name,string sex,string ident_no,int year,int month,int day):m_date(year,month,day)
{
m_no=no;
m_name=name;
m_sex=sex;
m_ident_no=ident_no;
}
People::People(long no,string name,string sex,string ident_no,Date date):m_date(date)
{
m_no=no;
m_name=name;
m_sex=sex;
m_ident_no=ident_no;
}
People::People(const People &p):m_date(date)
{
m_no=p.m_no;
m_name=p.m_name;
m_sex=p.m_sex;
m_ident_no=p.m_ident_no;
}
void People::Init(long no,string name,string sex,string ident_no,int year,int month,int day)
{
m_date.Init(year,month,day);
m_no=no;
m_name=name;
m_sex=sex;
m_ident_no=ident_no;
}
void People::Init(long no,string name,string sex,string ident_no,Date date)
{
m_date=date;
m_no=no;
m_name=name;
m_sex=sex;
m_ident_no=ident_no;
}
void People::Init(const People &p)
{
m_date=p.m_date;
m_no=p.m_no;
m_name=p.m_name;
m_sex=p.m_sex;
m_ident_no=p.m_ident_no;
}
void People::show() const
{
cout<<"名字"<<"\t"<<m_name<<endl;
cout<<"編號"<<"\t"<<m_no<<endl;
cout<<"性別"<<"\t"<<m_sex<<endl;
cout<<"身份證號"<<"\t"<<m_ident_no<<endl;
m_date.show();
}
uj5u.com熱心網友回復:
// main.cpp#include"People.h"
#include"Date.h"
void main()
{
People p(231,"dhfioer","hfk","hdi",234,3,87);
p.show();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/148779.html
標籤:基礎類
下一篇:Django 配置JWT認證方式
