回 帖 发 新 帖 刷新版面

主题:各位大哥,大姐,帮我改一下程序,行不?

#include <conio.h>
#include <graphics.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <dos.h>
#define  N  10
#define  PAGE 2
#define  PRINT1  printf("\n   姓名    性别    年龄    系别    专业    班级\n")
#define  PRINT2  printf("\n %6s%8s%8d%8s%8s%8d",student[i].name,student[i].sex,student[i].age,student[i].department,student[i].profession,student[i].classes)
#define  PRINT3  printf("\n   学号    职务    成                 绩    出生日期    地址    电话\n")
#define  PRINT4  printf("\n %6d%6s%4d%2d%2d%2d%2d-%2d-%8d%6s%8d\n",student[i].num,student[i].plants,student[i].exam.chinese,student[i].exam.math,student[i].exam.english,aver[i],student[i].birthday.year,student[i].birthday.month,student[i].birthday.date,student[i].add,student[i].telephone)
int sum;
float aver[20];              /*记录学生的人数*/
struct data
{ int year;
  int month;
  int date;
};
struct score
{ int chinese;
  int math;
  int english;

};

struct student_type
{ char name[20];

  char sex[10];
  int age;
  char department[20]; /*系别*/
  char profession[20]; /*专业*/
  int classes;
  int num;
  char plants[20];
  struct score exam;
  struct data birthday;
  char add[20];
  double telephone;
}student[N];


/*保存信息*/
save_message(int sum)
{ FILE *fp;
  int i;
  if((fp=fopen("student.txt"," wb"))==NULL)
  { printf("读信息错误!\n");
    return;
  }
  for(i=0;i<=sum;i++)
   if(fwrite(&student[i],sizeof(struct student_type),1,fp)!=1)
     printf("写信息错误!\n");
fclose(fp);
}


/*输入信息*/
input_message()
{ int i=0;
  char choice;
  int flag;
aver[i]=(float)(student[i].exam.chinese+student[i].exam.math+student[i].exam.english)/3.0;
  window(1,1,80,25);
  clrscr();
  printf("\n\n           输入学生信息(最多为 %d个) \n",N);
  printf("           _________________________________");
  do
  {
    printf("\n                   第%d个的学生信息",i+1 );
    printf("\n               学生姓名:");
    scanf ("%s",student[i].name);
    printf("               学生性别:");
    scanf ("%s",student[i].sex);
    printf("               学生年龄:");
    scanf ("%d",&student[i].age);
    printf("               学生系别:");
    scanf ("%s",&student[i].department);
    printf("               学生专业:");
    scanf ("%s",&student[i].profession);
    printf("               学生班级:");
    scanf ("%d",&student[i].classes);
    printf("               学生学号:");
    scanf ("%d",&student[i].num);
    printf("               学生职务:");
    scanf ("%s",&student[i].plants);
    printf("               学生成绩:");
    printf("语文:");
    scanf ("%d",&student[i].exam.chinese);
    printf("     数学:");
    scanf ("%d",&student[i].exam.math);
    printf("     英语:");
    scanf ("%d",&student[i].exam.english);
    printf("   平均成绩:%f",aver);
    printf("               出生日期(yyyy-mm-dd): ");
    scanf("%d-%d-%d",&student[i].birthday.year,&student[i].birthday.month,&student[i].birthday.date);
    printf("               家庭地址: ");
    scanf("%s",student[i].add);
    printf("               学生电话:");
    scanf ("%d",&student[i].telephone);
    printf("\n您还想继续吗?(Y/N) ");
    choice=getch();
    if(choice=='y'||choice=='Y')
    { printf("\n                  继续!\n");
      clrscr();
      i++;
      flag=1;

    }
    else flag=0;
  }while(flag==1);
  printf("\n                 第%d 个学生的信息已经输入完毕!\n",i+1 );
  sum=i+1;
  printf("\n                  按任意键返回主菜单!");
  bioskey(0);
}


/*读取信息*/
read_message()
{ FILE *fp;
  int i=0;
window(1,1,80,25);
  if((fp=fopen("student.txt","rb"))==NULL)
  { printf("\n\n                *****现在,还没有任何学生的信息, 按任意键返回主菜单!*****\n");
    return 0;
  }
  while(feof(fp)!=1)
  { fread(&student[i],sizeof(struct student_type),1,fp);
    if(student[i].num==0)   break;
    else i++;
  }
  fclose(fp);
  return(i);
}
output_message()
{ int i=0,page=1;
  int j=0;
  window(1,1,80,25);
  clrscr();
  printf("\n\n       ----学生管理信息----      第%d页\n\n", page);
  printf("     ---------------------------------");
do
  { if(student[i].num!=0)
    { j++;
      if(j%PAGE!=0)
      { PRINT1;
        PRINT2;
        PRINT3;
        PRINT4;
      }
    else
    { PRINT1;
      PRINT2;
      PRINT3;
      PRINT4;
      if(student[i+1].num!=0)
      { printf("按任意键继续!");
        bioskey(0);
        clrscr();
        printf("\n\n    --学生管理信息--   第%d页\n\n ",++page);
        printf("  ----------------------------");
        PRINT1;
      }
      }
    }
    i++;
   }while(student[i].num!=0);
   printf("按任意键退出!");
   bioskey(0);
}
insert_message()
{ int i=sum;
  int flag=0;
  char choice;
  aver[i]=(float)(student[i].exam.chinese+student[i].exam.math+student[i].exam.english)/3.0;
  clrscr();
  printf("\n\n                           插入学生信息\n");
do
  { student[i].num=++sum;
    printf("\n                 新生学号: %d ",student[i].num);
    printf("\n                 姓名:");
    scanf ("%s",&student[i].name);
    printf("\n                 性别:");
    scanf ("%s",&student[i].sex);
    printf("\n                 年龄:");
    scanf ("%d",&student[i].age);
    printf("\n                 系别:");
    scanf ("%s",&student[i].department);
    printf("\n                 专业:");
    scanf ("%s",&student[i].profession);
    printf("\n                 班级:");
    scanf ("%d",&student[i].classes);
    printf("\n                 学号:");
    scanf ("%d",&student[i].num);
    printf("\n                 职务:");
    scanf ("%s",&student[i].plants);
    printf("\n                 学生成绩:");
    printf("语文:");
    scanf ("%d",&student[i].exam.chinese);
    printf("      数学:");
    scanf ("%d",&student[i].exam.math);
    printf("      英语:");
    scanf ("%d",&student[i].exam.english);
    printf("\n                 平均成绩:%f",aver);
    printf("\n                 出生日期(yyyy-mm-dd):");
    scanf ("%d-%d-%d",&student[i].birthday.year,&student[i].birthday.month,&student[i].birthday.date);
    printf("\n                 电话:");
    scanf ("%d", &student[i].telephone);
    printf("\n                 地址:");
    scanf ("%s",student[i].add);
    printf("\n                您还想继续吗?(Y/N)");
    choice=getch();
    if(choice=='y'||choice=='Y')
    { printf("\n        继续!\n");
      i++;
      flag=1;
    }
    else  flag=0;
   }while(flag==1);
   printf("\n                  按任意键退出!");
   bioskey(0);
}


回复列表 (共3个回复)

沙发

一个放不下:


/**删除信息**/
  del_message()
  {  int i=0,j=0,k;
     char del_name[20];
     printf("\n 输入您想删除的学生姓名:");
     scanf("%s",del_name);
     for(i=0;i<sum;i++)
     { if(strcmp(student[i].name,del_name)==0&&student[i].num!=0)
    for(k=i;k<sum-1;k++)
      student[k]=student[k+1];
      else  j++;
     }
      if(j==sum)
      { printf("\n  没有此学生的信息!");
    printf("\n   按任意键退出!");
    return;
      }
   sum=i;
   bioskey(0);
  }


/*修改信息*/
revise_message()
{ int i=0,choice,flag;
   char  revise_name[20];
   aver[i]=(float)(student[i].exam.chinese+student[i].exam.math+student[i].exam.english)/3.0;
   do
   { clrscr();
     printf("\n                     输入您想修改的学生姓名:");
     scanf("%s",revise_name);
     for(i=0;i<sum;i++)
     {    if(strcmp(student[i].name,revise_name)==0&&student[i].num!=0)
      { printf("\n                      ----学生管理信息----\n");
        PRINT1;
        PRINT2;
        PRINT3;
        PRINT4;
         printf("\n                      您想修改哪项?\n");
         printf("\n                      1.姓名");
         printf("\n                      2.性别");
         printf("\n                      3.年龄");
         printf("\n                      4.系别");
         printf("\n                      5.专业");
         printf("\n                      6.班级");
         printf("\n                      7.学号");
         printf("\n                      8.职务");
         printf("\n                      9.成绩");
         printf("\n                      0.出生日期");
         printf("\n                        选择(0-9):");
         scanf("%d",&choice);
         switch(choice)
         {  case  1: printf("\n                   输入修改后的姓名:");
                 scanf("%s",student[i].name);break;
            case  2: printf("\n                   输入修改后的性别:");
                 scanf("%s",&student[i].sex);break;
            case  3: printf("\n                   输入修改后的年龄:");
                 scanf("%d",&student[i].age);break;
            case  4: printf("\n                   输入修改后的系别:");
                 scanf("%s",&student[i].department);break;
            case  5: printf("\n                   输入修改后的专业:");
                 scanf("%s",&student[i].profession);break;
            case  6: printf("\n                   输入修改后的班级:");
                 scanf("%d",&student[i].classes);break;
            case  7: printf("\n                   输入修改后的学号:");
                 scanf("%d",&student[i].num);break;
            case  8: printf("\n                   输入修改后的职务:");
                 scanf("%s",&student[i].plants);break;


            case  9: printf("\n                   输入修改后的成绩:");
                     printf("\n                     语文:");
                 scanf ("%d",&student[i].exam.chinese);
                     printf("                       数学:");
                 scanf ("%d",&student[i].exam.math);
                     printf("                       英语:");
                 scanf ("%d",&student[i].exam.english);
                     printf("\n                     平均成绩:%f",aver);break;
            case  0: printf("\n                   输入修改后的出生日期:");
                 scanf("%d-%d-%d",&student[i].birthday.year,&student[i].birthday.month,&student[i].birthday.date); break;
         }
        printf("\n           信息已修改!");
        PRINT1;
        PRINT2;
        PRINT3;
        PRINT4;
        break;
      }
    }
     if(i==sum)
      { printf("\n                 无此学生的信息!");
        bioskey(0);
      }
      printf("\n\n                     您还想继续修改吗 ?(Y/N) ");
      choice=getch();
      if(choice=='y'||choice=='Y')
      {  flag=1;
       printf("\n                继续!\n");
      }
     else  flag=0;
   }while(flag==1);
    printf("\n                          按任意键退出!");
    bioskey(0);
}
renew_message()
{ int choice;
   do
   {
      window(1,1,80,25);
      clrscr();
      printf("\n\n\n         *****更新学生信息*****\n\n");
      printf("\n                 1.插入信息\n\n");
      printf("\n                 2.删除信息\n\n");
      printf("\n                 3.修改信息\n\n");
      printf("\n                 4.退出\n\n");
      printf("\n                  选择 (1-4):");
      scanf("%d",&choice);
      switch(choice)
      { case  1: insert_message();break;
        case  2: del_message();break;
        case  3: revise_message();break;
        case  4: break;
      }
   }while(choice!=4);
}
inquire_name()
{ int i,j=0;
   char ch;
   char inquire_name[20];
ll:  clrscr();
   printf("\n           输入您想查询的学生姓名: ");
   scanf("%s",inquire_name);
   for(i=0;i<sum;i++)
   { if(strcmp(student[i].name,inquire_name)==0&&student[i].num!=0)
     { printf("\n                  ---------学生管理信息---------\n");
       PRINT1;
       PRINT2;
       PRINT3;
       PRINT4;
     }
     else  j++;
       if(j==sum)
      printf("\n                  无此学生信息 !");
     bioskey(0);
  }
   printf("\n 您还想继续吗?(Y/N)");
   scanf("%c",&ch);
   if(ch=='y'||ch=='Y')
    { j=1; goto ll;}
}
inquire_num()
{
    int i,j=0;
    char ch;
    int inquire_num;
  ll:  clrscr();
    printf("\n          输入您想查询的学生学号: ");
    scanf("%d",&inquire_num);
    for(i=0;i<sum;i++)
    { if(student[i].num==inquire_num&&student[i].num!=0)
      { printf("\n\n              学生管理信息");
    PRINT1;
    PRINT2;
    PRINT3;
    PRINT4;
      }
     else j++;
       if(j==sum)
       {printf("\n                        无此学生信息!");
    bioskey(0);
       }
   }
    printf("\n您还想继续吗?(y/Y)");
    scanf("%c",&ch);
    if(ch=='y'||ch=='Y') {j=1; goto ll;}
}

板凳

还有:

inquire_message()
{ int choice;
  window(1,1,80,25);
  do
  { clrscr();
    printf("\n\n\n                     ****查询学生信息****\n\n");
    printf("                   1.查询姓名\n\n");
    printf("                   2.查询学号\n\n");
    printf("                   3.退出\n\n  ");
    printf("               选择(1-3):");
    scanf("%d",&choice);
    switch(choice)
    { case  1: inquire_name();break;
      case  2: inquire_num();break;
      case  3:  break;
    }
  }while(choice!=3);
}

sort_num()
{ struct student_type t;
   int i,j,k;
   clrscr();
   printf("\n                        按学号排序\n");
   printf("\n序号      姓名     学号     年龄\n");
   for(i=0;i<sum;i++)
   { k=i;
     for(j=1;j<=sum;j++)
       if(student[k].num<student[j].num)  k=j;
     if(k!=i)
     { t=student[i]; student[i]=student[k]; student[k]=t;
     }
   }
  for(i=0;i<=sum;i++)
   printf("\n%6d%6s%6d%6d",i+1,student[i].name,student[i].num,student[i].age);
  bioskey(0);
}

sort_aver()
{ struct student_type t;
   int i,j,k;
   clrscr();
   printf("\n                        -----按平均成绩排序-----\n");
   printf("\n序号     平均成绩       姓名      年龄\n");
   for(i=0;i<sum;i++)
   { k=i;
     for(j=1;j<=sum;j++)
       if(aver[k]<aver[j])  k=j;
     if(k!=i)
     { t=student[i]; student[i]=student[k]; student[k]=t; }
   }
   for(i=0;i<=sum;i++)
     printf("\n%6d%6s%6d%6d",i+1,student[i].name,aver,student[i].num,student[i].age);
   bioskey(0);
}
sort_message()
{ int choice;
   window(1,1,80,25);
   do
   { clrscr();
     printf("\n\n\n              *****学生排序信息*****\n\n");
     printf("\n                  1. 按学号排序\n\n");
     printf("\n                  2. 按平均成绩排序\n\n");
     printf("\n                  0.  退出\n\n");
     printf("\n                  选择(0-2): ");
     scanf("%d",&choice);
     switch(choice)
     { case  1:  sort_num();break;
       case  2:  sort_aver();break;
       case  0:  break;
     }
   }while(choice!=0);
}
main()
{  int choice;
   sum=read_message();
   bioskey(0);
   do
   { window(1,1,80,25);
     textbackground(LIGHTGREEN);
     textcolor(BLUE);
     clrscr();
     gotoxy(19,0);
     window(60,3,75,5);
     textbackground(LIGHTBLUE);
     textcolor(YELLOW);
     clrscr();
     gotoxy(61,3);
     cputs("# 欢迎进入学生信息管理!");
     getch();
     printf("\n\n\n              *****学生管理信息 *****\n\n");
     printf("              1.录入学生信息\n\n");
     printf("              2.打印学生信息\n\n");
     printf("              3.更新学生信息\n\n");
     printf("              4.查询学生信息\n\n");
     printf("              5.分类学生信息\n\n");
     printf("              6.退出系统\n\n");
     printf("              7.请选择(1-6) :");
     scanf("%d",&choice);
     switch(choice)
     { case  1: input_message();break;
       case  2: output_message();break;
       case  3: renew_message();break;
       case  4: inquire_message();break;
       case  5: sort_message();break;
       case  6: break;
     }
   }while(choice!=6);
   save_message(sum);
   printf("\n-学生信息已保存! -(文件名:student.txt)\n ");

}

3 楼

我的油箱是banboo3@163.com

我来回复

您尚未登录,请登录后再回复。点此登录或注册