Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2349158
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 17:59:24

接上:
char buf[BUFLEN];
FILE *fp;
struct record s;
system("CLS");
printf("Please input the students marks record file's name: ");
scanf("%s",stuf);
if((fp=fopen(stuf,"r"))==NULL)
{
   printf("The file %s doesn't exit, do you want to creat it? (Y/N) ",stuf);
   getchar();
   c=getchar();
   if(c=='Y'||c=='y')
   {
    fp=fopen(stuf,"w");
    printf("Please input the record number you want to write to the file: ");
    scanf("%d",&n);
    for(i=0;i    {
     printf("Input the student's name: ");
     scanf("%s",&s.name);
     printf("Input the student's code: ");
     scanf("%s",&s.code);
     for(j=0;j     {
      printf("Input the %s mark: ",schoolwork[j]);
      scanf("%d",&s.marks[j]);
     }
     writerecord(fp,&s);
    }
    fclose(fp);
   }
}
fclose(fp);
getchar();
puts("Now you can input a command to manage the records.");
puts("m : mean of the marks.");
puts("t : total of the marks.");
puts("n : search record by student's name.");
puts("c : search record by student's code.");
puts("l : list all the records.");
puts("s : sort and list the records by the total.");
puts("q : quit!");
while(1)
{
   puts("Please input command:");
   scanf(" %c",&c);   /* 输入选择命令 */
   if(c=='q'||c=='Q')
   {
    puts("\n Thank you for your using.");
    break;   /* q,结束程序运行 */
   }
   switch(c)
   {
    case 'm': /* 计算平均分 */
    case 'M':
     if((n=totalmark(stuf))==0)
     {
      puts("Error!");
      break;
     }
     printf("\n");
     for(i=0;i      printf("%-15s's average is: %.2f.\n",schoolwork[i],(float)total[i]/n);
     break;
    case 't': /* 计算总分 */
    case 'T':
     if((n=totalmark(stuf))==0)
     {
      puts("Error!");
      break;
     }
     printf("\n");
     for(i=0;i      printf("%-15s's total mark is: %d.\n",schoolwork[i],total[i]);
     break;
    case 'n': /* 按学生的姓名寻找记录 */
    case 'N':
     printf("Please input the student's name you want to search: ");
     scanf("%s",buf);
     retrievebyn(stuf,buf);
     break;
    case 'c': /* 按学生的学号寻找记录 */
    case 'C':
     printf("Please input the student's code you want to search: ");
     scanf("%s",buf);
     retrievebyc(stuf,buf);
     break;
    case 'l': /* 列出所有学生记录 */
    case 'L':
     liststu(stuf);
     break;
    case 's': /* 按总分从高到低排列显示 */
    case 'S':
     if((head=makelist(stuf))!=NULL)
      displaylist(head);
     break;
    default: break;
   }
}
}
那是计算了所有学生单科的平均分和单科总分,以及总分的排序
问题:某班有20名学生,本学期进行了8门课的考试,现在要对考试成绩进行处理:
    (1)从键盘上输入学生的学号、姓名、每门课程的成绩;
 (2)计算每名学生的平均分;
    (3)输出原始成绩单;
(4)输出按平均分由高到低排列的成绩单。

--------------------next---------------------

阅读(7600) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~