标题:求帮助 报告速度 !!!!
只看楼主
zhoudaqing00
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-7-2
 问题点数:0 回复次数:1 
求帮助 报告速度 !!!!
4、学生成绩管理
完成如下功能:
       1)各种数据的输入操作
       2)能对各数据进行修改操作
       (1)错误的数据修改
       (2)增加学生
       (3)学生减员
       3)数据的处理
         按学生总成绩排序
       4)数据查询
       (1)按姓名查询某个学生的各种数据
       (2)统计每名学生不及格课程门数
      5)数据输出
       (1)输出(按姓名)某个学生的数据
       (2)按班级输出学生的各数据
(3)按学期输出学生的各数据
数据: 专业代码(字符数组/8)、学号(字符数组/4)、姓名(字符数组/8)、考试考察课(字符型/4),学期(字符型/2),成绩:数学、外语、计算机基础、C语言、网页设计、总成绩、平均成绩,均为单精度类型成员,宽度4.1。(“总成绩”、“平均成绩”数据由程序计算得到)
搜索更多相关主题的帖子: 总成绩 课程 统计 姓名 专业 
2013-07-02 12:30
zhoudaqing00
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-7-2
得分:0 
这是自己我编出的程序  但是 后面真的不清楚  怎么将其他条件加入进去#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define  SIZE  100
struct stud_type
{
    char bh[10];
    char name[20];
    char xb[2];
    int  nl;
    int  sx;
    int  yy;
    int  wy;
    int  cyy;
    int  jsj;
    int  zcj;
    int  pjcj;
};
 struct stud_type  arrange,student[SIZE];
 FILE *fp;
 char numstr[20];
 int  n=0;
 void menu();         //菜单
 void shuru();        //输入
 void shuchu();       //输出
 void chazhao();      //查找
 void xiugai();       //修改
 void charu();        //插入
 void shanchu();      //删除
 void tongji();       //统计
 void paixu();        //排序
 void tianjia();      //添加
 int main()
 {
     menu();           //调用菜单
 }        
void menu()
{   
    char choice;
    int k=1;
    while(k)
    {
    system("cls");
    printf("\n");
    printf("\t   ---------------------------------------------------------\n");
    printf("\t   ||  ~~~~~~~~~********学生成绩管理系统********~~~~~~~~  ||\n");
    printf("\t   =========================================================\n");
    printf("\t   ||                                                     ||\n");
    printf("\t   ||         1. 输入信息       2. 输出信息               ||\n");
    printf("\t   ||                                                     ||\n");
    printf("\t   ||         3. 查找信息       4. 修改信息               ||\n");
    printf("\t   ||                                                     ||\n");
    printf("\t   ||         5. 插入信息       6. 删除信息               ||\n");
    printf("\t   ||                                                     ||\n");
    printf("\t   ||         7. 统计、处理     8. 筛选排序               ||\n");
    printf("\t   ||                                                     ||\n");
    printf("\t   ||         9. 添加信息       0. 退出系统               ||\n");
    printf("\t   ||                                                     ||\n");
    printf("\t   =========================================================\n");
    printf("\t   |              请选择以上项目:                          |\n");
    printf("\t   ---------------------------------------------------------\n");
    choice=getchar();getchar();
    switch(choice)
     {
          case'1':shuru(); break;
          case'2':shuchu(); break;
          case'3':chazhao(); break;
          case'4':xiugai(); break;
          case'5':charu(); break;
          case'6':shanchu(); break;
          case'7':tongji(); break;
          case'8':paixu(); break;
          case'9':tianjia(); break;
          case'0':k=0;
    }
    }
}
void shuru()//输入信息
{
    int a,b;
    char ch;
     int n;
    if((fp=fopen("xuesheng.txt","wb"))==NULL)
    {
        printf("不能打开 xuesheng.txt");
        exit(0);
    }
    system("cls");
    printf("\t\t\t请输入学生信息\n");      
    for(n=0;n<=SIZE;)
    {
         printf(" 请输入学号:",n+1);
         gets(student[n].bh);
         printf(" 请输入姓名:",n+1);
         gets(student[n].name);
         printf(" 请输入性别:",n+1);
         gets(student[n].xb);
         printf("请输入数学成绩:");
         gets(numstr);
         student[n].sx=atof(numstr);
         printf("请输入外语成绩:");
         gets(numstr);
         student[n].yy=atof(numstr);
         printf("请输入网页成绩:");
         gets(numstr);
         student[n].wy=atof(numstr);
         printf("请输入c语言成绩:");
         gets(numstr);
         student[n].cyy=atof(numstr);
         printf("请输入计算机基础成绩:");
         gets(numstr);
         student[n].jsj=atof(numstr);
         a=1.0*(student[n].sx+student[n].yy+student[n].wy+student[n].cyy+student[n].jsj)/4;
         student[n].pjcj=a;
         b=(student[n].sx+student[n].yy+student[n].wy+student[n].cyy+student[n].jsj);
         student[n].zcj=b;
         n++;
         printf("是否继续输入(y/n)\n");
         ch=getchar();getchar();
         if(ch=='n')  break;         
    }
    fwrite(student,sizeof(student[0]),n,fp);
    fclose(fp);
}         
void shuchu()//输出信息
 {
     
    n=0;
    if((fp=fopen("xuesheng.txt","rb"))==NULL)
    {
        printf("不能打开 xuesheng.txt");
        exit(0);
    }
    system("cls");
    printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    printf("学号  姓名  性别  数学  外语  网页  c语言  计算机 平均成绩  总成绩 \n");
    printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
     while(fread(&student[n],sizeof(student[n]),1,fp)==1)
      {
        printf("%-7s%-7s%-7s%-7d%-7d%-7d%-7d%-12.2d%-10d\n",
        student[n].bh,student[n].name,student[n].xb,
        student[n].sx,student[n].yy,student[n].wy,
        student[n].cyy,student[n].jsj, student[n].pjcj,student[n].zcj);
        n++;
      }
      getchar();getchar();
         fclose(fp);
 }            
 void chazhao()//查找信息
 {
     int a=0,b,c; char cz; n=0;
     if((fp=fopen("xuesheng.txt","rb"))==NULL)
        {
           printf("不能打开文件\n ");
           exit(0);
        }
     while(fread(&student[n],sizeof(student[n]),1,fp)==1)
     n++;
     a=n;
     printf("\t\t   ---------------------------\n");
     printf("\t\t   || ********查询********* ||\n");
     printf("\t\t   ===========================\n");
     printf("\t\t   ||                       ||\n");
     printf("\t\t   ||    1. 按学号查询      ||\n");
     printf("\t\t   ||                       ||\n");
     printf("\t\t   ||    2. 按姓名查询      ||\n");
     printf("\t\t   ||                       ||\n");
     printf("\t\t   ||    3. 按总成绩查询    ||\n");
     printf("\t\t   ||                       ||\n");
     printf("\t\t   ===========================\n");
     printf("\t\t         按其它数字键退出     \n");
     cz=getchar();getchar();
     switch(cz)
     {
       case '1':
             printf(" 请输入您要查找的学号:\n");
             gets(numstr);
             for(n=0;n<a;)
              {
                if(!strcmp(numstr,student[n].bh)) break;
                 n++;
              }
             break;
         case '2':
             printf("请输入您要查找的姓名\n");
             gets(numstr);
             for(n=0;n<a;)
              {
               if(!strcmp(numstr,student[n].name)) break;
               n++;
              }
             break;
         case '3':
             printf("请输入您要查找的总成绩\n");
             gets(numstr);
             for(n=0;n<a;)
              {
                if(atol(numstr)==student[n].zcj) break;
               n++;
              }
             break;
       }
    printf("--\n");
    printf("%-7s%-7s%-7s%-7d%-7d%-7d%-7d%-12.2d%-10d\n",
    student[n].bh,student[n].name,student[n].xb,
    student[n].sx,student[n].yy,student[n].wy,student[n].cyy,student[n].jsj,
    student[n].pjcj,student[n].zcj);
    getchar();getchar();
    fclose(fp);
 }        
void xiugai()//修改信息
{
    char xg;int i=0;
      printf("如果你想修改必须先找到文件\n");
      chazhao();
     if((fp=fopen("xuesheng.txt","rb+"))==NULL)
      {
       printf("can not open the file.\n ");
       exit(0);
    }
      while(fread(&student[i],sizeof(student[i]),1,fp)==1)
          i++;
          printf("     请选择您要修改的内容:   \n");
        printf(" ============================ \n");
        printf("||   学  号          请按 1 ||\n");
        printf("||   姓  名          请按 2 ||\n");
        printf("||   性  别          请按 3 ||\n");
        printf("||   数  学          请按 4 ||\n");
        printf("||   外  语          请按 5 ||\n");
        printf("||   网  页          请按 6 ||\n");
        printf("||   C 语言          请按 7 ||\n");
        printf("||   计算机          请按 8 ||\n");
        printf("||   退  出          请按 0 ||\n");
        printf("+===========================+\n");
        printf("请输入您的选择:");
      xg=getchar();getchar();
      switch(xg)
       {
           case '0':break;
           case '1':
                printf("请输入要修改的学号:");
                gets(student[n].bh);
                printf("%s\n",student[n].bh);
                break;
            case '2':
                printf("请输入要修改的姓名:");
                gets(student[n].name);
                break;
            case '3':
                printf("请输入要修改的性别:");
                gets(student[n].xb);
                break;
            case '4':                                               
                printf("请输入要修改的数学分数:");
                gets(numstr);   
                student[n].sx=atoi(numstr);
                break;
            case '5':
                printf("请输入要修改的外语语分数:");
                gets(numstr);
                student[n].yy=atoi(numstr);
                break;
            case '6':
                printf("请输入要修改的网页分数:");
                gets(numstr);                                         
                student[n].wy=atoi(numstr);
                break;
               case '7':
                printf("请输入要修改的c语言分数:");
                gets(numstr);                                         
                student[n].cyy=atoi(numstr);
                break;
            case '8':
                printf("请输入要修改的计算机分数:");
                gets(numstr);                                         
                student[n].jsj=atoi(numstr);
                break;
            default:   
            break;
      }
      printf("%-7s%-7s%-7s%-7d%-7d%-7d%-7d\n",
     student[n].bh,student[n].name,student[n].xb,
    student[n].sx,student[n].yy,
    student[n].wy,student[n].cyy,
    student[n].jsj);
      rewind(fp);
      fwrite(student,sizeof(student[0]),i,fp);
      getchar();getchar();
      fclose(fp);
}
void charu()//插入信息
{
     int i=0, a=0;
     printf("如果你想插入一条记录. ");
     printf("请在插入之前查找记录.\n");
     chazhao();   
     if((fp=fopen("xuesheng.txt","rb+"))==NULL)
         {
          printf("不能打开 xuesheng.txt");
          exit(0);
         }
     while (fread(&student[i],sizeof(student[0]),1,fp)==1)
     i++;
     a=i;
     for(i=a-1;i>n-1;i--)
     student[i+1]=student[i];
     printf("请输入插入的学号:");
     gets(student[n].bh);
     printf("请输入插入的姓名:");
     gets(student[n].name);
     printf("请输入插入的性别:");
     gets(student[n].xb);
     printf("请输入插入的数学成绩:");
     gets(numstr);
     student[n].sx=atof(numstr);
     printf("请输入插入的外语成绩:");
     gets(numstr);
     student[n].yy=atof(numstr);
     printf("请输入插入的网页成绩:");
     gets(numstr);
     student[n].wy=atof(numstr);
     printf("请输入插入的c语言成绩:");
     gets(numstr);
     student[n].cyy=atof(numstr);
     printf("请输入插入的计算机成绩:");
     gets(numstr);
     student[n].sx=atof(numstr);
     rewind(fp);
     fwrite(student,sizeof(student[0]),a+1,fp);
     getchar();getchar();
     fclose(fp);
    }   
void shanchu()// 删除信息
{
      int i=0, a=0;
  printf("如果你想删除信息** 必须先找到.\n");
  chazhao();
  if((fp=fopen("xuesheng.txt","rb+"))==NULL)
     {
         printf("不能打开 xuesheng.txt");
         exit(0);
     }
   while (fread(&student[n],sizeof(student[0]),1,fp)==1)  
   i++;
   a=i;
   for(i=n;i<a;i++)
  student[n]=student[i+1];
  fp=fopen("xuesheng.txt","wb");
  printf("删除记录成功!");
  fwrite(student,sizeof(student[0]),a-1,fp);
  getchar();getchar();
  fclose(fp);
    }      
 void tongji()//统计、处理
 {
  int i=0;int a=0;double sum=0;char tj;
  if((fp=fopen("xuesheng.txt","rb"))==NULL)
     {
      printf("不能打开 xuesheng.txt");
      exit(0);
     }
  while (fread(&student[n],sizeof(student[0]),1,fp)==1)
          i++;
          a=i;
         printf("\t\t   ----------------------------\n");
         printf("\t\t   || ********统计********* ||\n");
         printf("\t\t   ===========================\n");
         printf("\t\t   ||                       ||\n");
         printf("\t\t   ||   你想统计哪科成绩:   ||\n");
         printf("\t\t   ||   1:平均成绩          ||\n");
         printf("\t\t   ||   1:总成绩            ||\n");
         printf("\t\t   ||                       ||\n");
         printf("\t\t   ===========================\n");
         tj=getchar();getchar();
 switch(tj)
  {
     
     case '1':
         printf("如果想统计,请先寻找.\n");
         chazhao();
         sum=student[n].sx+student[n].yy+student[n].wy+student[n].cyy+student[n].jsj;
         printf("%s 平均成绩是 %f",student[n].name,sum/4);
         break;
     case '2':  
         printf("如果想统计,请先寻找.\n");
         chazhao();
         sum=student[n].sx+student[n].yy+student[n].wy+student[n].cyy+student[n].jsj;
         printf("%s总成绩是 %f\n",student[n].name,sum);
         break;
      }
       getchar();getchar();
      fclose(fp);
 }
 
         
void paixu()//筛选排序
    {
       char px;
       int i=0, a=0,m=0,k=0;
       if((fp=fopen("xuesheng.txt","rb+"))==NULL)
         {
          printf("不能打开 xuesheng.txt");
          exit(0);
         }
       while (fread(&student[n],sizeof(student[0]),1,fp)==1)
       i++;
       a=i;
       printf("你想用什么方式排序?\n");
       printf("1.学号 2.成绩\n");
       px=getchar();getchar();
       switch(px)
       {
        case '1':
            for(i=0;i<a-1;i++)
                 for(k=i+1;k<a;k++)
                       if(student[i].bh>student[k].bh)
                       {
                      arrange=student[k];
                      student[k]=student[i];
                      student[i]=arrange;
                    }
              break;
       case '2':
            printf("1.数学 2.外语 3.网页 4.c语言 5.计算机\n");
            px=getchar();getchar();
            switch(px)
            {
              case '1':
                  for(i=0;i<a-1;i++)
                      for(k=i+1;k<a;k++)
                         if(student[i].sx>student[k].sx)
                          {
                            arrange=student[k];
                             student[k]=student[i];
                             student[i]=arrange;
                          }
                  break;
             case '2':
                     for(i=0;i<a-1;i++)
                         for(k=i+1;k<a;k++)
                             if(student[i].yy>student[k].yy)
                             {
                             arrange=student[k];
                             student[k]=student[i];
                             student[i]=arrange;
                              }
                    break;
             case '3':
                 for(i=0;i<a-1;i++)
                     for(k=i+1;k<a;k++)
                         if(student[i].wy>student[k].wy)
                        {
                             arrange=student[k];
                             student[k]=student[i];
                             student[i]=arrange;
                         }
                 break;
             case '4':
                for(i=0;i<a-1;i++)
                    for(k=i+1;k<a;k++)
                        if(student[i].cyy>student[k].cyy)
                         {
                          arrange=student[k];
                          student[k]=student[i];
                          student[i]=arrange;
                          }
                     break;
           }
        break;
        }
        rewind(fp);
        fwrite(student,sizeof(student[0]),a,fp);
        fclose(fp);
    }

   
void tianjia()//添加信息
{
    n=0;
    if((fp=fopen("xuesheng.txt","ab"))==NULL)
       { printf("不能打开 xuesheng.txt file\n");
        exit(0);
       }
     while (fread(&student[n],sizeof(student[0]),1,fp)==1)
          n++;
      fclose(fp);
      if((fp=fopen("xuesheng.txt","ab"))==NULL)
       {
        exit(0);
       }
           printf("\t\t\t请输入所要添加的信息\n");
            printf("请输入学号:",n+1);
         gets(student[n].bh);
         printf("请输入姓名:",n+1);
         gets(student[n].name);
         printf("请输入性别:",n+1);
         gets(student[n].xb);
         printf("请输入数学成绩:");
         gets(numstr);
         student[n].sx=atof(numstr);
         printf("请输入外语成绩:");
         gets(numstr);
         student[n].yy=atof(numstr);
         printf("请输入网页成绩:");
         gets(numstr);
         student[n].wy=atof(numstr);
         printf("请输入c语言成绩:");
         gets(numstr);
         student[n].cyy=atof(numstr);
         printf("请输入计算机成绩:");
         gets(numstr);
         student[n].jsj=atof(numstr);
       fwrite(&student[n],sizeof(student[n]),1,fp);
      fclose(fp);
}
2013-07-02 13:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-416504-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.190758 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved