学生信息进行管理.docx

上传人:b****7 文档编号:10845798 上传时间:2023-02-23 格式:DOCX 页数:18 大小:134.83KB
下载 相关 举报
学生信息进行管理.docx_第1页
第1页 / 共18页
学生信息进行管理.docx_第2页
第2页 / 共18页
学生信息进行管理.docx_第3页
第3页 / 共18页
学生信息进行管理.docx_第4页
第4页 / 共18页
学生信息进行管理.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

学生信息进行管理.docx

《学生信息进行管理.docx》由会员分享,可在线阅读,更多相关《学生信息进行管理.docx(18页珍藏版)》请在冰豆网上搜索。

学生信息进行管理.docx

学生信息进行管理

沈阳航空工业学院

课程设计

学号_____200604021075___

班级___6402103_______

姓名____杨金丹______

指导教师_刘成_________

2007年9月18日

沈阳航空工业学院

课程设计任务书

电子工程系电子信息工程专业6402103班学号200604021075

一、课程设计题目:

学生成绩管理

二、课程设计工作自2007年9月10日起至2007年9月14日止

三、课程设计内容:

用C语言编写软件完成以下任务:

能够对学生信息进行管理,至少包括信息的录入、修改、查询、删除4项功能;学生信息至少包括姓名、学号、数学成绩三方面;学生信息应及时保存在文件myfile.dat中。

四、课程设计要求:

程序质量:

●贯彻事件驱动的程序设计思想。

●用户界面友好,功能明确,操作方便;可以加以其它功能或修饰。

●用户界面中的菜单至少应包括“录入学生信息”、“修改学生信息”、“查询学生信息”、“退出”4项。

●代码应适当缩进,并给出必要的注释,以增强程序的可读性。

课程设计说明书:

课程结束后,上交课程设计说明书和源程序。

课程设计说明书的内容如下:

●程序设计题目

●需求分析(分析题目的要求)

●程序框图(总体框图和各功能模块框图,使用传统流程图或N-S框图)

●课程设计任务书

●核心技术的实现方法及程序源代码及注释

●个人总结

●[参考资料]

指导教师:

__________________

学生签名:

__________________

目录

一、需求分析1

二、程序流程图2

三、核心技术的实现说明及相应程序段6

四、个人总结12

五、参考文献12

六、源程序12

 

一、需求分析

经过对程序设计题目的分析可知,整个程序的设计实现大致分为五个模块,其中每一个模块对应一个函数,他们的功能分别是:

添加学生数据函数(add),删除数据函数(del),成绩查询函数(query),更改学生数据函数(change)以及显示学生信息函数(show)。

在这些函数当中,前四个函数的实现严格按照题目的要求,而后面的两个函数属于附加功能。

1、添加学生数据函数主要实现程序最初运行时学生数据的录入以及其后的运行中学生数据的追加功能;

2、删除学生数据函数实现的功能是按照学号对学生的数据记录进行删除;

3、排序函数按照题目的具体要求实现的是总成绩的递减排序以及名次显示,其中总成绩相同者名次相同;

4、更改数据函数可以实现对学生记录中除学号以外的信息进行修改;

5、显示函数实现的是显示目前所有的有效学生记录信息。

除上面介绍的功能之外,程序还具有退出功能,可以在程序的一次运行当中循环执行所有的功能,并根据需要终止程序的执行。

每一个学生记录都包含学号、姓名,以及英语、计算机和数学三门成绩,在程序当中,将学生记录类型定义为结构体类型,添加以及追加的学生信息直接写入E盘的myfile.dat文件中,其他函数每次对学生记录的访问,其数据来源都是myfile.dat文件,这样做不但可以保证学生数据的一致性,而且可以对学生数据进行永久保存,保证每次运行程序都可以采用原来的数据。

二、程序流程图

1、程序总体结构图

图1程序总体结构图

2、具体功能框图

(1)添加学生数据函数add

图2添加学生数据函数

(2)读取学生数据reads

图3读取学生数据

 

(3)删除学生记录函数del

(4)按总分排序函数sort

 

(4)排序函数sort

 

图4删除学生记录函数

三、核心技术的实现说明及相应程序段

本程序主要由六个自定义函数和一个主函数组成,其中主函数以菜单的形式调用其他函数来实现要求的所有功能。

在这些函数当中,添加数据函数、删除数据函数和排序函数是程序中较为核心的部分,下面分别进行说明。

1、添加数据函数

添加数据分为两种情况,其一是在学生文件(m)不存在的情况下,首先由程序创建一个新文件,并将录入的学生信息写入该文件当中;其二是在学生文件(myfile.dat)已经存在的情况下,此时文件要以读写方式或追加的方式打开,这样才可以保证以前已经存在的数据不丢失。

具体的程序段如下:

voidadd()

{FILE*fp;

intn,i,j;

structstudentstu;

if((fp=fopen("e:

\\myfile.dat","rb+"))!

=NULL)

{j=getw(fp);

rewind(fp);

printf("Pleaseinputtowantthestudent'squantitythatincrease,andpresstoreturnthecarkeytheconfirmation:

");

scanf("%d",&n);

putw(j+n,fp);

fseek(fp,0L,2);

for(i=1;i<=n;i++)

{printf("\nPleaseinputtheregistrationnumber,nameofthe%dstudent,usetheblankspacetoseparate,andpresstoreturnthecarkeytheconfirmationn:

\n",i);

scanf("%s%s",stu.num,stu.name);

printf("\nPleaseinputEnglish,computerofthe%dstudentwiththreescoresofmath,andusetheblankspacetoseparate,andpresstoreturnthecarkeytheconfirmation:

\n",i);

scanf("%f%f%f",&stu.English,&puter,&stu.math);

fwrite(&stu,sizeof(structstudent),1,fp);

}

}

else

{

if((fp=fopen("e:

\\myfile.dat","wb"))!

=NULL)

{

printf("Pleaseinputtowantthestudent'squantitythatincrease,andpresstoreturnthecarkeytheconfirmation:

");

scanf("%d",&n);

putw(n,fp);

for(i=1;i<=n;i++)

{printf("\nPleaseinputtheregistrationnumber,nameofthe%dstudent,usetheblankspacetoseparate,andpresstoreturnthecarkeytheconfirmationn:

\n",i);

scanf("%s%s",stu.num,stu.name);

printf("\nPleaseinputEnglish,computerofthe%dstudentwiththreescoresofmath,andusetheblankspacetoseparate,andpresstoreturnthecarkeytheconfirmation:

\n",i);

scanf("%f%f%f",&stu.English,&puter,&stu.math);

fwrite(&stu,sizeof(structstudent),1,fp);

}

}

}

fclose(fp);}}

2、删除数据函数

该函数的核心内容是删除算法以及最终对源文件的更新。

该函数执行时,首先调用reads函数将文件中的学生信息读入数组当中,并由用户输入待删除学生的学号,而后按照该学号进行查找,如果文件中存在该学生的数据,则采用删除算法删除,否则输出学生信息不存在的提示信息。

对学生信息的具体删除算法是在结构体数组中实现的,当学生的信息被找到后,位于数组中该学生后面的学生记录依次向前移动一个元素的位置,这些操作完成后,要删除的学生信息就被后面的数组元素覆盖掉了,也就实现了删除。

在数组中删除学生信息后,还要将更改后的信息重新写回文件当中,以保证数据的一致性。

具体程序段如下:

voiddel()

{structstudentstu[N];

charnumber[20];

FILE*fp;

intn,i,j;

reads(stu,&n);

printf("\nPleasethestudent'sregistrationnumberofinputtingtowantthedeletioninformation,andpresstoreturnthecarkeytheconfirmation:

");

getchar();

scanf("%s",number);

for(i=0;i

if(strcmp(number,stu[i].num)==0)break;

if(i>=n)

{printf("Didnotfindoutthestudent'sinformation!

\n");

return;

}

else

{for(j=i+1;j

strcpy(stu[j-1].num,stu[j].num);

strcpy(stu[j-1].name,stu[j].name);

stu[j-1].English=stu[j].English;

stu[j-1].computer=stu[j].computer;

stu[j-1].math=stu[j].math;

}

if((fp=fopen("e:

\\myfile.dat","wb"))==NULL)

{printf("Thedocumentopensthefailure!

");

return;

}

else

{putw(n-1,fp);

for(i=0;i

fwrite(&stu[i],sizeof(structstudent),1,fp);

}

fclose(fp);

printf("Deletethesuccess!

\n");}

四、个人总结

大一我们学习了计算机文化基础和C语言程序编程,这两门课程的学习,使我应用计算机有了一定的基础。

通过此次课程任务设计,使我对C语言运用更加自如。

编程是一项需要缜密思维的工作,不能有丝毫马虎,否则就会全盘皆输。

在编写程序的过程中,我遇到了很多困难,编出的程序漏洞百出,查错改错的过程充满艰辛,语法错误改完了,运行后才发现算法不对,不能实现题目要求的功能,只能再认真的从头再来,最后终于成功编出了能实现题目要求功能的程序,在这门课上我学会了如何做到精益求精。

C语言程序设计确实是一门很有用的学科,像我的题目—学生成绩管理一样,是与实际生活紧密相关的,在以后的工作当中都会用的到,所以这次课设并不是一个结束,而是一个开始,一个对C语言更深入学习的开始。

五、参考文献

1谭浩强.C程序设计.北京:

清华大学出版社,2005

2刘成等.C语言程序设计实验指导与习题集.北京:

中国铁道出版社,2006

六、源程序

#include

#include

#defineN20

structstudent

{charnum[20];

charname[10];

floatEnglish;

floatcomputer;

floatmath;

};

voidmenu();

voidreads();

voidadd();

voiddel();

voidsort();

voidquery();

voidchange();

voidshow();

main()

{

intn;

while

(1)

{

menu();

printf("\nPleaseinputtheoperationprefacethatyouwantchoicenumber,andpresstoreturnthecarkeytheconfirmation");

scanf("%d",&n);

switch(n)

{case1:

add();break;

case2:

show();break;

case3:

del();break;

case4:

change();break;

case5:

query();break;

case6:

exit(0);

default:

printf("Inputthemistake,andpleasetheimportationrowthewatchinsideprefacenumberthatexsits-\n");

}

}

}

voidmenu()

{printf("*****************Students'scoremanagementsystem**************");

printf("\n1Increasethestudent'sdata");

printf("\n2Showthestudent'sdata");

printf("\n3Deletethestudent'sdata");

printf("\n4Changethestudent'sdata");

printf("\n5Scoresearch");

printf("\n6quit");

}

voidreads(structstudentstu[N],int*n)

{

FILE*fp;

inti=0;

if((fp=fopen("e:

\\myfile.dat","rb"))==NULL)

{printf("Thedocumentopensthefailure!

\n");

return;

}

else

{

*n=getw(fp);

for(i=0;i<*n;i++)

fread(&stu[i],sizeof(structstudent),1,fp);

}

fclose(fp);

}

voidadd()

{FILE*fp;

intn,i,j;

structstudentstu;

if((fp=fopen("e:

\\myfile.dat","rb+"))!

=NULL)

{j=getw(fp);

rewind(fp);

printf("Pleaseinputtowantthestudent'squantitythatincrease,andpresstoreturnthecarkeytheconfirmation:

");

scanf("%d",&n);

putw(j+n,fp);

fseek(fp,0L,2);

for(i=1;i<=n;i++)

{printf("\nPleaseinputtheregistrationnumber,nameofthe%dstudent,usetheblankspacetoseparate,andpresstoreturnthecarkeytheconfirmationn:

\n",i);

scanf("%s%s",stu.num,stu.name);

printf("\nPleaseinputEnglish,computerofthe%dstudentwiththreescoresofmath,andusetheblankspacetoseparate,andpresstoreturnthecarkeytheconfirmation:

\n",i);

scanf("%f%f%f",&stu.English,&puter,&stu.math);

fwrite(&stu,sizeof(structstudent),1,fp);

}

}

else

{

if((fp=fopen("e:

\\myfile.dat","wb"))!

=NULL)

{

printf("Pleaseinputtowantthestudent'squantitythatincrease,andpresstoreturnthecarkeytheconfirmation:

");

scanf("%d",&n);

putw(n,fp);

for(i=1;i<=n;i++)

{printf("\nPleaseinputtheregistrationnumber,nameofthe%dstudent,usetheblankspacetoseparate,andpresstoreturnthecarkeytheconfirmationn:

\n",i);

scanf("%s%s",stu.num,stu.name);

printf("\nPleaseinputEnglish,computerofthe%dstudentwiththreescoresofmath,andusetheblankspacetoseparate,andpresstoreturnthecarkeytheconfirmation:

\n",i);

scanf("%f%f%f",&stu.English,&puter,&stu.math);

fwrite(&stu,sizeof(structstudent),1,fp);

}

}

}

fclose(fp);

}

voidshow()

{structstudentstu[N];

inti,n;

reads(stu,&n);

if(n==0)

return;

printf("**********Allstudentinformationasfollows*******");

for(i=0;i

printf("\n%3d%5s%5s%8f%8f%8f\n",i+1,stu[i].num,stu[i].name,stu[i].English,stu[i].computer,stu[i].math);

getch();

}

voiddel()

{structstudentstu[N];

charnumber[20];

FILE*fp;

intn,i,j;

reads(stu,&n);

printf("\nPleasethestudent'sregistrationnumberofinputtingtowantthedeletioninformation,andpresstoreturnthecarkeytheconfirmation:

");

getchar();

scanf("%s",number);

for(i=0;i

if(strcmp(number,stu[i].num)==0)break;

if(i>=n)

{printf("Didnotfindoutthestudent'sinformation!

\n");

return;

}

else

{for(j=i+1;j

strcpy(stu[j-1].num,stu[j].num);

strcpy(stu[j-1].name,stu[j].name);

stu[j-1].English=stu[j].English;

stu[j-1].computer=stu[j].computer;

stu[j-1].math=stu[j].math;

}

if((fp=fopen("e:

\\myfile.dat","wb"))==NULL)

{printf("Thedocumentopensthefailure!

");

return;

}

else

{putw(n-1,fp);

for(i=0;i

fwrite(&stu[i],sizeof(structstudent),1,fp);

}

fclose(fp);

printf("Deletethesuccess!

\n");

}

voidchange()

{structstudentstu[N],temp;

intn,i;

FILE*fp;

printf("\nPleaseinputthestudent'sregistrationnumberofwantingtochangetheinformation,andpresstoreturnthecarkeytheconfirmation:

");

scanf("%s",temp.num);

reads(stu,&n);

for(i=0;i

if(strcmp(temp.num,stu[i].num)==0)break;

if(i>=n)

{printf("Havenothisstudent'sinformation!

");

return;

}

printf("\nPleasethreescoresofnameofinputtingtochangetheempressstudent,English,computer,math,andpresstoreturnthecarkeytheconfirmation:

\n");

scanf("%s%f%f%f",temp.name,&temp.English,&puter,&temp.math);

strcpy(stu[i].name,temp.name);

stu[i].English=temp.English;

stu[i].computer=puter;

stu[i].math=temp.math;

if((fp=fopen("e:

\\myfile.dat","wb"))==NULL)

{printf("Openthedocumentfailure!

");

return;

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 高中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1