C++的一个问题!请指教!

来源:百度知道 编辑:UC知道 时间:2024/06/16 06:45:33
我刚学C++不久,最近刚学到结构体,有一道题想了好久也不会做,请高手指教,多谢了!如下:
从键盘输入5个学生的姓名和生日,根据生日排序后输出;
要求:定义两个结构类型Date和Student;
定义一个排序函数sort;
定义一个收集学生信息的函数input;
定义一个输出显示学生信息的函数output;
定义一个学生生日的比较函数compareTo;

我也是c++初学者,试着写了下不知道能不能给你点帮助,呵呵。 那个排序和比较我不知道为什么题目要求要用两个函数来完成,我只用了一个楼主看看吧。

#include<iostream>
using namespace std;
struct information
{
string student;
int date;

}information[5];

main()
{

void input();
void output();
void compareto();
input();
compareto();
output();
system("pause");
}

void input()
{
cout<<"请输入5个学生的姓名和生日(xx年xx月xx日):"<<endl;
for(int i=0;i<=4;i++)
{
cin>>information[i].student;
cin>>information[i].date;

}
cout<<"信息输入完毕\n\n\n\n";
}

void compareto()
{
int i,j,temp;
for(j=0;j<4;j++)
for(i=0;i<4-j;i++)
if(information[i].date>information[i+1].date)
{<