编写一程序,统计学生的成绩信息(成绩信息保存在文件Score.dat中)
要求:
1. 能按总分,数学成绩,英语成绩,计算机成绩分别排序
2. 能分别统计数学,英语,计算机中不及格人数
3. 能按学号查找学生,并显示该学生信息。
注
1. 从文件中读入数据用ReadData.c 实现,功能菜单显示用Menu.c实现
2. 代码的总体结构在文件Score.c中
score.h
#ifndef _SCORE_H
#define _SCORE_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#define N 10
#define STUDENT_COUNT 50 //学生数
#define LESSON_COUNT 3 //课程数
#define SUM_SORT 0 //按总分排序
#define MATH_SORT 1 //按数学成绩排序
#define ENGLISH_SORT 2 //按英语成绩总分排序
#define COMPUTER_SORT 3 //按计算机成绩排序
#define SUM_STATISTICS 4 // 统计总分
#define MATH_STATISTICS 5 // 统计数学成绩
#define ENGLISH_STATISTICS 6 // 统计英语成绩
#define COMPUTER_STATISTICS 7 // 统计计算机成绩
#define SEARCH 8 // 查找
typedef struct _Student
{
int id; //学号
char name[N]; //姓名
int score[LESSON_COUNT]; //成绩
int sum; //总分
}Student;
//按课程成绩对学生进行排序
void Sort(Student stu[], int lessonId);
//求所有课程的总分
int Sum(Student stu[] , int count);
//按学号搜索某一名学生
int Search(Student stu[] ,int studentId);
//统计某门课程的不及格人数
int Statistics(Student stu[], int lessonId);
//显示信息
void ShowInfo(Student stu[] , int count);
//从文件读取数据
void ReadData(Student stu[] , int count);
//显示菜单
int Menu();
#endif
ReadData.c
#include "Score.h"
void ReadData(Student stu[] , int count)
{
FILE *fp;
int i;
char ch[10];
if((fp = fopen("Score.dat","rt")) == NULL)
{
printf("t无法打开文件: Score.dat.nt ");
system("pause");
exit(0);
}
fscanf(fp,"%s%s%s%s%s",ch,ch,ch,ch,ch);
for(i = 0 ; i < count ; i++)
fscanf(fp,"%d%s%d%d%d",&stu[i].id,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
Menu.c
#include "Score.h"
//显示功能菜单,返回选择的菜单项
int Menu()
{
int menuitem ;
int item;
while(1)
{
menuitem = -1;
item = -1;
while ( menuitem != 1 && menuitem != 2 && menuit