c语言成绩管理

来源:互联网 发布:nba球队数据统计排名 编辑:程序博客网 时间:2024/04/25 19:12

#include <stdio.h>
#include <conio.h>
#include <string.h>
#define N 100


void openfile();
void savefile();
void editmenu();
void findmenu();
void  mysort();
void mystat();
void mystat();
void mymodify();
void mainmenu();
void myremov();
void someonerec();
void input();
void so();
struct student
{ char num[12];
  float score[5];
  char name[30];
  float avg;
};
struct student stu[100];
int n=0;
void input()
{
  int i=n; float temp1,temp2,temp3,temp4,temp5;
  char ch='y';
  while(ch=='y')
  {
     printf("/nPlease input the name and number:");
     scanf("%s%s",stu[i].name,stu[i].num);
     printf("Input the 5 score:");
     scanf("%f%f%f%f%f",&temp1,&temp2,&temp3,&temp4,&temp5);
     stu[i].score[0]=temp1;
     stu[i].score[1]=temp2;
     stu[i].score[2]=temp3;
     stu[i].score[3]=temp4;
     stu[i].score[4]=temp5;
     stu[i].avg=( stu[i].score[0]+ stu[i].score[1]+ stu[i].score[2]+ stu[i].score[3]+ stu[i].score[4])/5;
     printf("continue or not(y/n)?");
     scanf(" %c",&ch);
     i++;
     }

     n=i;
     printf("/nname  number  English  Mathmatic  Chinese  C program  Jisuanji  Final/n");
     for(i=0;i<n;i++)
     printf("%s     %s       %-10.1f%-10.1f%-10.1f%-10.1f%-10.1f%-10.1f/n",stu[i].name,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4], stu[i].avg);
      printf("/n             press any key to continue....");
 getch();
       }

 

void main( )
{ char choose='/0';

 do
 { mainmenu();
  scanf(" %c",&choose);
  switch(choose)
  {   case '1':  openfile(); break;
   case '2':  savefile(); break;
   case '3':  editmenu(); break;
   case '4':  findmenu(); break;
             case '5':  mysort();    break;
   case '6':  mystat();    break;
   case '0':  exit(0);
       default:   printf(" Input error.Please again.");
    }
 }while(1);
}

void mainmenu()  
{
 clrscr();
     printf("/n/n/n/n/n/n/n/n");     
 printf("        |******Student Grade Management System******|/n");
  printf("        |-------------------------------------------|/n");
  printf("        |       Please input option(0-9):           |/n");
  printf("        |-------------------------------------------|/n");
 printf("        |        1--Open file                       |/n");
 printf("        |        2--save file                       |/n");
 printf("        |        3--Edit                            |/n");
  printf("        |        4--View                            |/n");
  printf("        |        5--Sort                            |/n");
  printf("        |        6--list of no degree               |/n");
 printf("        |        0--Exit                            |/n");
  printf("        |-------------------------------------------|/n");
}

void editmenu()
{      char choose='/0';
       do
       {
     clrscr();
         printf("/n/n/n/n/n/n/n/n");
  printf("        |-------------------------------------------|/n");
   printf("        |       Please input option(0-3):           |/n");
   printf("        |-------------------------------------------|/n");
   printf("        |        1----Add record                    |/n");
  printf("        |        2----Del record                    |/n");
  printf("        |        3----Modify record                 |/n");
  printf("        |        0----Return mainmenu               |/n");
   printf("        |-------------------------------------------|/n");
          scanf(" %c",&choose);
          switch(choose)
  {  case '1':  input(); break;
      case '2':  myremov(); break;
      case '3':  mymodify(); break;
   case '0':  return;
      default:   printf(" Input error.Please again.");
   }
       }while(1);
}
void openfile()
{
}
void savefile()
{}

void findmenu()
{   char sh='/0';
    do
    {
       clrscr();
       printf("/n/n/n/n/n/n/n/n");
       printf("      |---------------------------------------------|/n");
       printf("      |        Please input option(0-2)             |/n");
       printf("      |---------------------------------------------|/n");
       printf("      |        1----View of whole record            |/n");
       printf("      |        2----View of someone record          |/n");
       printf("      |        0----Return mainmenu                 |/n");
       printf("      |---------------------------------------------|/n");
       scanf("%c",&sh);
       switch(sh)
       {
       case'1': so(); break;
       case'2': someonerec(); break;
       case'0': return;
       default: printf("Input error.please again.");
       }
       }while(1);
}
void  mysort()
{  struct student temp;
   int i,j;
  for(j=0;j<n;j++);
    for(i=0;i<n-j-1;i++)
    if(stu[i].avg<stu[i+1].avg)
  {
      temp=stu[i];
      stu[i]=stu[i+1];
      stu[i+1]=temp;
   }

  printf("Name    Number     English   Chinese   C program    Jisuanji   Final/n");
  for(i=0;i<n;i++)
   printf("%s     %s       %-10.1f%-10.1f%-10.1f%-10.1f%-10.1f%-10.1f/n",stu[i].name,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4], stu[i].avg);
  printf("                press any key continue....");  getch();

}
void mystat()
{     int i,j;  int flag=0;
       printf("             The list of no degree/n");
      printf("Name   number    english   mathmatic   chinese   c program  final/n");
      for(i=0;i<n;i++)
  for(j=0;j<5;j++)
 if(stu[i].score[j]<60)
      {
 flag=1;
 printf("%s     %s       %-10.1f%-10.1f%-10.1f%-10.1f%-10.1f%-10.1f/n",stu[i].name,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4], stu[i].avg);
 break;
      }
      if(flag==1) printf("%-8.s%-8.s",stu[i].name,stu[i].num);
       printf("            press any key to continue....");
      getch();
}
void mymodify()
{   char s='y';char name[30];
    int i=0,flag=0,j=0;
    float k,sum=0;
    while(s=='y')
    {
    printf("input the name of modifing:");
  flag=0;
  scanf("%s",name);
  getch();
  for(i=0;i<n;i++)
  {
       if(strcmp(name,stu[i].name)==0)
       {
       flag=1;
       printf("please input new score:/n");
       for(j=0;j<5;j++)
       {
     scanf("%f",&k);
     stu[i].score[j]=k;
     sum=sum+stu[i].score[j];
     }
     stu[i].avg=sum/5;
     getch();
       printf("name num  socore1 score2 score3  score4  score5  score6/n");
  printf("%s  %s%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f/n",stu[i].name,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4],stu[i].avg);
       }
       }
  if(!flag)
  printf("No this person.");
  printf("Continue to modify(y/n)");
  scanf("%c",&s);
  }
    printf("            press any key to continue..../n");
    getch();
}
void myremov()
{
  char name[30];char h='y';
  int i=0,j=0,flag=0;
  while(h=='y')
  {
  printf("input name of deleting:");
  flag=0;
  scanf("%s",name);
  getch();
  for(i=0;i<n;i++)
  {
    if(strcmp(name,stu[i].name)==0)
    {
    flag=1;
    for(j=i;j<n-1;j++)
    stu[j]=stu[j+1];
    n--;
    for(i=0;i<n;i++)
    printf("%-5s%-6s",stu[i].name,stu[i].num);
       }
     }
     if(!flag)
     printf("/nno person!");
     printf("continue input to (y/n)?");
  scanf("%c",&h);
 }
 printf("              press any key to continue..../n");
 getch();
}
void someonerec()
{
    char name[30];int i;
       printf("/nPlease input name to display:");
       scanf("%s",name);
       for(i=0;i<n;i++)
 {
 if(strcmp(name,stu[i].name)==0)
      { printf("name   num   socore1   score2  score3  score4  score5/n");
  printf("%s  %s%8.1f%8.1f%8.1f%8.1f%8.1f/n",stu[i].name,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4]);
      }
      else
  printf("No this person!/n");
 }
 printf("             press any key continue....");
 getch();
}
void so()
{  int i;
   printf("Name     Number    English    Mathmatic   C promgram    Jisuanji   Final/n");
   for(i=0;i<n;i++)
   printf("%s     %s       %-10.1f%-10.1f%-10.1f%-10.1f%-10.1f%-10.1f/n",stu[i].name,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4], stu[i].avg);
   printf(              "Press any key to contine.....");
   getch();
}

原创粉丝点击