这是vc++2008编译的程序:
程序中的函数FillPerson提示用户输入全部姓名和生日信息,此函数的原型为: Person FillPerson();
这句话的意思可能是要你用类实现,我没用类 只用的结构体
// tast.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
// 帮忙.cpp : 定义控制台应用程序的入口点。
//
#include <iostream>
#define N
2
using namespace std;
struct Date
{
int year;
int month;
int day;
};
struct Person
{
char name[20];
Date birthday;
};
void enter(Person &person,int i);
void
WritePerson(Person);
void Who_is_old(Person,Person);
int main()
{
Person person[N];
for(int i=0;i<N;i++)
{
enter(person[i],i);
}
Who_is_old(person[0],person[1]);
}
void enter(Person &person,int i)
{
cout<<"请输入第 "<<i+1<<" 个人的姓名和年龄:"<<endl;
cout<<"姓名:";cin>>person.name;
cout<<"生日:";
cin >>person.birthday.year>>person.birthday.month
>>person.birthday.day;
}
void WritePerson(Person person)
{
cout<<"姓名"<<person.name<<endl;
cout<<"生日"<<person.birthday.year<<" "<<person.birthday.month<<" "<<person.birthday.day<<endl;
}
void
Who_is_old(Person person1,Person person2)
{
WritePerson(person1);
WritePerson(person2);
if(person1.birthday.year<person2.birthday.year)
{cout<<"年龄较大的是"<<person1.name;}
else
{ cout<<"年龄较大的是"<<person2.name;}
if(person1.birthday.year==person2.birthday.year)
{
if(person1.birthday.month<person2.birthday.month)
{
cout<<"年龄较大的是"<<person1.name;}
else
{
cout<<"年龄较大的是"<<person2.name;}
if(person1.birthday.month==person2.birthday.month)
{
if(person1.birthday.day<person2.birthday.day)
{
cout<<"年龄较大的是"<<person1.name;}
else
{cout<<"年龄较大的是"<<person2.name;}
}
}
}