#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAXSIZE 100
int n,m;
typedef struct 
{
    char name[20];
    int num;
    int yuwen;
    int shuxue;
    int yinyu;
}DataType;
typedef struct 
{
    DataType data[MAXSIZE];
    int last;
}seqlist;
seqlist *A1,*A2,*A3,*A4,*A6;
struct In
{
    int sum;
    int nums;
    char names[20];
}A5[MAXSIZE];
void Printf1( )
{
     printf("姓名\t学号\t语文\t数学\t英语\n");
     for(int i=1;i<=n;i++)
     {
              printf("%s\t%d\t%d\t%d\t%d\n",&A1->data[i].name,A1->data[i].num,A1->data[i].yuwen,A1->data[i].shuxue,A1->data[i].yinyu);
     }
}
void Printf2( )
{
     printf("姓名\t学号\t语文\t数学\t英语\n");
     for(int i=1;i<=m;i++)
     {
              printf("%s\t%d\t%d\t%d\t%d\n",&A2->data[i].name,A2->data[i].num,A2->data[i].yuwen,A2->data[i].shuxue,A2->data[i].yinyu);
     }
}
void Printf3()
{
     printf("姓名\t学号\t语文\t数学\t英语\n");
     for(int i=1;i<=m+n;i++)
     {
              printf("%s\t%d\t%d\t%d\t%d\n",&A3->data[i].name,A3->data[i].num,A3->data[i].yuwen,A3->data[i].shuxue,A3->data[i].yinyu);
     }  
}
void Printf4()
{
     printf("姓名\t学号\t语文\t数学\t英语\n");
     for(int i=1;i<=A4->last;i++)
     {
              printf("%s\t%d\t%d\t%d\t%d\n",&A4->data[i].name,A4->data[i].num,A4->data[i].yuwen,A4->data[i].shuxue,A4->data[i].yinyu);
     }  
}
void creat()
{
    A1=(seqlist *)malloc(sizeof(seqlist));
    A2=(seqlist *)malloc(sizeof(seqlist));
    printf("请输入文件一的内容:\n");
    printf("请输入学生的个数:\n");
    scanf("%d",&n);
    printf("请输入文件一的具体内容:\n");
    for(int i=1;i<=n;i++)
    {
        scanf("%s%d%d%d%d",A1->data[i].name,&A1->data[i].num,&A1->data[i].yuwen,&A1->data[i].shuxue,&A1->data[i].yinyu);
    }
    A1->last=n;
    printf("请输入文件二的内容:\n");
    printf("请输入学生的个数:\n");
    scanf("%d",&m);
    printf("请输入文件二的具体内容:\n");
    for(int i=1;i<=m;i++)
    {
         scanf("%s%d%d%d%d",A2->data[i].name,&A2->data[i].num,&A2->data[i].yuwen,&A2->data[i].shuxue,&A2->data[i].yinyu);
    }
    A2->last=m;
    printf("输出文件一和文件二的信息:\n");
    printf("学生成绩信息文件1(1.txt),内容如下:\n");
    printf("---------------------------------------------------------\n");
    Printf1();
    printf("---------------------------------------------------------\n");
    printf("学生成绩信息文件2(2.txt),内容如下:\n");
    printf("---------------------------------------------------------\n");
    Printf2();
    printf("---------------------------------------------------------\n");
}
void Union()
{
    
    A3=(seqlist *)malloc(sizeof(seqlist));
    for(int i=1;i<=n;i++)
    {
        strcpy(A3->data[i].name,A1->data[i].name);
        A3->data[i].num=A1->data[i].num;
        A3->data[i].yuwen=A1->data[i].yuwen;
        A3->data[i].shuxue=A1->data[i].shuxue;
        A3->data[i].yinyu=A1->data[i].yinyu;
    }
    for(int i=n+1;i<=n+m;i++)
    {
        strcpy(A3->data[i].name,A2->data[i-n].name);
        A3->data[i].num=A2->data[i-n].num;
        A3->data[i].yuwen=A2->data[i-n].yuwen;
        A3->data[i].shuxue=A2->data[i-n].shuxue;
        A3->data[i].yinyu=A2->data[i-n].yinyu;         
    }
    A3->last=n+m;
    printf("学生成绩信息文件3(3.txt),内容如下:\n");
    printf("---------------------------------------------------------\n");
    Printf3();
    printf("---------------------------------------------------------\n");
}
void bukao()
{
    A4=(seqlist *)malloc(sizeof(seqlist)); 
    int j=1;
    for(int i=1;i<=n+m;i++)
    {
        if(A3->data[i].yuwen<60||A3->data[i].shuxue<60||A3->data[i].yinyu<60)
        {
              strcpy(A4->data[j].name,A3->data[i].name);
              A4->data[j].num=A3->data[i].num;
              A4->data[j].yuwen=A3->data[i].yuwen;
              A4->data[j].shuxue=A3->data[i].shuxue;
              A4->data[j].yinyu=A3->data[i].yinyu; 
              j++;   
        }
    }
    A4->last=j-1;
    printf("学生成绩信息文件4(4.txt),内容如下:\n");
    printf("---------------------------------------------------------\n");
    Printf4();
    printf("---------------------------------------------------------\n");
}
int cmp(const void *a,const void *b)
{
    return (*(In *)b).sum - (*(In *)a).sum;
}
void Qsort()
{ 
     for(int i=1;i<=m+n;i++)
     {
          strcpy(A5[i].names,A3->data[i].name);
          A5[i].nums=A3->data[i].num;
          A5[i].sum=A3->data[i].yuwen+A3->data[i].shuxue+A3->data[i].yinyu;
     }
     qsort(A5+1,m+n,sizeof(A5[0]),cmp);
     A6=(seqlist *)malloc(sizeof(seqlist));
     for(int i=1;i<=m+n;i++)
     {
          strcpy(A6->data[i].name,A5[i].names);
          A6->data[i].num=A5[i].nums;
          for(int j=1;j<=m+n;j++)
          {
               if(A3->data[j].num==A5[i].nums)
               {
                    A6->data[i].yuwen=A3->data[j].yuwen;
                    A6->data[i].shuxue=A3->data[j].shuxue;
                    A6->data[i].yinyu=A3->data[j].yinyu;
               }
          }
     }
     for(int i=1;i<=m+n;i++)
     {
          A3->data[i].num=A6->data[i].num;
          A3->data[i].yuwen=A6->data[i].yuwen;
          A3->data[i].shuxue=A6->data[i].shuxue;
          A3->data[i].yinyu=A6->data[i].yinyu;
          strcpy(A3->data[i].name,A6->data[i].name);
     }
     printf("学生成绩信息文件5(5.txt),内容如下:\n");
     printf("---------------------------------------------------------\n");
     Printf3();
     printf("---------------------------------------------------------\n");
}
void Search()
{
     char ch[20];
     printf("请输入要查找的学生的名字:\n");
     while(scanf("%s",ch))
     {
          int i;
          for( i=1;i<=m+n;i++)
          {
               if(!(strcmp(ch,A3->data[i].name)))
               {
                    printf("%s\t%d\t%d\t%d\t%d\n",&A3->data[i].name,A3->data[i].num,A3->data[i].yuwen,A3->data[i].shuxue,A3->data[i].yinyu);
                    break;
               }
          }
          if(i==m+n+1)
          {
              printf("学生信息管理系统中不含有此学生的信息!\n");
          }
     }
}
int main()
{
    creat();
    Union();
    bukao();
    Qsort();
    Search();
    system("pause");
    return 0;      
}
posted on 2011-06-22 16:24  枫叶飘泪  阅读(387)  评论(1编辑  收藏  举报