
求编程高手帮忙,若编的程序能运行且符合要求。定追加。。。 30
学生成绩管理系统现有学生成绩信息文件1(1.txt),内容如下姓名学号语文数学英语张明明01677882李成友02789188张辉灿03688256王露04564577陈...
学生成绩管理系统
现有学生成绩信息文件1(1.txt),内容如下
姓名 学号 语文 数学 英语
张明明 01 67 78 82
李成友 02 78 91 88
张辉灿 03 68 82 56
王露 04 56 45 77
陈东明 05 67 38 47
…. .. .. .. …
学生成绩信息文件2(2.txt),内容如下:
姓名 学号 语文 数学 英语
陈果 31 57 68 82
李华明 32 88 90 68
张明东 33 48 42 56
李明国 34 50 45 87
陈道亮 35 47 58 77
…. .. .. .. …
试编写一管理系统,要求如下:
1) 实现对两个文件数据进行合并,生成新文件3.txt
2) 抽取出三科成绩中有补考的学生并保存在一个新文件4.txt
3) 对合并后的文件3.txt中的数据按总分降序排序(至少采用两种排序方法实现)
4) 输入一个学生姓名后,能查找到此学生的信息并输出结果(至少采用两种查找方法实现)
5) 要求使用结构体,链或数组等实现上述要求. 展开
现有学生成绩信息文件1(1.txt),内容如下
姓名 学号 语文 数学 英语
张明明 01 67 78 82
李成友 02 78 91 88
张辉灿 03 68 82 56
王露 04 56 45 77
陈东明 05 67 38 47
…. .. .. .. …
学生成绩信息文件2(2.txt),内容如下:
姓名 学号 语文 数学 英语
陈果 31 57 68 82
李华明 32 88 90 68
张明东 33 48 42 56
李明国 34 50 45 87
陈道亮 35 47 58 77
…. .. .. .. …
试编写一管理系统,要求如下:
1) 实现对两个文件数据进行合并,生成新文件3.txt
2) 抽取出三科成绩中有补考的学生并保存在一个新文件4.txt
3) 对合并后的文件3.txt中的数据按总分降序排序(至少采用两种排序方法实现)
4) 输入一个学生姓名后,能查找到此学生的信息并输出结果(至少采用两种查找方法实现)
5) 要求使用结构体,链或数组等实现上述要求. 展开
2个回答
展开全部
#include <stdio.h>
#include <string.h>
int cnt=0;//记录当前可读或可写记录条数
struct student
{
char name[11];//名字最长五个汉字
char sid[5];//学号最长四位
int score[3];//分别代表语数外
};
struct Head
{
char name[10];
char sid[5];
char score[3][5];
}head;
int main()
{
void getstuall(FILE *file,student s[]);
void get3txt(FILE *file,student s[]);
void get4txt(FILE *file,student s[],student b[]);
student s[100];//最多100个
student b[30];
FILE *fp1,*fp2,*fp3,*fp4;
if((fp1=fopen("1.txt","rt"))==NULL)
{
printf("file open error!");
return -1;
}
if((fp2=fopen("2.txt","rt"))==NULL)
{
printf("file open error!");
return -1;
}
if((fp3=fopen("3.txt","wt"))==NULL)
{
printf("file open error!");
return -1;
}
if((fp4=fopen("4.txt","wt"))==NULL)
{
printf("file open error!");
return -1;
}
getstuall(fp1,s);
getstuall(fp2,s);
get3txt(fp3,s);
get4txt(fp4,s,b);
}
void getstuall(FILE *file,student s[])
{
int rows=1;
while(!feof(file))
{
if(rows==1)
{
fscanf(file,"%s%s%s%s%s",head.name,head.sid,&head.score[0],&head.score[1],&head.score[2]);
rows++;
}
else
{
fscanf(file,"%s%s%d%d%d",s[cnt].name,s[cnt].sid,&s[cnt].score[0],&s[cnt].score[1],&s[cnt].score[2]);
cnt++;
}
}
fclose(file);
}
void get3txt(FILE *file,student s[])
{
fprintf(file,"%s\t%s\t%s\t%s\t%s\n",head.name,head.sid,head.score[0],head.score[1],head.score[2]);
for(int i=0;i<cnt;i++)
fprintf(file,"%s\t%s\t%d\t%d\t%d\n",s[i].name,s[i].sid,s[i].score[0],s[i].score[1],s[i].score[2]);
fclose(file);
}
void get4txt(FILE *file,student s[],student b[])
{
int i,j;
cnt=0;
for(i=0;i<100;i++)
{
for(j=0;j<3;j++)
{
if(s[i].score[j]<60&&s[i].score[j]>0)
{
memcpy(b[cnt].name,s[i].name,11);
memcpy(b[cnt].sid,s[i].sid,5);
b[cnt].score[0]=s[i].score[0];
b[cnt].score[1]=s[i].score[1];
b[cnt++].score[2]=s[i].score[2];
break;
}
}
}
get3txt(file,b);
}
//这是我以前写的半成品,就差统计总分,排序和输出了,你可以参考下。
//需要注意的是,1.txt和2.txt中的数据需要用制表符(tab)分割,不用空格
#include <string.h>
int cnt=0;//记录当前可读或可写记录条数
struct student
{
char name[11];//名字最长五个汉字
char sid[5];//学号最长四位
int score[3];//分别代表语数外
};
struct Head
{
char name[10];
char sid[5];
char score[3][5];
}head;
int main()
{
void getstuall(FILE *file,student s[]);
void get3txt(FILE *file,student s[]);
void get4txt(FILE *file,student s[],student b[]);
student s[100];//最多100个
student b[30];
FILE *fp1,*fp2,*fp3,*fp4;
if((fp1=fopen("1.txt","rt"))==NULL)
{
printf("file open error!");
return -1;
}
if((fp2=fopen("2.txt","rt"))==NULL)
{
printf("file open error!");
return -1;
}
if((fp3=fopen("3.txt","wt"))==NULL)
{
printf("file open error!");
return -1;
}
if((fp4=fopen("4.txt","wt"))==NULL)
{
printf("file open error!");
return -1;
}
getstuall(fp1,s);
getstuall(fp2,s);
get3txt(fp3,s);
get4txt(fp4,s,b);
}
void getstuall(FILE *file,student s[])
{
int rows=1;
while(!feof(file))
{
if(rows==1)
{
fscanf(file,"%s%s%s%s%s",head.name,head.sid,&head.score[0],&head.score[1],&head.score[2]);
rows++;
}
else
{
fscanf(file,"%s%s%d%d%d",s[cnt].name,s[cnt].sid,&s[cnt].score[0],&s[cnt].score[1],&s[cnt].score[2]);
cnt++;
}
}
fclose(file);
}
void get3txt(FILE *file,student s[])
{
fprintf(file,"%s\t%s\t%s\t%s\t%s\n",head.name,head.sid,head.score[0],head.score[1],head.score[2]);
for(int i=0;i<cnt;i++)
fprintf(file,"%s\t%s\t%d\t%d\t%d\n",s[i].name,s[i].sid,s[i].score[0],s[i].score[1],s[i].score[2]);
fclose(file);
}
void get4txt(FILE *file,student s[],student b[])
{
int i,j;
cnt=0;
for(i=0;i<100;i++)
{
for(j=0;j<3;j++)
{
if(s[i].score[j]<60&&s[i].score[j]>0)
{
memcpy(b[cnt].name,s[i].name,11);
memcpy(b[cnt].sid,s[i].sid,5);
b[cnt].score[0]=s[i].score[0];
b[cnt].score[1]=s[i].score[1];
b[cnt++].score[2]=s[i].score[2];
break;
}
}
}
get3txt(file,b);
}
//这是我以前写的半成品,就差统计总分,排序和输出了,你可以参考下。
//需要注意的是,1.txt和2.txt中的数据需要用制表符(tab)分割,不用空格
追问
虽然没完。。还是谢谢。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询