(学生成绩文件管理.docVIP

  • 30
  • 0
  • 约3.27千字
  • 约 9页
  • 2016-12-22 发布于北京
  • 举报
课题一:学生成绩文件管理 一、目的 1.掌握文件指针的概念和运用 2.掌握文件的相关操作:打开、读、写、关闭 3.掌握文件的定位操作 二、实习环境 个人计算机,Windows操作系统,Turbo C 2.0或 WinTC或Visual C++等编译开发环境 三、实习内容、步骤与要求 1.定义一个结构体数组,存放10个学生的学号,姓名,三门课的成绩 2.从键盘输入10个学生的以上内容,存入文件stud.txt,关闭文件 3.打开stud.txt文件,将数据读出,查看是否正确写入,关闭文件。 4.打开文件stud.txt文件,读出数据,将10个学生按照平均分数从高到低进行排序, 分别将结果输出到屏幕上和另一文件studsort.txt中。 5.在实习报告中画出程序流程图,说明程序设计的算法,附主要程序段及运行结果(屏幕截图)。 6.在实习报告中说明知识点。 7.在实习报告中说明程序设计过程中的难点、解决办法及编程小结或体会。 四、程序代码 #includestdio.h #includestring.h #define N 10 struct student { char num[10] ; char name[8] ; int chinese ; int math ; int english ; int average ; } ; struct sort { int score ; char num[10] ; } ; void main() { FILE *fp ; struct student stu[N] ; struct sort sor[N] ; int i,j,temp ; char tempnum[10] ; /*INPUT*/ fp = fopen(e:\\stud.txt,w+) ; for(i = 0 ; i N ; i ++) { printf(Input student %d num :,i + 1) ; scanf(%s,stu[i].num) ; printf(Input student %d name :,i + 1) ; scanf(%s,stu[i].name) ; printf(Input student %d Chinese score :,i + 1) ; scanf(%d,stu[i].chinese) ; printf(Input student %d Math score :,i + 1) ; scanf(%d,stu[i].math) ; printf(Input student %d English score :,i + 1) ; scanf(%d,stu[i].english) ; printf(\n) ; } for(i = 0 ; i N ; i ++) { stu[i].average = (stu[i].chinese + stu[i].math + stu[i].english) / 3 ; fprintf(fp,%s\t%s\t%d\t%d\t%d\t%d\n,stu[i].num,stu[i].name,stu[i].math,stu[i].chinese,stu[i].english,stu[i].average) ; } fclose(fp) ; /*Sort and output*/ fp = fopen(e:\\studsort.txt,w+) ; for(i = 0 ; i N ; i ++) { sor[i].score = stu[i].average ; strcpy(sor[i].num,stu[i].num) ; } for(i = 0 ; i N - 1 ; i ++) for(j = i + 1 ; j N ; j ++) { if(sor[i].score sor[j].score) { temp = sor[i].score ; sor[i].score = sor[j].score ; sor[j].score = temp ; strcpy(tempnum,sor[i].num) ; strcpy(

文档评论(0)

1亿VIP精品文档

相关文档