求个 Visual c++高手 帮我看看下面一个题目 Please!!

填空题填写横线的空白使程序输出如下要求结果(5)要求输出结果按姓名排序排序前:张三男出生日期:1978年4月20日王五女出生日期:1965年8月3日杨六女出生日期:196... 填空题 填写横线的空白 使程序输出如下要求结果
(5)要求输出结果
按姓名排序
排序前:
张三 男 出生日期: 1978年4月20日
王五 女 出生日期: 1965年8月3日
杨六 女 出生日期: 1965年9月5日
李四 男 出生日期: 1973年5月30日

排序后:
李四 男 出生日期: 1973年5月30日
王五 女 出生日期: 1965年8月3日
杨六 女 出生日期: 1965年9月5日
张三 男 出生日期: 1978年4月20日

#include<iostream>
using namespace std;

class Date{ // 日期类
int year,month,day; // 年、月、日
public:
Date(int year, int month, int day):year(year),month(month),day(day){}
int getYear()const{ return year; }
int getMonth()const{ return month; }
int getDay()const{ return day; }
};

class Person{ // 人员类
char name[14]; // 姓名
bool is_male; // 性别,为 true 时表示男性
Date birth_date; // 出生日期
public:
Person(char *name, bool is_male, Date birth_date)
//**********found**********
:_____________________________________________________

{
strcpy(this->name, name);
}
const char *getName()const{ return name; }

bool isMale()const{ return is_male; }

Date getBirthdate()const{ return birth_date; }

//利用strcmp()函数比较姓名,返回一个正数、0 或负数,分别表示大于、等于、小于
int compareName(const Person &p)const{
//**********found**********
_______________________________________
}

void show(){
cout<<endl;
cout<<name<<' '<<(is_male? "男" : "女")<<' '<<"出生日期:"
<<birth_date.getYear()<<"年" //显示出生年
//**********found**********
____________________________________________ //显示出生月
<<birth_date.getDay()<<"日"; //显示出生日
}
};

void sortByName(Person ps[], int size){ //将人员数组按姓名排列为升序
for(int i=0; i<size-1; i++){ //采用选择排序算法
int m=i;
for(int j=i+1; j<size; j++)
if(ps[j].compareName(ps[m])<0) m=j;
if(m>i){
Person p=ps[m];
ps[m]=ps[i];
ps[i]=p;
}
}
}

int main(){
Person staff[]={
Person("张三", true, Date(1978, 4, 20)),
Person("王五", false, Date(1965,8,3)),
Person("杨六", false, Date(1965,9,5)),
Person("李四", true, Date(1973,5,30))
};

const int size=sizeof(staff)/sizeof(staff[0]);
int i;
cout<<endl<<"按姓名排序";
cout<<endl<<"排序前:";
for(i=0; i<size; i++) staff[i].show();

sortByName(staff,size);

cout<<endl<<endl<<"排序后:";
for(i=0; i<size; i++) staff[i].show();

cout<<endl;
return 0;
}
展开
 我来答
我是小超子
2008-09-20 · TA获得超过380个赞
知道答主
回答量:102
采纳率:0%
帮助的人:0
展开全部
////结果为

#include<iostream>
using namespace std;

class Date{ // 日期类
int year,month,day; // 年、月、日
public:
Date(int year, int month, int day):year(year),month(month),day(day){}
int getYear()const{ return year; }
int getMonth()const{ return month; }
int getDay()const{ return day; }
};

class Person{ // 人员类
char name[14]; // 姓名
bool is_male; // 性别,为 true 时表示男性
Date birth_date; // 出生日期
public:
Person(char *name, bool is_male, Date birth_date)
//**********found**********
: is_male(is_male),birth_date(birth_date) //////

{
strcpy(this->name, name);
}
const char *getName()const{ return name; }

bool isMale()const{ return is_male; }

Date getBirthdate()const{ return birth_date; }

//利用strcmp()函数比较姓名,返回一个正数、0 或负数,分别表示大于、等于、小于
int compareName(const Person &p)const{
//**********found**********
return strcmp(name,p.name);///////
}

void show(){
cout<<endl;
cout<<name<<' '<<(is_male? "男" : "女")<<' '<<"出生日期:"
<<birth_date.getYear()<<"年" //显示出生年
//**********found**********
<<birth_date.getMonth()<<"月"//显示出生月 /////
<<birth_date.getDay()<<"日"; //显示出生日
}
};

void sortByName(Person ps[], int size){ //将人员数组按姓名排列为升序
for(int i=0; i<size-1; i++){ //采用选择排序算法
int m=i;
for(int j=i+1; j<size; j++)
if(ps[j].compareName(ps[m])<0) m=j;
if(m>i){
Person p=ps[m];
ps[m]=ps[i];
ps[i]=p;
}
}
}

int main(){
Person staff[]={
Person("张三", true, Date(1978, 4, 20)),
Person("王五", false, Date(1965,8,3)),
Person("杨六", false, Date(1965,9,5)),
Person("李四", true, Date(1973,5,30))
};

const int size=sizeof(staff)/sizeof(staff[0]);
int i;
cout<<endl<<"按姓名排序";
cout<<endl<<"排序前:";
for(i=0; i<size; i++) staff[i].show();

sortByName(staff,size);

cout<<endl<<endl<<"排序后:";
for(i=0; i<size; i++) staff[i].show();

cout<<endl;
return 0;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
唯我独狂520
2008-09-20 · TA获得超过721个赞
知道小有建树答主
回答量:947
采纳率:0%
帮助的人:444万
展开全部
太难了,不会。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式