⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stuinformation.cpp

📁 学生成绩信息管理软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
     temp=(node*)malloc(sizeof(node));
     q=p->next;
     while(p->next!=NULL)
     {
         while(q->next!=NULL)
         {
             if((p->mathScore)<(q->mathScore))
             {
                 temp->mathScore=p->mathScore;
                 temp->programScore=p->programScore;
                 temp->sumScore=p->sumScore;
                 temp->no=p->no;
                 temp->name[12]=p->name[12];
 
                 p->mathScore=q->mathScore;
                 p->programScore=q->programScore;
                 p->sumScore=q->sumScore;
                 p->no=q->no;
                 p->name[12]=q->name[12];
 
                 q->mathScore=temp->mathScore;
                 q->programScore=temp->programScore;
                 q->sumScore=temp->sumScore;
                 q->no=temp->no;
                 q->name[12]=temp->name[12];
             }
             q=q->next;
         }
         p=p->next;
         q=p->next;
     }
     printStu(head);
     fclose(fp);
     writeBackFile(head);
     freeNode(head);
 }
 
 void sortByProgram()//按程序设计成绩排序
 {
     FILE *fp;
     node *head,*p,*q,*temp;
     clrscr();
     if(fileExist())
         fp=(fopen(MYDB,"rb+"));
     else
         return;
 
     head=getRecords();
     p=head;
     temp=(node*)malloc(sizeof(node));
     q=p->next;
     while(p->next!=NULL)
     {
         while(q->next!=NULL)
         {
             if((p->programScore)<(q->programScore))
             {
                 temp->mathScore=p->mathScore;
                 temp->programScore=p->programScore;
                 temp->sumScore=p->sumScore;
                 temp->no=p->no;
                 temp->name[12]=p->name[12];
 
                 p->mathScore=q->mathScore;
                 p->programScore=q->programScore;
                 p->sumScore=q->sumScore;
                        p->no=q->no;
                 p->name[12]=q->name[12];
 
                 q->mathScore=temp->mathScore;
                 q->programScore=temp->programScore;
                 q->sumScore=temp->sumScore;
                        q->no=temp->no;
                 q->name[12]=temp->name[12];
                  }
             q=q->next;
         }
         p=p->next;
         q=p->next;
     }
     printStu(head);
     fclose(fp);
     writeBackFile(head);
     freeNode(head);
 }
 void sortBySum()//按总成绩排序
 {
     FILE *fp;
     node *p,*q,*head,*temp;
     clrscr();
     if(fileExist())
         fp=(fopen(MYDB,"rb+"));
     else
     return;
     head=getRecords();
     p=head;
     temp=(node*)malloc(sizeof(node));
     q=p->next;
     while(p->next!=NULL)
     {
         while(q->next!=NULL)
         {
             if((p->sumScore)<(q->sumScore))
             {
                 temp->mathScore=p->mathScore;
                 temp->programScore=p->programScore;
                 temp->sumScore=p->sumScore;
                 temp->no=p->no;
                 temp->name[12]=p->name[12];
 
                 p->mathScore=q->mathScore;
                 p->programScore=q->programScore;
                 p->sumScore=q->sumScore;
                 p->no=q->no;
                 p->name[12]=q->name[12];
 
                 q->mathScore=temp->mathScore;
                 q->programScore=temp->programScore;
                 q->sumScore=temp->sumScore;
                 q->no=temp->no;
                 q->name[12]=temp->name[12];
             }
             q=q->next;
         }
     p=p->next;
     q=p->next;
     }
     printStu(head);
     fclose(fp);
     writeBackFile(head);
     freeNode(head);
 }
 
 void QueryMenu()//学生信息查询系统
 {
     int doWhich;
     system("cls");
     fflush(stdin);
     printf("\n____________________________\n");
     printf("\n学生信息查询系统\n");
     printf("\n____________________________\n");
     printf("\n1.按学号查询\n");
     printf("\n2.按姓名查询\n");
     printf("\n3.按数学成绩查询\n");
     printf("\n4.按程序设计成绩查询\n");
     printf("\n5.按总分查询\n");
     printf("\n6.返回主菜单\n");
     printf("\n___________________________\n");
     printf("\n请输入你的选择(1~6):");
     scanf("%d",&doWhich);
     switch (doWhich)
     {
         case 1:queryByNo();break;
         case 2:queryByName();break;
         case 3:queryByMath();break;
         case 4:queryByProgram();break;
         case 5:queryBySum();break;
         default:return;
     }
 }
 
 void queryByNo()//按学号查询
 {
     node *p,*head;
     int No;
	 clrscr();
     fflush(stdin);
     head=p=getRecords();
     printf("请输入学生学号: ");
     scanf("%d",&No);
     while(p!=NULL)
     {
         if((p->no)==No)
         {
             printf("\n\n_____________________________________________________");
             printf("\n%-6s%-16s%-12s%-16s%-12s","No","name","mathScore","promgramScore","sumScore");
             printf("\n%-6d%-16s%-12d%-16d%-12d",p->no,p->name,p->mathScore,p->programScore,p->sumScore);
             printf("\n\n____________________________________________________\n");
             getchar();
             getchar();
             return;
         }
         p=p->next;
     }
     printf("此学生不存在!");
     getchar();
     getchar();
     freeNode(head);
     return;
 }
 
 void queryByName()//按姓名查询
 {
     node *p,*head;
     int i=0;
     char findName[12];
	 clrscr();
     fflush(stdin);
     head=p=getRecords();
     printf("请输入学生姓名: ");
     scanf("%s",findName);
     while(p!=NULL)
     {
         if(strcmp(p->name,findName)==0)
         {
             printf("\n\n_____________________________________________________");
             printf("\n%-6s%-16s%-12s%-16s%-12s","No","name","mathScore","promgramScore","sumScore");
             printf("\n%-6d%-16s%-12d%-16d%-12d",p->no,p->name,p->mathScore,p->programScore,p->sumScore);
             printf("\n\n____________________________________________________\n");
             i++;
         }
         p=p->next;
     }
     if(i==0)
     {
         printf("此学生不存在!");
         printf("Press any key to continue...");
         getchar();
     }
     getchar();
     freeNode(head);
     return;
 }
 void queryByMath()//按数学成绩查询
 {
     node *p,*head;
     int i=0;
     int findMath;
	 clrscr();
     fflush(stdin);
     head=p=getRecords();
     printf("请输入学生数学成绩 ");
     scanf("%d",&findMath);
     while(p!=NULL)
     {
         if((p->mathScore)==findMath)
         {
             printf("\n\n_____________________________________________________");
             printf("\n%-6s%-16s%-12s%-16s%-12s","No","name","mathScore","promgramScore","sumScore");
             printf("\n%-6d%-16s%-12d%-16d%-12d",p->no,p->name,p->mathScore,p->programScore,p->sumScore);
             printf("\n\n____________________________________________________\n");
             i++;
         }
         p=p->next;
     }
     if(i==0)
     {
         printf("此学生不存在!\n");
         printf("Press any key to continue...");
         getchar();
     }
     getchar();
     printf("Press any key to continue...");
     freeNode(head);
     return;
 }
 void queryByProgram()//按程序设计成绩查询
 {
     node *p,*head;
     int i=0;
     int findProgram;
	 clrscr();
     fflush(stdin);
     head=p=getRecords();
     printf("请输入此学生程序设计成绩: ");
     scanf("%d",&findProgram);
     while(p!=NULL)
     {
         if((p->programScore)==findProgram)
         {
             printf("\n\n_____________________________________________________");
             printf("\n%-6s%-16s%-12s%-16s%-12s","No","name","mathScore","promgramScore","sumScore");
             printf("\n%-6d%-16s%-12d%-16d%-12d",p->no,p->name,p->mathScore,p->programScore,p->sumScore);
             printf("\n\n____________________________________________________\n");
             i++;
         }
         p=p->next;
     }
     if(i==0)
     {
         printf("此学生不存在!");
         printf("Press any key to continuel...");
         getchar();
     }
     printf("Press any key to continue...");
     getchar();
     freeNode(head);
     return;
 }
 void queryBySum()//按总成绩查询
 {
     node *p,*head;
     int i=0;
     int findSum;
	 clrscr();
     fflush(stdin);
     head=p=getRecords();
     printf("请输入此学生总成绩: ");
     scanf("%d",&findSum);
     while(p!=NULL)
     {
         if((p->sumScore)==findSum)
         {
             printf("\n\n_____________________________________________________");
             printf("\n%-6s%-16s%-12s%-16s%-12s","No","name","mathScore","promgramScore","sumScore");
             printf("\n%-6d%-16s%-12d%-16d%-12d",p->no,p->name,p->mathScore,p->programScore,p->sumScore);
             printf("\n\n____________________________________________________\n");
             i++;
         }
         p=p->next;
     }
     if(i==0)
     {
         printf("此学生不存在!");
         printf("Press any key to continue...");
         getchar();
     }
     getchar();
     freeNode(head);//释放由getRecords()函数生成的链表
     return;
 }
 
 
 void printStu(node *head)//输出所有链表结点
 {
     node *p;
     p=head;
     fflush(stdin);
     clrscr();
     printf("\n\n_______________________________________________________");
     printf("\n%-6s%-16s%-12s%-16s%-12s\n","No","name","mathScore","promgramScore","sumScore");
     while(p->next!=NULL)
     {
        printf("\n%-6d%-16s%-12d%-16d%-12d",p->no,p->name,p->mathScore,p->programScore,p->sumScore);
        printf("\n\n______________________________________________________\n");
        p=p->next;
     }
     getchar();
 }
 void writeBackFile(node *head)//写文件
 {
     FILE *fp;
     node *p;
     p=head;
     if(fileExist())
     {
         fp=fopen(MYDB,"wb");
     }
     else
         return ;
     while(p->next!=NULL)
     {
         fwrite(p,sizeof(node),1,fp);
         p=p->next;
     }
     fclose(fp);
 }
 
 int writeCheckByNo(node *p,int No)//检查重复学号
 {
     int flag;
     while(p!=NULL)
     {
         if(p->no==No)
            {
                flag=0;
                return flag;
            }
         else
            p=p->next;
     }
     flag=1;
     return flag;
 }
 
 
 int fileExist()//判断文件是否存在
 {
     FILE *fp;
     if ((fp=fopen(MYDB,"rb+"))==NULL)
         return 0;
     else
         fclose(fp);
     return 1;
 }
 void freeNode(node *head)//一个一地释放链表结点
 {
     node *p,*q;
     q=p=head;
     while(p->next!=NULL)
     {
         p=p->next;
         free(q);
         q=p;
     }
     free(p);
 } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -