毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

C语言课程设计之学生成绩简单管理程序 第2页

更新时间:2007-10-22:  来源:毕业论文

Statistic(Student stud[],int n)            /*新增功能,输出统计信息*/

{

                    int i,j=0,k=0,sum=0;

                    float aver;            /*成绩平均值*/

                    for(i=0;i<n;i++)            /*循环输入判断*/

                             {

                              sum+=stud[i].score;

                              if(stud[j].score>stud[i].score) j=i;

                              if(stud[k].score<stud[i].score) k=i;

                             }

                    aver=1.0*sum/n;

                    printf("\t\t\tthere are %d records.\n",n);            /*总共记录数*/

                    printf("\t\t\tthe hignest score:\n");           /*最高分*/

                    printf("\t\t\tnumber:%s   name:%s   score:%d\n",stud[j].num,stud[j].name,stud[j].score);

                    printf("\t\t\tthe lowest score:\n");            /*最低分*/

                    printf("\t\t\tnumber:%s   name:%s   score:%d\n",stud[k].num,stud[k].name,stud[k].score);

                    printf("\t\t\tthe average score is %5.2f\n",aver);                  /*平均分*/

}

 

int AddfromText(Student stud[],int n)               /*从文件中读入数据*/

{

                    int i=0,num;

                    FILE *fp;            /*定义文件指针*/

                    char filename[20];                  /*定义文件名*/

                    printf("\t\t\tInput the filename:");

                    scanf("\t\t\t%s",filename);              /*输入文件名*/

                    if((fp=fopen(filename,"rb"))==NULL)             /*打开文件*/

                             {

                                       printf("\t\t\tcann't open the file\n");                  /*打开失败信息*/

                                       printf("\t\t\t");

                                       system("pause");

                                       return(n);

                             }

                fscanf(fp,"%d",&num);                  /*读入总记录量*/

                    while(i<num)                /*循环读入数据*/

                    {

                             fscanf(fp,"%s%s%d",stud[n+i].num,stud[n+i].name,&stud[n+i].score);

                             i++;

                }

                    n+=num;

                    fclose(fp);           /*关闭文件*/

                    printf("\t\t\tSuccessed!\n");

                    printf("\t\t\t");

                    system("pause");

                    return(n);

}

 

void WritetoText(Student stud[],int n)               /*将所有记录写入文件*/

{

 int i=0;

 FILE *fp;           /*定义文件指针*/

 char filename[20];                 /*定义文件名*/

                    printf("\t\t\tWrite Records to a Text File\n");             /*输入文件名*/

                    printf("\t\t\tInput the filename:");

                    scanf("\t\t\t%s",filename);

                    if((fp=fopen(filename,"w"))==NULL)             /*打开文件*/

                             {

                                       printf("\t\t\tcann't open the file\n");

                                       system("pause");

                                       return;

                             }

                fprintf(fp,"%d\n",n);             /*循环写入数据*/

                    while(i<n)

                    {

                             fprintf(fp,"%-16s%-15s%d\n",stud[i].num,stud[i].name,stud[i].score);

                             i++;

                }

                    fclose(fp);           /*关闭文件*/

                    printf("Successed!\n");          /*返回成功信息*/

}

 

void main()           /*主函数*/

{

 int n=0;

                    for(;;)

                    {

                             switch(menu_select())           /*选择判断*/

                             {

                             case 1:

                                       printf("\t\t\tInput Records\n");                /*输入若干条记录*/

                                       n=Input(stu,n);

                                       break;

                             case 2:

                                       printf("\t\t\tDisplay All Records\n");                /*显示所有记录*/

                                       Display(stu,n);

                                       break;

                             case 3:

                                       printf("\t\t\tSort\n");

                                       Sort_by_num(stu,n);             /*按学号排序*/

                                       printf("\t\t\tSort Suceessed!\n");

                                       printf("\t\t\t");

                                       system("pause");

                                       break;

                             case 4:

                                       printf("\t\t\tInsert a Record\n");

                                       n=Insert_a_record(stu,n);               /*插入一条记录*/

                                       printf("\t\t\t");

                                       system("pause");

                                       break;

                             case 5:

                                       printf("\t\t\tDelete a Record\n");

                                       n=Delete_a_record(stu,n);              /*按姓名查找,删除一条记录*/

                                       printf("\t\t\t");

                                       system("pause");

                                       break;

                             case 6:

                                       printf("\t\t\tQuery\n");

                                       Query_a_record(stu,n);                  /*查找并显示一个记录*/

                                       printf("\t\t\t");

                                       system("pause");

                                       break;

                             case 7:

                                       printf("\t\t\tStatistic\n");

                                       Statistic(stu,n);             /*新增功能,输出统计信息*/

                                       printf("\t\t\t");

                                       system("pause");

                                       break;

                             case 8:

                                       printf("\t\t\tAdd Records from a Text File\n");

                                       n=AddfromText(stu,n);                  /*新增功能,输出统计信息*/

                                       break;

                             case 9:

                                       printf("\t\t\tWrite to a Text file\n");

                                       WritetoText(stu,n);                /*循环写入数据*/

                                       printf("\t\t\t");

                                       system("pause");

                                       break;

                             case 0:

                                       printf("\t\t\tHave a Good Luck,Bye-bye!\n");           /*结束程序*/

                                       printf("\t\t\t");

                                       system("pause");

                                       exit(0);

                             }

                    }

}

 

4 .函数调用关系图

Reverse(head)函数

按学号排序

5.设计测试流程

 

1、进入界面

  

2、输入选项1,回车;

  按提示输入数据:

 

3、回到主菜单;

  输入选项7,回车;

   输入文件名:data.txt,回车;

   出现成功提示,则读入文件操作成功。

 

   4、回到主菜单,输入2,回车

          10个暂停显示数据

5、回到主菜单,输入3,回车

   出现排序成功信息。

 

6、回到主菜单,输入4,回车

   按提示插入一组数据

 

7、回到主菜单,输入5,回车

   按提示输入姓名,删除数据

   出现删除成功的信息

 

 

8、回到主菜单,输入6,回车

   输入姓名进行查询

 

9、回到主菜单,输入7,回车

   出现统计信息

 

10、回到主菜单

,输入9,回车

输入result.txt,回车

出现成功写入文件的信息

 

11、回到主菜单,输入0,回车退出系统

上一页  [1] [2] 

C语言课程设计之学生成绩简单管理程序 第2页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。