2020-09-20

C语言作业:学生学号系统

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define M 5
typedef struct list
{
	char sum[20],name[20];
	int score[M],all;
	struct list *next;
}NODE,*LIST;
void printf1()//首行,末行
{
	int i;
	for(i=0;i<60;i++)
		printf("*");
	printf("\n");
}
void printf2(int a)//空行
{
	int i,j;
	for(i=0;i<a;i++)
	{
		printf("*");
		for(j=0;j<58;j++)
			printf(" ");
		printf("*\n");
	}
}
void printfs(char s[])//字行
{
	int i,j,a;
	for(i=a=0;s[i];i++)
			a++;
	printf("*");
	j=(58-a)/2;
	for(i=0;i<j;i++)
		printf(" ");
	printf("%s",s);
	j=(58-a)/2+1/2;
	for(i=0;i<j;i++)
		printf(" ");
	printf("*\n");
}
void password()
{
	char *s,q[20];
	printf1();
	printf2(5);
	printfs(s="请输入密码");
	printf2(5);
	printf1();
	scanf("%s",&q);
	system("cls");
	if(strcmp(q,"123456")==0)
	{
		system("cls");
		return;
	}
	else 
	{	
		printf1();
		printf2(2);
		printf("*      一   一                                             *\n");
		printf("*         -                                                *\n");
		printfs(s="密码输入错误");
		printfs(s="请重新输入");
		printf("*                                       一   一            *\n");
		printf("*                                          -               *\n");
		printf("*                                          =               *\n");
		printf2(2);
		printf1();
		scanf("%s",q);
		if(strcmp(q,"123456")==0)
		{
			system("cls");
			return;
		}
		else
		{
			system("cls");
			printf1();
			printf2(2);
			printf("*      一   一                                             *\n");
			printf("*         0                                                *\n");
			printfs(s="密码输入错误");
			printfs(s="你还有一次机会");
			printfs(s="请重新输入");
			printf("*                                            一   一       *\n");
			printf("*                                               0          *\n");
			printf2(2);
			printf1();
			scanf("%s",q);
			if(strcmp(q,"123456")==0)
			{
				system("cls");
				return;
			}
			else
			{
				system("cls");
				printf1();
				printf2(4);
				printf("*            O(∩_∩)O~                                    *\n");
				printfs(s="密码输入错误");
				printfs(s="按任意键");
				printfs(s="关闭系统");
				printf2(4);
				printf1();
				exit(0);
			}
		}
	}
	
}
void open()
{
	FILE *fp;
	fp=fopen("d:\\Class","rt");
	if(fp==NULL)
	{
		fp=fopen("d:\\Class","wt");
	}
	fclose(fp);
}
void add();
void one();
int check(char sum[20])
{
	int i,n=0;
	FILE *fp;
	LIST head,p;
	fp=fopen("d:\\Class","rt");
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(i=0;i<M;i++)
		{
			fscanf(fp,"%d\t",&p->score[i]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	while(p)
	{
		if(strcmp(sum,p->sum)==0)
		{
			system("cls");
			printf1();
			printf2(4);
			printfs("此学号已存在");
			printfs("指令一,重新输入新学号");
			printfs("指令二,更改原有储存学生信息");
			printfs("指令三,停止输入,返回主页");
			printf2(4);
			printf1();
			scanf("%d",&i);
			system("cls");
			switch(i)
			{
			case 1:return 1;
				break;
			case 2:return 2;
				break;
			default:return 3;
				break;
			}
		}
		p=p->next;
	}
	return 0;
}
void change();
void add()
{
	int i,j,n,m,score[M];
	char s,name[20],sum[20];
	FILE *fp;
	fp=fopen("d:\\Class","at");
	printf1();
	printf2(2);
	printfs("请输入学生学号");//15
	printf2(9);
	printf1();
	scanf("%s",sum);
	system("cls");
	i=check(sum);
	if(i==1)
	{
		add();
		return;
	}
	else if(i==2)
	{
		change(sum);
		return;
	}
	else if(i==3)
	{
		one();
		return;
	}
	//001
	i=strlen(sum);
	printf1();
	printf2(2);
	printf("*学生学号:\t%s",sum);
	for(j=0;j<43-i;j++)
		printf(" ");
	printf("*\n");
	printfs("请输入学生姓名");
	printf2(8);
	printf1();
	scanf("%s",name);
	system("cls");
	//002
	for(n=0;n<M+1;n++)
	{
		printf1();
		printf2(2);
		i=strlen(sum);
		printf("*学生学号:\t%s",sum);
		for(j=0;j<43-i;j++)
			printf(" ");
		printf("*\n");
		i=strlen(name);
		printf("*学生姓名:\t%s",name);
		for(j=0;j<43-i;j++)
		printf(" ");
		printf("*\n");
		for(m=0;m<n;m++)
		{
			i=(int)(log10(score[m])+1);
				printf("*第%d科成绩:     %d",m+1,score[m]);
			for(j=0;j<43-i;j++)
				printf(" ");
			printf("*\n");
		}
		if(n!=M)
		{
			printf("*");
			for(i=0;i<20;i++)
				printf(" ");
			printf("请输入第%d科的分数",n+1);
			for(i=0;i<21;i++)
				printf(" ");
			printf("*\n");
			printf2(7-n);
			printf1();
			scanf("%d",&score[n]);
			system("cls");
		}
		else
		{
			printfs("按回车键,继续输入,按其他键,停止输入");
			printf2(7-n);
			printf1();
		}
	}
	fprintf(fp,"%s\t%s\t",sum,name);
	for(i=0;i<M;i++)
		fprintf(fp,"%d\t",score[i]);
	fprintf(fp,"\n");
	fclose(fp);
	getchar();
	s=getchar();
	system("cls");
	if(s=='\n')
	{
		add();
		return;
	}
	else
	{
		one();
		return;
	}
}
void change1();
void change(char na[20])
{

	int i,j,n,a=0;
	char *sum[10]={"一","二","三","四","五","六","七","八","九","十"};
	NODE *head,*p;
	FILE *fp;
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	fp=fopen("d:\\Class","rt");
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(j=0;j<M;j++)
		{
			fscanf(fp,"%d\t",&p->score[j]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	n=0;
	while(p)
	{
		if(strcmp(na,p->sum)==0||strcmp(na,p->name)==0)
		{
			n++;
		}
		p=p->next;
	}
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	fp=fopen("d:\\Class","rt");
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(j=0;j<M;j++)
		{
			fscanf(fp,"%d\t",&p->score[j]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	if(n==2)
	{		
		while(p)
		{
			if(strcmp(na,p->sum)==0||strcmp(na,p->name)==0)
			{	
				if(a==1)
				{
					printf1();
					printf2(2);
					i=strlen(p->sum);
					j=strlen(p->name);
					printfs("是否对第二位同学的信息进行更改");
					printf("*                  学号为   %s   的  %s     同学             *\n",p->sum,p->name);
					for(n=0;n<M;n++)
					{
						i=(int)log10(p->score[n])+1;
						printf("*                  第%s科成绩:         %d                   *\n",sum[n],p->score[n]);
					}
					printfs("更改请输入一,返回主页面请输入零");
					printf2(7-M);
					printf1();
					scanf("%d",&n);
					system("cls");
					switch(n)
					{
					case 1:change1(p->sum,p->name);break;
					case 2:one();break;
					}
				}
				if(a==0)
				{
					printf1();
					printf2(2);
					i=strlen(p->sum);
					j=strlen(p->name);
					printfs("查找到两人,是否对第一位同学的信息进行更改");
					printf("*                    学号为%s的%s同学",p->sum,p->name);
					for(n=0;n<26-i-j;n++)
						printf(" ");
					printf("*\n");
					for(n=0;n<M;n++)
					{
						i=(int)log10(p->score[n])+1;
						printf("*               第%s科成绩:     %d",sum[n],p->score[n]);
						for(j=0;j<27-i;j++)
							printf(" ");
						printf("*\n");
					}
					printfs("更改请输入一,查看下一位,请输入二");
					printf2(7-M);
					printf1();
					scanf("%d",&n);
					system("cls");
					switch(n)
					{
					case 1:change1(p->sum,p->name);a=1;break;
					case 2:a=1;break;
					}
				}
				
			}
			p=p->next;
		}
	}
	else if(n==0)
	{
		printf1();
		printf2(5);
		printfs("未找到该学生");
		printfs("请检查输入信息");
		printfs("按任意键退出");
		printf2(4);
		printf1();
		system("pause");
		system("cls");
		one();
	}
	else
	{
		while(p)
		{
			if(strcmp(na,p->sum)==0||strcmp(na,p->name)==0)
			{	
				printf1();
				printf2(2);
				i=strlen(p->sum);
				j=strlen(p->name);
				printfs("是否对该学生的信息进行更改");
				printf("*                    学号为%s的%s同学",p->sum,p->name);
				for(n=0;n<26-i-j;n++)
					printf(" ");
				printf("*\n");
				for(n=0;n<M;n++)
				{
					i=(int)log10(p->score[n])+1;
					printf("*          第%s科成绩:          %d",sum[n],p->score[n]);
					for(j=0;j<27-i;j++)
					printf(" ");
					printf("*\n");
				}
				printfs("更改请输入一,取消修改请输入零");
				printf2(7-M);
				printf1();
				scanf("%d",&n);
				system("cls");
				switch(n)
				{
				case 1:change1(p->sum,p->name);break;
				case 0:one();break;
				}
			}
			p=p->next;
		}
	}

}	
void changes();				
void change1(char sum[20],char name[20])
{
	int i,j,n,m;
	char a[20],*sm[10]={"一","二","三","四","五","六","七","八","九","十"};
	NODE *head,*p;
	FILE *fp;
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	fp=fopen("d:\\Class","rt");
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(j=0;j<M;j++)
		{
			fscanf(fp,"%d\t",&p->score[j]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);	
			printf1();
			printf2(2);
			printfs("请问你需要修改什么信息");
			printfs("学号,请输入一");
			printfs("姓名,请输入二");
			for(n=0;n<M;n++)
				printf("*\t\t第%s科成绩,请输入        %s                *\n",sm[n],sm[n+2]);
			printf2(7-M);
			printf1();
			scanf("%d",&n);
			system("cls");
			if(n==1)
			{
				printf1();
				printf2(5);
				printfs("请输入");
				printfs("新学号");
				printf2(5);
				printf1();
				scanf("%s",&a);
				m=0;
				m=check(a);
			}
	fp=fopen("d:\\Class","wt");
	while(p)
	{
		if(strcmp(sum,p->sum)==0&&strcmp(name,p->name)==0)
		{	
			if(n==1)
			{
				if(m==0)
				{
					strcpy(p->sum,a);
				}
				fprintf(fp,"%s\t%s\t",p->sum,p->name);
				for(i=0;i<M;i++)
					fprintf(fp,"%d\t",p->score[i]);
				fprintf(fp,"\n");
				system("cls");
			}
			else if(n==2)
			{
				printf1();
				printf2(5);
				printfs("请输入");
				printfs("新姓名");
				printf2(5);
				printf1();
				scanf("%s",&p->sum);
				fprintf(fp,"%s\t%s\t",p->sum,p->name);
				for(i=0;i<M;i++)
					fprintf(fp,"%d\t",p->score[i]);
				fprintf(fp,"\n");
				system("cls");
			}
			else
			{
				printf1();
				printf2(5);
				printf("*                      请输入第%s科的                      *\n",sm[n-3]);
				printfs("新成绩");
				printf2(5);
				printf1();	
				scanf("%d",&p->score[n-3]);
				fprintf(fp,"%s\t%s\t",p->sum,p->name);
				for(i=0;i<M;i++)
					fprintf(fp,"%d\t",p->score[i]);
				fprintf(fp,"\n");
				system("cls");
				
			}
		}
		else
		{
			fprintf(fp,"%s\t%s\t",p->sum,p->name);
			for(i=0;i<M;i++)
				fprintf(fp,"%d\t",p->score[i]);
			fprintf(fp,"\n");
		}
		p=p->next;
	}
	if(m==1)
	{
		changes();
		return;
	}
	else if(m==2)
	{
		change1(sum,name);
		return;
	}
	else if(m==3)
	{
		one();
		return;
	}
	printf1();
	printf2(4);
	printfs("修改完成");
	printfs("是否继续修改该学生信息");
	printfs("继续修改请输入一,返回主页请输入零");
	printf2(5);
	printf1();
	fclose(fp);
	scanf("%d",&n);
	system("cls");
	switch(n)
	{
	case 1:change1(sum,name);break;
	case 2:one();break;
	}
}
void changes()
{
	char sn[20];
	printf1();
	printf2(5);
	printfs("请输入需要修改学生信息");
	printfs("学号或姓名");
	printf2(5);
	printf1();
	scanf("%s",&sn);
	system("cls");
	change(sn);
}
void close();
void close2();
void close4();
void close1(char na[20])
{

	int i,j,n,a=0;
	char *sum[10]={"一","二","三","四","五","六","七","八","九","十"};
	NODE *head,*p;
	FILE *fp;
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	fp=fopen("d:\\Class","rt");
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(j=0;j<M;j++)
		{
			fscanf(fp,"%d\t",&p->score[j]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	n=0;
	while(p)
	{
		if(strcmp(na,p->sum)==0||strcmp(na,p->name)==0)
		{
			n++;
		}
		p=p->next;
	}
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	fp=fopen("d:\\Class","rt");
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(j=0;j<M;j++)
		{
			fscanf(fp,"%d\t",&p->score[j]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	if(n>=2)
	{		
		while(p)
		{
			if(strcmp(na,p->sum)==0||strcmp(na,p->name)==0)
			{	
				if(a==1)
				{
					printf1();
					printf2(2);
					printf("*                   是否对第%s位同学的信息进行删除           *\n",sum[a]);
					i=strlen(p->sum);
					j=strlen(p->name);
					printf("*                  学号为   %s   的  %s     同学             *\n",p->sum,p->name);
					for(n=0;n<M;n++)
					{
						i=(int)log10(p->score[n])+1;
						printf("*                  第%s科成绩:         %d                   *\n",sum[n],p->score[n]);
					}
					printfs("删除请输入一,返回主页面请输入零");
					printf2(7-M);
					printf1();
					a++;
					scanf("%d",&n);
					system("cls");
					switch(n)
					{
					case 1:
						close2(p->sum,p->name);
						break;
					case 2:one();
						break;
					}
					
				}
				if(a==0)
				{
					printf1();
					printf2(2);
					i=strlen(p->sum);
					j=strlen(p->name);
					printfs("查找到多人,这是第一位同学的信息");
					printf("*                    学号为%s的%s同学",p->sum,p->name);
					for(n=0;n<26-i-j;n++)
						printf(" ");
					printf("*\n");
					for(n=0;n<M;n++)
					{
						i=(int)log10(p->score[n])+1;
						printf("*               第%s科成绩:     %d",sum[n],p->score[n]);
						for(j=0;j<27-i;j++)
							printf(" ");
						printf("*\n");
					}
					printfs("删除请输入一,查看下一位,请输入二");
					printf2(7-M);
					printf1();
					scanf("%d",&n);
					system("cls");
					switch(n)
					{
					case 1:close2(p->sum,p->name);a=1;break;
					case 2:a=1;break;
					}
				}
				
			}
			p=p->next;
		}
	}
	else if(n==0)
	{
		printf1();
		printf2(5);
		printfs("未找到该学生");
		printfs("请检查输入信息");
		printfs("按任意键退出");
		printf2(4);
		printf1();
		system("pause");
		system("cls");
		one();
	}
	else
	{
		while(p)
		{
			if(strcmp(na,p->sum)==0||strcmp(na,p->name)==0)
			{	
				printf1();
				printf2(2);
				i=strlen(p->sum);
				j=strlen(p->name);
				printfs("是否对该学生的信息进行删除");
				printf("*                    学号为%s的%s同学",p->sum,p->name);
				for(n=0;n<26-i-j;n++)
					printf(" ");
				printf("*\n");
				for(n=0;n<M;n++)
				{
					i=(int)log10(p->score[n])+1;
					printf("*          第%s科成绩:          %d",sum[n],p->score[n]);
					for(j=0;j<27-i;j++)
					printf(" ");
					printf("*\n");
				}
				printfs("删除请输入一,取消删除请输入零");
				printf2(7-M);
				printf1();
				scanf("%d",&n);
				system("cls");
				switch(n)
				{
				case 1:close2(p->sum,p->name);
					break;
				case 0:close4();
					break;
				}
			}
			p=p->next;
		}
	}

}	
void close3()
{
	int n;
	system("cls");
	printf1();
	printf2(4);
	printfs("删除完成");
	printfs("是否继续删除学生信息");
	printfs("继续删除请输入一,返回主页请输入零");
	printf2(5);
	printf1();
	scanf("%d",&n);
	system("cls");
	switch(n)
	{
	case 1:
		close();
		break;
	case 0:
		one();
		break;
	}
}
void close4()
{
	int n;
	system("cls");
	printf1();
	printf2(4);
	printfs("完成取消删除");
	printfs("是否继续删除学生信息");
	printfs("继续删除请输入一,");
	printfs("返回主页请输入零");
	printf2(4);
	printf1();
	scanf("%d",&n);
	system("cls");
	switch(n)
	{
	case 1:close();break;
	case 0:one();break;
	}
}
				
void close2(char sum[20],char name[20])
{
	int i,j,n=0;
	char *sm[10]={"一","二","三","四","五","六","七","八","九","十"};
	NODE *head,*p;
	FILE *fp;
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	fp=fopen("d:\\Class","rt");
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(j=0;j<M;j++)
		{
			fscanf(fp,"%d\t",&p->score[j]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);	
	fp=fopen("d:\\Class","wt");
	while(p)
	{
		if(strcmp(sum,p->sum)==0&&strcmp(name,p->name)==0)
		{	
			printf1();
			printf2(5);
			printfs("请问你确认删除该学生的信息");
			printfs("删除请输入一,");
			printfs("取消删除请输入二");
			printf2(4);
			printf1();
			scanf("%d",&i);
			switch(i)
			{
			case 1:n=1;
				feof(fp);
				break;
			case 2:
				n=2;fprintf(fp,"%s\t%s\t",p->sum,p->name);
			for(i=0;i<M;i++)
				fprintf(fp,"%d\t",p->score[i]);
			fprintf(fp,"\n");
				break;
			}
		}
		else
		{
			fprintf(fp,"%s\t%s\t",p->sum,p->name);
			for(i=0;i<M;i++)
				fprintf(fp,"%d\t",p->score[i]);
			fprintf(fp,"\n");
		}
		p=p->next;
	}
	if(n==1)
		close3();
	if(n==2)
		close4();	
}
void close()
{
	char sn[20];
	printf1();
	printf2(5);
	printfs("请输入需要删除的学生信息");
	printfs("学号或姓名");
	printf2(5);
	printf1();
	scanf("%s",&sn);
	system("cls");
	close1(sn);
}
void mx()
{
	int i,n,j[M]={0},f,score[M]={0};
	char *sum[10]={"一","二","三","四","五","六","七","八","九","十"};
	FILE *fp;
	LIST head,p;
	fp=fopen("d:\\Class","rt");
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(i=0;i<M;i++)
		{
			fscanf(fp,"%d\t",&p->score[i]);
		}
		fscanf(fp,"\n");
		p->next=head->next;
		head->next=p;	
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	while(p)
	{
		for(i=0;i<M;i++)
		{
			if(p->score[i]>score[i])
				score[i]=p->score[i];
		}
		p=p->next;
	}
	fp=fopen("d:\\Class","rt");
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(i=0;i<M;i++)
		{
			fscanf(fp,"%d\t",&p->score[i]);
		}
		fscanf(fp,"\n");
		p->next=head->next;
		head->next=p;	
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	while(p)
	{
		for(i=0;i<M;i++)
		{
			if(p->score[i]==score[i])
				j[i]++;
				
		}
		p=p->next;
	}	
	printf1();
	printf2(2);
	for(n=0;n<M;n++)//第几科
	{
		i=strlen(sum[n])+(int)log10(score[n])+(int)log10(j[n])+2;
		printf("*  第%s科,最高分为%d,共%d名",sum[n],score[n],j[n]);
		for(f=0;f<36-i;f++)
			printf(" ");
		printf("*\n");
		printf("*  学号\t姓名\t");
		for(f=0;f<M;f++)
			printf("第%s科\t",sum[f]);
		printf("   *\n");
		for(i=0;i<j[n];i++)
		{
			fp=fopen("d:\\Class","rt");
			head=(LIST)malloc(sizeof(NODE));
			head->next=NULL;
			for(;;)
			{
				p=(LIST)malloc(sizeof(NODE));
				fscanf(fp,"%s\t%s\t",p->sum,p->name);
				for(i=0;i<M;i++)
				{
					fscanf(fp,"%d\t",&p->score[i]);
				}
				fscanf(fp,"\n");
				p->next=head->next;
				head->next=p;	
				if(feof(fp))
					break;
			}
			p=head->next;
			fclose(fp);
			while(p)
			{
				if(p->score[n]==score[n])
				{
					printf("*  %s\t%s\t",p->sum,p->name);
					for(f=0;f<M;f++)
						printf("%d\t",p->score[f]);
					printf("   *\n");
				}	
				p=p->next;
			}
		}
	}
	printf2(2);
	printf1();
	system("pause");
	system("clse");
	one();
}
void eve()
{
	int i,j=0,n[M]={0};
	float score[M]={0},score1[M];
	char *sum[10]={"一","二","三","四","五","六","七","八","九","十"};
	FILE *fp;
	LIST head,p;
	fp=fopen("d:\\Class","rt");
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(i=0;i<M;i++)
		{
			fscanf(fp,"%d\t",&p->score[i]);
		}
		fscanf(fp,"\n");
		p->next=head->next;
		head->next=p;	
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	while(p)
	{
		for(i=0;i<M;i++)
		{
			score[i]+=(float)p->score[i];
		}
		j++;
		p=p->next;
	}
	for(i=0;i<M;i++)
		score[i]/=(float)j;
	printf1();
	printf2(5);
	printf("*\t");
	for(i=0;i<M;i++)
		printf("第%s科\t",sum[i]);
	printf("\t   *\n*平均分\t");
	for(i=0;i<M;i++)
		printf("%.2f\t",score[i]);
	printf("\t   *\n");
		fp=fopen("d:\\Class","rt");
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(i=0;i<M;i++)
		{
			fscanf(fp,"%d\t",&p->score[i]);
		}
		fscanf(fp,"\n");
		p->next=head->next;
		head->next=p;	
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	while(p)
	{
		for(i=0;i<M;i++)
		{
			score1[i]=(float)p->score[i];
			if(score1[i]>score[i])
				n[i]++;
		}
		p=p->next;
	}
	printf("*人数\t");
	for(i=0;i<M;i++)
		printf("%d\t",n[i]);
	printf("\t   *\n");
	printf2(4);
	printf1();
	system("pause");
	system("cls");
	one();
}
void emit()
{
	int i,j,n=0;
	char sm[20],*sum[10]={"一","二","三","四","五","六","七","八","九","十"};
	FILE *fp;
	LIST head,p;
	fp=fopen("d:\\Class","rt");	
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(i=0;i<M;i++)
		{
			fscanf(fp,"%d\t",&p->score[i]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	printf1();
	printf2(5);
	printfs("请输入需要查找学生的信息");
	printfs("----学号或姓名----");
	printf2(5);
	printf1();
	scanf("%s",sm);
	system("cls");
	printf1();
	printf2(2);
	printf("*  学号\t姓名\t");
	for(i=0;i<M;i++)
	{
		printf("第%s科\t",sum[i]);
	}
	printf("   *\n");
	
	while(p)
	{
		if(strcmp(sm,p->sum)==0||strcmp(sm,p->name)==0)
		{
			i=0;
			n++;
			i=strlen(p->sum)+strlen(p->name);
			for(j=0;j<M;j++)
				i+=(int)log10(p->score[j]);
			printf("*   %s\t%s\t",p->sum,p->name);
			for(j=0;j<M;j++)
				printf(" %d\t",p->score[j]);
			printf("   *\n");
		}
		p=p->next;
	}
	printf2(9-n);
	printf1();
	system("pause");
	system("cls");
	one();
}
void line1();
void line2(LIST p)//找到最大的
{
	int i;
	char sum[20]={'\0'};
	LIST p1,head1;
	head1=(LIST)malloc(sizeof(NODE));
	head1->next=NULL;
	while(p)
	{
		p1=(LIST)malloc(sizeof(NODE));
		if(strcmp(p->sum,sum)==1)
		{
			strcpy(sum,p->sum);
		}
		strcpy(p1->sum,p->sum);
		strcpy(p1->name,p->name);
		for(i=0;i<M;i++)
		{
			p1->score[i]=p->score[i];
		}
		p1->next=head1->next;
		head1->next=p1;
		p=p->next;
	}
	p1=head1->next;
	line1(sum,p1);
}
void line1(char *sum,LIST p)//舍弃最大的
{
	int i,j,n;
	LIST p1,head1;
	head1=(LIST)malloc(sizeof(NODE));
	head1->next=NULL;
	while(p)
	{
		if(strcmp(sum,p->sum)!=0)
		{
			p1=(LIST)malloc(sizeof(NODE));
			strcpy(p1->sum,p->sum);
			strcpy(p1->name,p->name);
			for(i=0;i<M;i++)
			{
				p1->score[i]=p->score[i];
			}
			p1->next=head1->next;
			head1->next=p1;
		}
		else
		{
			i=0;
			n++;
			i=strlen(p->sum)+strlen(p->name);
			for(j=0;j<M;j++)
				i+=(int)log10(p->score[j]);
			printf("*   %s\t%s\t",p->sum,p->name);
			for(j=0;j<M;j++)
				printf(" %d\t",p->score[j]);
			printf("   *\n");
		}
		p=p->next;
	}
	p1=head1->next;
	if(p1==NULL)
		return;
	line2(p1);	
}
void line()//找出最大的
{
	char sum[20]={'\0'},name[20],*sm[10]={"一","二","三","四","五","六","七","八","九","十"};
	int score[M],i,n=0;
	FILE *fp;
	LIST p,head;
	fp=fopen("d:\\Class","rt");
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	for(;;)
	{
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(i=0;i<M;i++)
		{
			fscanf(fp,"%d\t",&p->score[i]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	while(p)
	{
		if(strcmp(p->sum,sum)>0)
		{
			strcpy(sum,p->sum);
			strcpy(name,p->name);
			for(i=0;i<M;i++)
			{
				score[i]=p->score[i];
			}
		}
		p=p->next;
	}	
	fp=fopen("d:\\Class","rt");
	head=(LIST)malloc(sizeof(NODE));
	head->next=NULL;
	for(;;)
	{
		n++;
		p=(LIST)malloc(sizeof(NODE));
		fscanf(fp,"%s\t%s\t",p->sum,p->name);
		for(i=0;i<M;i++)
		{
			fscanf(fp,"%d\t",&p->score[i]);
		}
		p->next=head->next;
		head->next=p;
		if(feof(fp))
			break;
	}
	p=head->next;
	fclose(fp);
	printf1();
	printf2(2);
	printf("*  学号\t姓名\t");
	for(i=0;i<M;i++)
	{
		printf("第%s科\t",sm[i]);
	}
	printf("   *\n");
	line1(sum,p);
	if(n<10)
		printf2(9-n);
	else
		printf2(2);
	printf1();
	system("pause");
	system("cls");
	one();
}
void error()
{
	printf1();
	printf2(5);
	printfs("指令错误");
	printfs("按任意键返回");
	printf2(5);
	printf1();
	system("pause");
	system("cls");
	one();
}
void statistics()
{
	int i;
	printf1();
	printf2(4);
	printfs("请选择,新的指令");
	printfs("指令一,显示每门课程成绩最高的学生的基本信息");
	printfs("指令二,显示每门课程的平均成绩,            ");
	printfs("        并且超过某门课程平均成绩的学生人数 .");
	printfs("指令零,返回主页面");
	printf2(3);
	printf1();
	scanf("%d",&i);
	system("cls");
	switch(i)
	{
	case 0:one();
		break;
	case 1:mx();
		break;
	case 2:eve();
		break;
	default:error();
		statistics();
		break;
	}
}
void one()
{
	int i=0;
	printf1();
	printf2(2);
	printfs("请选择,您需要执行的指令");
	printfs("指令一,添加学生信息");
	printfs("指令二,更改学生信息");
	printfs("指令三,查询学生信息");
	printfs("指令四,删除学生信息");
	printfs("指令五,显示学生信息");
	printfs("指令六,统计输出信息");
	printfs("指令零,关闭系统");
	printf2(1);
	printfs("对应的指令数,请输入对应的阿拉伯数字");
	printf1();
	scanf("%d",&i);
	system("cls");
	switch(i)
	{
	case 0:exit(0);
		break;
	case 1:add();
		break;
	case 2:changes();
		break;
	case 3:emit();
		break;
	case 4:close();
		break;
	case 5:line();
		break;
	case 6:statistics();
		break;
	default:error();
		one();
		break;
	}
}
int main()
{
	password();
	open();
	one();
}

密码是123456

©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页