c语言综合实验 学生成绩管理系统

#include
#include
#include
#define num 100
int student_number=0;
 struct info{
char number[10];
 char name[10];
 char sex;
    int english;
    int math;
    int chinese;
  float sum;
 float score;
};
void input(struct info *);
void alter(struct info *);
void output(struct info *);
void add(struct info *);
void cal(struct info *);
void del(struct info *);
void seek(struct info *);
void sort(struct info *);
void main(void)
{
 int i,k,choice;
  struct info stu[num];
  while(1){
 
 printf("               学生成绩管理系统\n");
 printf("1.创建学生的资料             2.添加学生的资料\n");
 printf ("3.删除学生的成绩            4.修改学生的资料\n");
 printf("5.按平均分排序               6.输出当前学生信息\n");
 printf("7.搜索学生的资料              8.退出\n");
 printf("*************欢迎进入学生成绩管理系统***********************\n输入你的选择\n");
 
 scanf("%d",&choice);
  switch(choice)
  {
   case 1:{
   system("cls");
   input(stu);
   cal(stu);
   break;
   }
   case 2:{
    
   system("cls");
   add(stu);
   cal(stu);
   break;}
   case 3:{
   
   system("cls");
   del(stu);
   break;}
   case 4:{
    alter(stu);
    break;
   }
   case 5:{
   
   system("cls");
   sort(stu);
   break;}
  
   case 6:{system("cls");
   output(stu);
    break;
   }
      case 7:{system("cls");
      cal(stu);
   seek(stu);
    break;
   }
   case 8:
            exit(0);
        default:
            printf("error!input again\n");
  }
 }  
}
void input(struct info *p)
{
 int i;
 printf("输入学生人数:");
 scanf("%d",&student_number);
 for(i=0;i  printf("第%d个学生:",i+1);
 printf("Please enter the number :");
     scanf("%s",&p[i].number);
     while(getchar()!='\n')
  continue;
 printf("Please enter the name:");
 gets(p[i].name);
 printf(" sex:");
scanf("%c",&p[i].sex);
 printf("english,math,chinese:");
 scanf("%d%d%d",&p[i].english,&p[i].math,&p[i].chinese);}
}
void sort(struct info *p)
{
 int i,j;
 struct info temp;
 for(i=0;i  {
  for(j=i+1;j   if(p[i].score   {temp=p[i];
 p[i]=p[j];
  p[j]=temp;
  } 
 }for(i=0;i   printf("%s 平均分:%.2f\n",p[i].name,p[i].score);
}
void seek(struct info *stu)
{
 int i,k;
 char s[20]={0};
 printf("please input the name or number:\n");
 scanf("%s",s);
 while(1){
 for(i=0,k=0;i  {
  if((!(strcmp(s,stu[i].name)))||(!(strcmp(s,stu[i].number))))
 {
 printf(" 学号 姓名 性别 英语 数学 语文 平均 总分\n ");
 printf("%s %2s %2c %4d %4d %6d %4.2f %4.2f\n",stu[i].number,stu[i].name,stu[i].sex,stu[i].english,stu[i].math,stu[i].chinese,stu[i].sum,stu[i].score);
k=1;}}
if(k==0)
 printf("NO FIND\n");
 printf("please input the name or number(q to quit):\n");
 scanf("%s",s);
 if(s[0]=='q'&&s[1]=='\0')
 break;
}
}
void add(struct info *stu)
{
    int i,k=1;
    while(1)
    {
        if(k==1)
        {
            student_number++;
            i=student_number;
            printf("input number:");
            scanf("%s",&stu[i-1].number);
            getchar();
            printf("name: ");
            scanf("%s",&stu[i-1].name);
            getchar();
            printf("sex(m or f): ");
            scanf("%c",&stu[i-1].sex);
            printf("english,math,chinese:");
            scanf("%d%d%d",&stu[i-1].english,&stu[i-1].math,&stu[i-1].chinese);
       
         
          
        }
        else if(k==2)
            break;
        else
            printf("Error! Please input again.\n");
        printf("Do you want to add again? If yes, press 1, if not, press 2.\n");
        scanf("%d",&k);
    }
}
void alter(struct info *stu)
{
    int i,k,t=0,m;
    char p[10];
    while(1)
    {
        printf("1.alter           2.quit: \n");
        scanf("%d",&k);
        if(k==1)
        {
            printf("please input the name or number: ");
            scanf("%s",p);
            for(i=0; i             {
                if((!(strcmp(p,stu[i].name)))||(!(strcmp(p,stu[i].number))))
                {
                    printf("你要修改的学生为: %s\n",stu[i].name);
                    while(1)
                    {
                        printf("1,修改高数成绩 \t");
                        printf("2,修改语文成绩 \n");
                        printf("3,修改英语成绩 \t");
                        printf("4,quit \n");
                        scanf("%d",&m);
                        switch(m)
                        {
                        case 1:
                        {
                            printf("请输入修改后的高数成绩:\n");
                            scanf("%d",&stu[i].math);
                            break;
                        }
                        case 2:
                        {
                            printf("请输入修改后的语文成绩:\n");
                            scanf("%d",&stu[i].chinese);
                            break;
                        }
                        case 3:
                        {
                            printf("请输入修改后的英语成绩:\n");
                            scanf("%d",&stu[i].english);
                            break;
                        }
                        default:
                            break;
                        }
                        if(m==4)
                            break;
                    }
                    break;
                }
                else
                    t++;
            }
            if(t==student_number)
                printf("NO FIND\n");
        }
        else if(k==2)
            break;
        else
            printf("Error, please input again.\n");
    }
}
void del(struct info *stu)
{
    int i,k,t=0,m,j;
    m=student_number;
    char p[10];
    while(1)
    {
        printf("1.delete               2.quit \nenter you choice:");
        scanf("%d",&k);
        if(k==1)
        {
            printf("please input the name or number: ");
            scanf("%s",p);
            for(i=0; i             {
                if((!(strcmp(p,stu[i].name)))||(!(strcmp(p,stu[i].number))))
                {for(j=i;j                     stu[j]=stu[j+1];
                    student_number--;
                    printf("done!\n");
                    break;
                }
                else
                    t++;
            }
            if(t==m)
                printf("NO FIND\n");
        }
        else if(k==2)
            break;
        else
            printf("Error, please input again.\n");
    }
}
void output(struct info *stu)
{
    int i;
    if(student_number!=0)
    {
            printf(" 学号 姓名 性别  英语 数学 语文 总分 平均\n ");
            for(i=0; i            
 printf("%s%5s%5c%5d%5d%4d %4.2f% 4.2f\n",stu[i].number,stu[i].name,stu[i].sex,stu[i].english,stu[i].math,stu[i].chinese,stu[i].sum,stu[i].score);
       
    }
    else
        printf("no find!\n");
}
void cal(struct info *stu){
 int i;
 for(i=0;i  {
 stu[i].sum=(float)(stu[i].english+stu[i].math+stu[i].chinese);
 stu[i].score=stu[i].sum/3.0;}
 
}

你可能感兴趣的:(c语言综合实验 学生成绩管理系统)