第一范文网 - 专业文章范例文档资料分享平台

实验5(1) 参考答案

来源:用户分享 时间:2025/5/31 11:49:31 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

char * GetName( ) { return name; } int GetScore( ) { return score; } Date GetDate( ) { return birthday; } private: char name[20]; int score; Date birthday; };

int CompareDate( Date d1, Date d2 ); void SortByName( Student *, int num ); void SortByScore( Student *, int num ); void SortByBirthday( Student *, int num ); void PrintStudent( Student *, int num );

int main( ) {

Student st[5] = {Student(1990,2,5,99,\

Student(1989,12,25,62,\ Student(1990,3,14,88,\Student(1989,10,15,74,\Student(1990,5,22,92,\

PrintStudent( st,5); cout<

int CompareDate( Date d1, Date d2 ) { //int t;

if (d1.GetYear()

else if(d1.GetYear()==d2.GetYear()) if(d1.GetMonth()

void SortByName( Student *st, int num ) { Student t; int k; for(int i=0;ist[j].GetName()) if(strcmp(st[k].GetName(),st[j].GetName() )>0) k=j; t=st[k]; st[k]=st[i]; st[i]=t; } }

void SortByScore( Student *st, int num ) { Student t; int k; for(int i=0;i

st[i]=t; } }

void SortByBirthday( Student *st, int num ) { Student t; int k; for(int i=0;i

void PrintStudent( Student *st, int num ) { for (int i=0;i

运行结果为: Jack 99 1990-2-5 Mike 62 1989-12-25 Tom 88 1990-3-14 Kate 74 1989-10-15 Rowen 92 1990-5-22

Jack 99 1990-2-5 Kate 74 1989-10-15 Mike 62 1989-12-25 Rowen 92 1990-5-22 Tom 88 1990-3-14

Jack 99 1990-2-5 Rowen 92 1990-5-22 Tom 88 1990-3-14 Kate 74 1989-10-15 Mike 62 1989-12-25

Kate 74 1989-10-15 Mike 62 1989-12-25 Jack 99 1990-2-5 Tom 88 1990-3-14

Rowen 92 1990-5-22

Press any key to continue

三、实验指导

题目1指导:

① 程序的主要代码如下,在横线上补充相应的语句。

#include using namespace std; class Member1 { public: };

class Member2 { public:

Member2( (1) ): (2) { }

~Member2( ) { }

void show( ) { }

cout << \cout << \y = c;

cout << \Member1(int a) { }

~Member1( ) { }

void show( ) { } int x;

cout << \cout << \x = a;

cout << \

private:

private:

搜索更多关于: 实验5(1) 参考答案 的文档
实验5(1) 参考答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c15ovm659742v3bv3zrh9_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top