C语言实现项目---学期评优方案

前言

一位地大的朋友面临一个复杂的课设找我寻求帮助,而我呢,面临期末,压力巨大,一边复习一边带着做,想着做完发篇博客。终于,昨天考完了最后一门,熬夜把项目给写了出来,但是还需要很大的优化,因为时间仓促,基本功能已经可以体现。

题目

 已知文本文件f1.txt中存放了某校若干名大一学生的相关信息(不超过5000人),具体数据及存放格式为:每行存放一个学生的数据,数据之间用空格分隔,共有11项,依次为:学号、姓名、专业编号、通识教育课一、通识教育课二、通识教育课三、公共基础课一、公共基础课二、公共基础课三、专业主干课一、专业主干课二等8门课程的成绩。其中,学号为5位数字字符;姓名为长度不超过10个的字符;专业编号为二位数字字符,编号从01-50;所有课程成绩均为0-100的整数。(具体功能见附件)

相关资料放入附件里。

代码

#include<stdio.h>
#include<string.h>
#include<stdlib.h> 
#define N 5000			//总学生数 
#define M 50			//专业 

struct student
{
	char num[6];
	char name[20];
	char major[3];
	int score1;
	int score2;
	int score3;
	int score4;
	int score5;
	int score6;
	int score7;
	int score8;
	int total;
	bool estu1;		//是否是校级优秀学生 
	bool estu2;		//是否是专业优秀学生 	
};

struct student st[N];
char majorinfo[M][3] = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50"};
int nummajor[M] = {0};


void mysort()			//按总评成绩冒泡排序 
{	
	bool change;
	int i,j;
	change=true;
	for(i=0;i<N&&change;++i)
	{
		change=false;
		for(j=0;j<N;++j)
		{
			if(st[i].total > st[j].total)
			{
				struct student top = st[i];
				st[i] = st[j];
				st[j] = top;
				change=true;
			}
		}
	}
}


//校级优秀学生 
void excellent1(){
	int i=0,j=0;
	FILE *fp2;
	if((fp2=fopen("f2.txt","w"))==NULL)
 	{
    	printf("数据有误!");
	}else{
		while(j<N*0.05){
			if(st[i].score1>=60&&st[i].score2>=60&&st[i].score3>=60&&st[i].score4>=70&&st[i].score5>=70&&st[i].score6>=70&&st[i].score7>=80&&st[i].score8>=80){	
				st[i].estu1 = true;
				fprintf(fp2,"%s %s %s %d %d %d %d %d %d %d %d %d\n",st[i].num,st[i].name,st[i].major,st[i].score1,st[i].score2,st[i].score3,st[i].score4,st[i].score5,st[i].score6,st[i].score7,st[i].score8,st[i].total);
				j++;
			}
			i++;	
		}
	}
	printf("校级优秀学生信息已放入f2.txt中!\n");
	fclose(fp2);
}

int main(){
	printf("请喝杯茶等候片刻~~");
	FILE *fp;
	int i=0,j,max=0,k,l=0;
	int arr[M]={0};		//存放各专业获得校级优秀学生的人数
	int brr[M]={0};		//专业优秀的人数 
	int crr[M]={0};		//专业校级优秀学生人数
	int drr[M]={0}; 	//专业不具有资格的 
	int err[8]={0};		//分析 
	
	if((fp=fopen("f1.txt","r"))==NULL){
		printf("查询不到数据!");
	}else{
		while(!feof(fp)){
			fscanf(fp,"%s%s%s%d%d%d%d%d%d%d%d",st[i].num,st[i].name,st[i].major,&st[i].score1,&st[i].score2,&st[i].score3,&st[i].score4,&st[i].score5,&st[i].score6,&st[i].score7,&st[i].score8);
			st[i].total = (int)(0.8*(st[i].score4+st[i].score5+st[i].score6)+1.2*(st[i].score7+st[i].score8));
			for(j=0;j<M;j++){
				if(strcmp(majorinfo[j],st[i].major)==0){
					nummajor[j]++;
				}
			}
			i++;
		}
	}
	
	mysort();
	system("cls");
	FILE *fp1;			//获取s1 
	if((fp1=fopen("s1.txt","w"))==NULL)
 	{
    	printf("数据有误!");
	}else{
    	for(i=0;strlen(st[i].name)!=0;i++)		//没有考分的部分要标注防止录不了数据 
		{
			fprintf(fp1,"%s %s %s %d %d %d %d %d %d %d %d %d\n",st[i].num,st[i].name,st[i].major,st[i].score1,st[i].score2,st[i].score3,st[i].score4,st[i].score5,st[i].score6,st[i].score7,st[i].score8,st[i].total);
	  	}
	}
	printf("排序后的总成绩表已放入s1.txt中!\n");	

	struct student maj[200];		//专业符合排名的学生 
	for(i=0;i<M;i++){
		k=0;
		for(j=0;j<N;j++){
			if(strcmp(majorinfo[i],st[j].major)==0){
				if(st[j].score1>=60&&st[j].score2>=60&&st[j].score3>=60&&st[j].score4>=70&&st[j].score5>=70&&st[j].score6>=70&&st[j].score7>=80&&st[j].score8>=80){
					maj[k]=st[j]; 
					k++;
				}
			}
		}
		brr[i]=k;
		max=0;
		for(l=0;l<N;l++){
			if(max<(int)((double)k*0.1+0.5)){
				if(strcmp(majorinfo[i],st[l].major)==0){
					if(st[l].score1>=60&&st[l].score2>=60&&st[l].score3>=60&&st[l].score4>=70&&st[l].score5>=70&&st[l].score6>=70&&st[l].score7>=80&&st[l].score8>=80){
						st[l].estu2 = true;
						max++; 
					}
				}
			}
		}  
		l=0;
		FILE *fp3;
		if((fp3=fopen("f3.txt","a"))==NULL)
	 	{	
		   	printf("数据有误!");
		}else{
	    	while(l<(int)((double)k*0.1+0.5)){		//没有考分的部分要标注防止录不了数据 	
				fprintf(fp3,"%s %s %s %d %d %d %d %d %d %d %d %d\n",maj[l].num,maj[l].name,maj[l].major,maj[l].score1,maj[l].score2,maj[l].score3,maj[l].score4,maj[l].score5,maj[l].score6,maj[l].score7,maj[l].score8,maj[l].total);	  	
				l++;					
			}			
		}
		fclose(fp3);
	} 
	
	printf("专业优秀学生信息已放入f3.txt中!\n"); 
	excellent1();	//校级优秀学生 
	fclose(fp);
	fclose(fp1);
	
	 
	int n;
	bool truth = true;
	//功能部分 
	while(truth){
		printf("请选择您的操作:\n");
		printf("(1) 生成校级优秀学生的评优成绩。\n"); 
		printf("(2) 生成各个专业的专业优秀学生的评优成绩。\n");
		printf("(3) 统计各个专业校级优秀学生的人数。\n");
		printf("(4) 统计没有校级优秀学生的专业信息。\n");
		printf("(5) 统计校级优秀学生人数最多的专业信息。\n");
		printf("(6) 统计各专业不具备评优资格的人数。\n");
		printf("(7) 统计不具备评优资格人数最多的专业信息。\n");
		printf("(8) 统计各个专业优秀学生的人数。\n");
		printf("(9) 统计各个专业优秀学生的信息。\n");
		printf("(10) 根据学生输入的学号及姓名,查询本人的评优结果。\n(如果输入的学号与姓名不匹配,提示错误信息。如果只输入一项信息,禁止查询。)\n");
		printf("(11) 分析出不具备校级优秀评选资格的各因素所点的比重以及最主要原因。\n");
		printf("(12) 退出程序。\n\n\n"); 
		printf("输入数字序号:");
		scanf("%d",&n);
		
		if(n<=12&&n>=1){
			switch(n){
				case 1:
					i=0,j=0;
					FILE *fp2;
					if((fp2=fopen("option1.txt","w"))==NULL)
				 	{
				    	printf("数据有误!");
					}else{
						while(j<N*0.05){
							if(st[i].score1>=60&&st[i].score2>=60&&st[i].score3>=60&&st[i].score4>=70&&st[i].score5>=70&&st[i].score6>=70&&st[i].score7>=80&&st[i].score8>=80){	
								fprintf(fp2,"学号:%s   姓名:%s   专业:%s   评优成绩:%d\n",st[i].num,st[i].name,st[i].major,st[i].total);
								j++;
							}
							i++;	
						}
					}
					fclose(fp2);
					printf("数据已放入option1.txt中!\n");
					printf("---------------------------\n\n\n\n");
					break;
				
				case 2: 
					FILE *fp5;
					if((fp5=fopen("option2.txt","w"))==NULL)
				 	{
				    	printf("数据有误!");
					}else{
							for(i=0;i<M;i++){
								for(j=0;j<N;j++){
									if(strcmp(majorinfo[i],st[j].major)==0){
										if(st[j].estu2==true){
											fprintf(fp5,"学号:%s   姓名:%s   专业:%s   评优成绩:%d\n",st[j].num,st[j].name,st[j].major,st[j].total);
										}
									}
								}
							}
					}
					fclose(fp5);
					
					printf("专业优秀学生的评优成绩已放入option2.txt中!\n");
					printf("---------------------------\n\n\n\n");
					break;
					
				case 3:
					i=0,j=0;
					while(j<N*0.05){
						if(st[i].score1>=60&&st[i].score2>=60&&st[i].score3>=60&&st[i].score4>=70&&st[i].score5>=70&&st[i].score6>=70&&st[i].score7>=80&&st[i].score8>=80){	
							for(k=0;k<M;k++){
								if(strcmp(st[i].major,majorinfo[k])==0){
									arr[k]++;
								}
							}
							j++;	
						}
						i++;	
					}
					
					
					printf("各个专业校级优秀学生的人数分别为:\n");
					for(i=0;i<M;i++){
						printf("专业%d的人数为:%d\n",i+1,arr[i]);
					}					
					
					printf("---------------------------\n\n\n\n");	
					break;
					
				case 4:
					i=0;
					FILE *fp4;
					if((fp4=fopen("option4.txt","a"))==NULL)
				 	{
				    	printf("数据有误!");
					}else{	
						for(i=0;strlen(st[i].name)!=0;i++){
							if(st[i].estu1==false){
								fprintf(fp4,"学号:%s   姓名:%s   专业:%s   评优成绩:%d\n",st[i].num,st[i].name,st[i].major,st[i].total);
							}
						}
					}			
					fclose(fp4);
					printf("统计成功!数据已放入option4.txt!\n");
					printf("---------------------------\n\n\n\n");
					break;
					
				case 5:
					for(i=0;i<M;i++){
						for(j=0;j<N;j++){
							if(strcmp(majorinfo[i],st[j].major)==0){
								if(st[j].estu1==true){
									crr[i]++;
								}
							}
						}
					}
					for(i=0;i<M;i++){
						j= j+crr[i];
						printf("专业%d的校级优秀学生数为:%d\n",i+1,crr[i]);
					}
					printf("---------------------------\n\n\n\n");				 
				 	break;
				 	
				case 6:
					for(j=0;j<M;j++){
						for(i=0;i<N;i++){
							if(strcmp(majorinfo[j],st[i].major)==0){
								if(!(st[i].score1>=60&&st[i].score2>=60&&st[i].score3>=60&&st[i].score4>=70&&st[i].score5>=70&&st[i].score6>=70&&st[i].score7>=80&&st[i].score8>=80)){
									drr[j]++;
								}
							}
						}
					}
					
					for(i=0;i<M;i++){
						printf("%d专业有%d人没有评选资格;\n",i+1,drr[i]);
					}
					printf("---------------------------\n\n\n\n");
					break;
					
				case 7:
					for(j=0;j<M;j++){
						for(i=0;i<N;i++){
							if(strcmp(majorinfo[j],st[i].major)==0){
								if(!(st[i].score1>=60&&st[i].score2>=60&&st[i].score3>=60&&st[i].score4>=70&&st[i].score5>=70&&st[i].score6>=70&&st[i].score7>=80&&st[i].score8>=80)){
									drr[j]++;
								}
							}
						}
					}
					j=0,l=0;
					for(i=0;i<M;i++){
						if(j<drr[i]){
							j=drr[i];
							l=i;
						}
					}
					printf("不具备评优资格人数最多的专业为:%d,有%d人。\n",l+1,drr[l]);
					
					printf("---------------------------\n\n\n\n");
					printf("---------------------------\n\n\n\n");
					break;
					
				case 8:
					for(i=0;i<M;i++){
						printf("%d专业有%d个专业优秀学生;\n",i+1,brr[i]);
					}
					printf("---------------------------\n\n\n\n");
					break; 
					
				case 9:
					FILE *fp6;
					if((fp6=fopen("option9.txt","a"))==NULL)
				 	{
				    	printf("数据有误!");
					}else{	
						for(j=0;j<M;j++){
							for(i=0;i<N;i++){
								if(strcmp(majorinfo[j],st[i].major)==0){
									if(st[i].estu2==true){
										fprintf(fp6,"学号:%s   姓名:%s   专业:%s   评优成绩:%d\n",st[i].num,st[i].name,st[i].major,st[i].total);
									}
								}
							}
						}		
					}			
					fclose(fp6);
					
					printf("各个专业优秀学生的信息已放入option9.txt中!\n");
					printf("---------------------------\n\n\n\n");
					break;
					
				case 10:
					char name0[20];
					char num0[6];
					printf("请输入要查询的姓名:");
					scanf("%s",&name0);
					printf("请输入要查询的学号:");
					scanf("%s",&num0);
					bool sured;
					for(i=0;i<N;i++){
						if(!strcmp(st[i].num,num0)&&!strcmp(st[i].name,name0)){
							if(st[i].estu1==true&&st[i].estu2==false){
								printf("%s同学是校级优秀学生!\n",st[i].name);
								sured = true;
							}
							else if(st[i].estu1==false&&st[i].estu2==true){
								printf("%s同学是专业优秀学生!\n",st[i].name);
								sured = true;
							}
							else if(st[i].estu1==true&&st[i].estu2==true){
								printf("%s同学既是校级优秀学生,又是专业优秀学生!\n",st[i].name);
								sured = true;
							}
						}
					}
					if(sured==false){
						printf("输入信息错误!\n");
					}
					printf("---------------------------\n\n\n\n");
					break;
					
				case 11:
					for(i=0;strlen(st[i].name)!=0;i++){
						if(st[i].score1<60){
							err[0]++;
						}
						if(st[i].score2<60){
							err[1]++;
						}
						if(st[i].score3<60)
						{
							err[2]++;
						}
						if(st[i].score4<70)
						{
							err[3]++;
						}
						if(st[i].score5<70)
						{
							err[4]++;
						}
						if(st[i].score6<70)
						{
							err[5]++;
						}
						if(st[i].score7<80)
						{
							err[6]++;
						}
						if(st[i].score8<80) 
						{
							err[7]++;
						}
					}
					
					int m1,m2,m3,h;		//三种课的平均值 
					m1=(err[0]+err[1]+err[2])/3;
					m2=(err[3]+err[4]+err[5])/3;
					m3=(err[6]+err[7])/2;
					
					if(m1>m2){
						if(m1>m3){
							printf("通识教育课程挂科率太高,需要加强通识教育。\n");
						}else if(m1<m3){
							printf("专业主干课程挂科率太高,需要加强专业课教育。\n");
						}
					}else if(m1<m2){
						if(m2>m3){
							printf("公共基础课挂科率太高,需要加强公共教育。\n");
						}else if(m2<m3){
							printf("专业主干课程挂科率太高,需要加强专业课教育。\n");
						}
					}
					printf("输入1查看各课程挂科数,退出请输入0!\n");
					scanf("%d",&h);
					if(h==1){
						for(i=0;i<8;i++){
							printf("第%d门课的挂科数:%d\n",i+1,err[i]);
						}
					}else if(h==0){
						break;
					} 
					
					printf("---------------------------\n\n\n\n");
					break;
					
				case 12:
					truth = false;
					printf("已退出程序,请关闭窗口!");
					break;
			}
		}else{
			printf("请输入正确的数字!");
		} 
	}
	
	
	
	
	return 0;
}



效果演示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

发布了10 篇原创文章 · 获赞 32 · 访问量 2366

猜你喜欢

转载自blog.csdn.net/qq_34533266/article/details/103832291
今日推荐