C语言实现学生管理信息系统

来源:互联网 发布:mysql 清空数据表 编辑:程序博客网 时间:2024/05/18 01:11
#include <stdio.h>#include <stdlib.h>#define SIZE 100enum{    SYSEXIT,    INPUTSTUDENT,    DELETESTUDENT,    UPDATESTUDENT,    SEARCHSTUDENT,    SORTSTUDENT};struct SCORE{    float math;    float chinese;    float english;};struct STUDENT{    int     num;    char    name[10];    char    adr[10];    char    sex[4];    struct  SCORE score;    }Student[SIZE] ={0}; void InputStudent(){    int count,choice;    for(count =0; count <SIZE; count++)    {        if(Student[count].num ==0)            break;    }    if(count >=SIZE)    {        printf("数据存储已满!\n");        return;    }    for(;count <SIZE ;count++)    {        printf("请输入第%d个学生的学号:\n",count+1);scanf("%d",&Student[count].num);        printf("请输入第%d个学生的姓名:\n",count+1);scanf("%s",&Student[count].name);        printf("请输入第%d个学生的性别:\n",count+1);scanf("%s",&Student[count].sex);        printf("请输入第%d个学生的地址:\n",count+1);scanf("%s",&Student[count].adr);        printf("请输入第%d个学生的数学成绩:\n",count+1);scanf("%f",&Student[count].score.math);        printf("请输入第%d个学生的语文成绩:\n",count+1);scanf("%f",&Student[count].score.chinese);        printf("请输入第%d个学生的英语成绩:\n",count+1);scanf("%f",&Student[count].score.english);        printf("是否继续输入学生信息?\n1.YES\n0.NO\n");        scanf("%d",&choice);        if(choice ==0)            break;    }} void DeleteStudent(){    int count,choice,sign=0;    int sno;    for(count=0 ;count <SIZE; count ++)    {        if(Student[count].num !=0)        {            sign++;        }    }    if(sign ==0)    {        printf("没有存储任何学生信息!\n");        return ;     }    printf("1.根据学号删除学上信息:\n");    printf("2.删除全部学生信息:\n");     printf("0.退出\n");     printf("请输入功能选择\n");     scanf("%d",&choice);    if(choice ==0)    {        return;    }    else if(choice ==1)    {         printf("\n");         printf("请输入要删除的学生学号:\n");           scanf("%d",&sno);         count=sno-1;         for(;count < SIZE-1; count ++)         {             Student[count] =Student[count+1];         }         printf("删除成功!\n\n");     }     else if(choice ==2)    {        for(count =0; count <SIZE; count ++)         {            Student[count].num=0;        }        printf("删除成功!\n\n");     }    else        return;      }void UodateStudent(){     int sign =0;int count;     for(count=0 ; count <SIZE; count ++)     {        if(Student[count].num !=0)        {            sign++;        }     }     if(sign ==0)     {        printf("没有存储任何学生信息!\n");        return ;      }     int choice ,sno;     printf("1.修改学生的姓名:\n");     printf("2.修改学生的数学成绩:\n");     printf("0.退出:\n");     printf("请输入你的选择:\n");     scanf("%d",&choice);     switch(choice)     {         case 1:              {                   printf("请输入要修改第几位学生的学号:\n");                   scanf("%d",&sno);                   printf("请输入修改后学生的姓名:\n");                   scanf("%s",&Student[sno-1].name);                    printf("修改成功!\n");                    break;              }         case 2:              {                   printf("请输入要修改学生的学号:\n");                   scanf("%d",&sno);                   for(count =0; count <SIZE; count++)                   {                       if(Student[count].num ==sno)                           break;                   }                   printf("请输入修改后的数学成绩:");                   scanf("%f",&Student[count].score.math);                   printf("修改成功!\n");                                  }         default :                 break;     }   }void SearchStudent(){     int sign=0,count;     int  choice,sno;     for(count=0 ;count <SIZE; count ++)     {        if(Student[count].num !=0)        {            sign++;        }     }     if(sign ==0)     {        printf("没有存储任何学生信息!\n");        return ;      }          printf("1.根据学号查询学生信息:\n");     printf("2.查询全部学生信息\n");     printf("0.退出.\n");     printf("请输入功能选择:\n");     scanf("%d",&choice);     if(choice ==0)     {         return;     }     else if(choice ==1)     {          printf("请输入学生学号:\n");          scanf("%d",&sno);          for(count =0; count <SIZE; count++)          {               if(Student[count].num ==sno)                   break;          }          printf("学号   姓名   性别     地址     数学成绩   语文成绩    英语成绩\n");          printf("%-8d",Student[count].num);          printf("%-8s",Student[count].name);          printf("%-8s",Student[count].sex);          printf("%-8s",Student[count].adr);          printf("%-12.2f",Student[count].score.math);          printf("%-12.2f",Student[count].score.chinese);          printf("%-12.2f",Student[count].score.english);          printf("\n");                           }     else if(choice ==2)     {                    printf("学号   姓名   性别     地址     数学成绩   语文成绩    英语成绩\n");          int count;          for(count =0; count <SIZE; count++)          {              if(Student[count].num !=0)              {                  printf("%-8d",Student[count].num);                  printf("%-8s",Student[count].name);                  printf("%-8s",Student[count].sex);                  printf("%-8s",Student[count].adr);                  printf("%-12.2f",Student[count].score.math);                  printf("%-12.2f",Student[count].score.chinese);                  printf("%-12.2f",Student[count].score.english);                  printf("\n");               }          }     }     else         return;     }void SortStudent(){    printf("1.根据学号进行排序:\n");    printf("2.根据学生总成绩排序:\n");    printf("0.退出:\n");    printf("请输入功能选择:\n");    int  count ,choice ,j;    struct STUDENT temp;    scanf("%d",&choice);    if(choice ==0)    {        return;    }    else if(choice ==1)    {         int sign =0;         for(count=0 ;count <SIZE; count ++)         {            if(Student[count].num !=0)            {                sign++;            }         }         if(sign ==0)         {            printf("没有存储任何学生信息!\n");            return ;          }         for(count =0; count <SIZE-1; count ++)         {             for(j=0; j< SIZE-1-count; j++)             {                 if(Student[j].num > Student[j+1].num)                 {                     temp =Student[j];                     Student[j] =Student[j+1];                     Student[j+1] =temp;                                      }             }         }         printf("排序成功!\n");         printf("学号   姓名   性别     地址     数学成绩   语文成绩    英语成绩\n");         for(count =0; count <SIZE ;count ++)         {             if(Student[count].num !=0)             {                  printf("%-8d",Student[count].num);                  printf("%-8s",Student[count].name);                  printf("%-8s",Student[count].sex);                  printf("%-8s",Student[count].adr);                  printf("%-12.2f",Student[count].score.math);                  printf("%-12.2f",Student[count].score.chinese);                  printf("%-12.2f",Student[count].score.english);                  printf("\n");              }         }             }    else if(choice ==2)    {         int sign=0;         for(count=0 ;count <SIZE ;count ++)         {            if(Student[count].num !=0)            {                sign++;            }         }         if(sign ==0)         {            printf("没有存储任何学生信息!\n");            return ;          }         for(j =0; j <SIZE -1;j ++)         {             for(count =0; count <SIZE-1-j ;count ++)             {                 if((Student[count].score.math+Student[count].score.chinese+Student[count].score.english)                      >(Student[count+1].score.math+Student[count+1].score.chinese+Student[count+1].score.english))                                       {                     temp =Student[count];                     Student[count] =Student[count+1];                     Student[count+1] =temp;                                      }             }         }         printf("排序成功!\n");         printf("学号   姓名   性别     地址     数学成绩   语文成绩    英语成绩\n");         for(count =0; count <SIZE ;count ++)         {             if(Student[count].num !=0)             {                  printf("%-8d",Student[count].num);                  printf("%-8s",Student[count].name);                  printf("%-8s",Student[count].sex);                  printf("%-8s",Student[count].adr);                  printf("%-12.2f",Student[count].score.math);                  printf("%-12.2f",Student[count].score.chinese);                  printf("%-12.2f",Student[count].score.english);                  printf("\n");              }         }    }    else        return;     } int main(int argc, char *argv[]){      int flag;      printf("**学生信息管理系统**\n");      while(1)      {          printf("1.输入学生信息:\n");          printf("2.删除学生信息:\n");          printf("3.修改学生信息:\n");          printf("4.查询学生信息:\n");          printf("5.排列学生信息:\n");          printf("0.退出管理系统:\n");          printf("请输入你的选择:\n");          printf("\n");          scanf("%d",&flag);          switch(flag)          {              case SYSEXIT:                   {                        return;                                           }              case INPUTSTUDENT:                   {                        InputStudent();                        break;                   }              case DELETESTUDENT:                   {                        DeleteStudent();                        break;                    }              case UPDATESTUDENT:                   {                        UodateStudent();                        break;                   }              case SEARCHSTUDENT:                    {                        SearchStudent();                        break;                    }              case SORTSTUDENT:                    {                        SortStudent();                        break;                    }              default :                    {                        printf("输入错误!\n\n");                    }          }          printf("\n");                }      system("PAUSE");       return 0;}


 

原创粉丝点击