C++编程实例学生成绩排名系统(一)

2014-07-19 22:52:07 · 作者: · 浏览: 422

  //文件读取需要自己在电脑中添加相应的文件名称

  #include

  #include

  #include

  #include

  #include

  using namespace std;

  void showmeanu();

  void add(struct student *a,int *n); //添加函数

  void del(struct student *a,int *n); //删除函数

  void change(struct student *a,int n); //修改函数

  void search1(struct student *a,int n); //查询单个函数

  void allrank(struct student *a,int n); //排序所有信息

  void printfall(struct student *a,int n); //打印所有信息

  void printf1(struct student *a,int n); //打印单个信息

  void mutirank(struct student *a,int n); //多重排名函数

  void ffprintf(struct student *a,int n); //写入函数

  void fail(struct student *a,int n);

  struct student

  {

  char number[15];

  char name [15];

  int c;

  int math;

  int gym;

  int all;

  int english;

  };

  int main()

  {

  struct student a[50];

  int n=0,i=0;

  char m;

  int flag=0;

  printf(" 欢迎来到学生成绩排名系统\n");

  printf(" 请选择你要执行的项目\n");

  FILE *fp;

  fp=fopen("H:\\student.txt","r");

  if(fp==NULL)

  {

  printf("文件读取失败\n");

  exit(1);

  }

  int k;

  i=0;

  while(( fscanf(fp,"%d%s%s%d%d%d%d%d",&k,a[i].number,a[i].name,&a[i].c,&a[i].math,&a[i].english,&a[i].gym,&a[i].all))!=EOF)

  i++;

  fclose(fp);

  n=i;

  while(1)

  {

  system("cls");

  showmeanu();

  m=getch();

  switch(m)

  {

  case '1':

  add(a,&n);

  break;

  case '2':

  if(n==0)

  {

  printf("亲,还没有联系人呢,按1添加联系人\n");

  break;

  }

  change(a,n);

  break;

  case '3':

  if(n==0)

  {

  printf("亲,还没有联系人呢,按1添加联系人\n");

  break;

  }

  del(a,&n);

  break;

  case '4':

  if(n==0)

  {

  printf("亲,还没有联系人呢,按1添加联系人\n");

  break;

  }

  search1(a,n);

  printf("\n");

  break;

  case '5':

  if(n==0)

  {

  printf("亲,还没有联系人呢,按1添加联系人\n");

  break;

  }

  printfall(a,n);

  char k;

  printf("按任意键返回……………………\n");

  k=getch();

  break;

  case '6':

  if(n==0)

  {