PeoPle类

用到了上一篇文章的TDate类。

TDate.h:

#include<iostream>
using namespace std;
int yearyn(int y);

class TDate{
private:
	int year,month,day;
public:
	TDate();
	TDate(int,int,int);
	void setDate(int,int,int);
	void addOneDay();
	void print() const;
};

TDate::TDate(){
	setDate(0,0,0);
}


TDate::TDate(int a,int b,int c){
	setDate(a,b,c);
}

void TDate::setDate(int y,int m,int d){
	year=y;
	month=m;
	day=d;
}

void TDate::addOneDay(){
	day++;
	if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&day==32)
	{month++;day=1;}
	else if((month==4||month==9||month==11)&&day==31)
	{month++;day=1;}
	else if(yearyn(year)==1&&month==2&&day==30)
	{month++;day=1;}
	else if(yearyn(year)==0&&month==2&&day==29)
	{month++;day=1;}
	if(month==13) {year++;month=1;}	
}

int yearyn(int y) {
	if(y%400==0||(y%100!=0&&y%4==0))
		return 1;
	else return 0;
}
void TDate::print() const{
	cout<<year<<"-"<<month<<"-"<<day;
}

Pople.h

#include"TDate.h"
#include<iostream>
#include<string>
using namespace std;

class People{
private:
	string name;
	TDate birthday;
	float high;
	string add;
public:
	People();
	People(string,int,int,int,float,string);
	People(string,TDate,float,string);
	void setadd(string);
	string getname();
	TDate getbirthday();
	float gethigh();
	string getadd();
	void print();
};

People::People():birthday(0,0,0){
	name="无名";
	high=0;
	add="地球";
}

People::People(string a,int y,int m,int d,float c,string s):birthday(y,m,d){
	name=a;
	high=c;
	add=s;
}

People::People(string a,TDate b,float c,string d){
	name=a;
	birthday=b;
	high=c;
	add=d;
}

void People::setadd(string a){
	add=a;
}

string People::getname(){
	return name;
}

TDate People::getbirthday(){
	return birthday;
}

float People::gethigh(){
	return high;
}

string People::getadd(){
	return add;
}

void People::print(){
	cout<<"姓名:"<<name<<endl;
	cout<<"生日:";birthday.print();
	cout<<"\n身高:"<<high<<endl;
	cout<<"住址:"<<add<<endl;
}

main.cpp

#include"People.h"

int main(){
	string name,add;
	int y,m,d;
	float high;
	cout<<"\n\t\t    =============创建档案============="<<endl;
	cout<<"输入姓名:";
	cin>>name;
	cout<<"输入生日(年月日):";
	cin>>y>>m>>d;
	TDate birthday(y,m,d);
	cout<<"请输入身高:";
	cin>>high;
	cout<<"请输入住址:";
	cin>>add;
	People people(name,birthday,high,add);
	cout<<"\n\t\t    =============人员信息:============="<<endl;
	people.print();
	system("pause");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值