简易学生成绩管理(C语言)

//在Dev-C++上编译通过
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
#define LEN sizeof(struct student)

struct student
{
	int num;
	float score;
	float score1;
	float score2;
	float score3;
	char name[20];
	struct student *next;
};
int n;
struct student *creat(struct student *head)
{
	
	struct  student *p1=(struct student*)malloc(LEN);
	printf("请输入学号:\n");
	scanf("%d",&p1->num);
	printf("请输入姓名:\n");
	scanf("%s",&p1->name);
	printf("\n请输入高数成绩:\n");
	scanf("%f",&p1->score);	
	printf("\n请输入C语言成绩:\n");
	scanf("%f",&p1->score1);
	printf("\n请输入英语成绩:\n");
	scanf("%f",&p1->score2);
	p1->score3=p1->score1+p1->score+p1->score2;	
	int b=0;struct student *p2;
	struct student *p3=(struct student*)malloc(LEN);;
	p2=p3=head;
	int a,c;
	while(p3)
	{
		p3=p3->next;
	}	
	if(head==NULL)	p2=head=p1;
	else
	{
		while(p2->next)
		{
		
			p2=p2->next;
	
	 	}
	}
	p2->next=p1;
	p1->next=NULL;
	return head;
}
struct student *change(struct student *head)
{
	struct student *p1,*p2; 
	p2=(struct student *)malloc(LEN);
	printf("请输入学号:\n");
	scanf("%d",&p2->num);
	printf("请输入姓名:\n");
	scanf("%s",&p2->name);
	printf("\n请输入高数成绩:\n");
	scanf("%f",&p2->score);	
	printf("\n请输入C语言成绩:\n");
	scanf("%f",&p2->score1);
	printf("\n请输入英语成绩:\n");
	scanf("%f",&p2->score2);
	p2->score3=(p2->score1+p2->score+p2->score2)/3;
	p1=head;
	while(p1->num!=p2->num&&p1->num!=NULL)
	{
		p2=p1;
		p1=p1->next;
	}
	if(p2->num==p1->num)
	{
		if(p1==head) head=p1->next;
		else         p2->next=p1->next;
		
	
	}
	
	struct student *p3;
	p3=head;
	int a,c;
		
	if(head==NULL)	head=p2;
	else
	{
		while(p3)
		{
			p3=p3->next;
		}
		p3->next=p2;
		
	}
	p2->next=NULL;
	 printf("修改成功");
	return head;

}

void print(struct student *head)
{
	struct student *p;
	p=head;
	if(head)
	{
		while(p)
		{
			printf("学号\t姓名\t高数\tC语言\t英语\t总分\n",p->num,p->name,p->score);
			printf("%d	%s	%.2f	%.2f	%.2f    %.2f\n",p->num,p->name,p->score,p->score1,p->score2,p->score3);
			p=p->next;
		}
	}
 } 
struct student *del(struct student *head)
{
	struct student *p1,*p2;
	int num;
	printf("\n请输入需要删除的学号:");
	scanf("%d",&num);
	if(head==NULL)
	{
		printf("\nTfis list is null!\n");
		goto end;
	}
	p1=head;
	while(p1->num!=num&&p1->num!=NULL)
	{
		p2=p1;
		p1=p1->next;
	}
	if(num==p1->num)
	{
		if(p1==head) head=p1->next;
		else         p2->next=p1->next;
		printf("删除成功!!");
		n=n-1;
	}
	else printf("%d not been found!\n",num);
	return head; 
	end:return head;
}

void find(struct student *head)
{
	int c=0,num;
	struct student *p1,*p2;
	printf("\n请输入与要查找的学号:");
	scanf("%d",&num);
	if(head==NULL) printf("\nTfis list is null!\n");
	else
	{
		p1=head;
		while(p1)
		{
			if(p1->num!=num)
			{
				p1=p1->next;
			}	
			else
			{
				printf("学号\t姓名\t高数\tC语言\t英语\t总分\n");
				printf("%d	%s	%.2f	%.2f	%.2f    %.2f\n",p1->num,p1->name,p1->score,p1->score1,p1->score2,p1->score3);
				c=1;break;
			}	
		}
		if(c==0)
		{
			system("color 4");
			printf("没有你所要查找的学生请重新选择!!!");
		}
	}
}
void find1(struct student *head)
{
	int c=0,num;
	char name[20];
	struct student *p1,*p2;
	printf("\n请输入与要查找的姓名:");
	scanf("%s",&name);
	if(head==NULL) printf("\nTfis list is null!\n");
	else
	{
		p1=head;
		while(p1)
		{
			if(strcmp(p1->name,name)!=0)
			{
				p1=p1->next;
			}	
			else
			{
				printf("学号\t姓名\t高数\tC语言\t英语\t总分\n");
				printf("%d	%s	%.2f	%.2f	%.2f    %.2f\n",p1->num,p1->name,p1->score,p1->score1,p1->score2,p1->score3);
				c=1;break;
			}	
		}
		if(c==0)
		{
			system("color 4");
			printf("没有你所要查找的学生请重新选择!!!");
		}
	}
}

struct student *sort(struct student *head)  //高数成绩排序 
{
	student *p1,*p2,*p3;
	int n; 
	p1=head; 
	n=1; 
	while(p1->next) 
	{ n++; p1=p1->next; } 
	
	int i; 
	p1=head; 
	for(i=1;i<n;i++) 
	{ 
		p1=head; 
		if (p1->score3<p1->next->score3) // 如果头结点大于第二个的 
		{ 
			p2=p1->next; 
			p1->next=p1->next->next; 
			p2->next=p1; //头结点交换 
			head=p2; 
		} 
		p1=head; 
		while(p1->next->next) //中间的交换 
		{ 
			p2=p1; 
			p1=p1->next; 
			if(p1->score3<p1->next->score3) 
			{ 
				p2->next=p1->next; 
				p1->next=p1->next->next; 
				p2->next->next=p1; 
				p1=p2->next; //交换 
			} 
		} 
	} 
	print(head);
		return head; 
} 

void count(struct student *head)
{
	student *p1,*p2,*p3;
	int a=0,b=0,c=0,d=0; 
	p1=head; 
	while(p1->next) 
	{ 
	    if(p1->score3>=270) a++;
	    if(p1->score3>=240&&p1->score3<=270) b++;
	    if(p1->score3>=180&&p1->score3<=240) c++;
	    if(p1->score3<180) d++;
		p1=p1->next; 
	} 
	printf("优,良,中,差的人分别有:%d  %d  %d  %d",a,b,c,d)	;
}
void save(struct student *head)
{
	struct student *p;
  	p=head;
  	FILE*fp = fopen("101.txt","w+");
	if(fp!=NULL)
	{
		while(p!=NULL)
		{
   		    fprintf(fp,"%d\t%s\t%f\t%f\t%f\t%f\n",p->num,p->name,p->score,p->score1,p->score2,p->score3);
   			p=p->next;
  			printf("保存成功!\n");
  		}
	}
	fclose(fp); 
}
int choose()
{
	int a,d,num2,score2,n;
	struct student *stu_2,*head;
	head=NULL;
	while(true)
	{
		system("color 6");
		printf("请选择你所需要的操作\n");
		printf("\t\t\t\t\t\t****************************\n");
		printf("\t\t\t\t\t\t*\t1.创建数据         *\n");
		
		printf("\t\t\t\t\t\t*\t2.学号查找         *\n");
		printf("\t\t\t\t\t\t*\t3.姓名查找         *\n");
		
		
		printf("\t\t\t\t\t\t*\t4.排序             *\n");
		printf("\t\t\t\t\t\t*\t5.统计             *\n");
		printf("\t\t\t\t\t\t*\t6.存入文件         *\n");
		printf("\t\t\t\t\t\t*\t7.输出数据         *\n");
		printf("\t\t\t\t\t\t*\t8.删除             *\n");
		printf("\t\t\t\t\t\t*\t9.修改             *\n");
		printf("\t\t\t\t\t\t*\t10.退出程序        *\n");		
		printf("\t\t\t\t\t\t****************************\n");
		scanf("%d",&a);
		fflush(stdin);
		switch(a)
		{
			case 3:find1(head);break; 
			case 2:find(head);break;
			case 4:head=sort(head);break; 
			case 5:count(head);break;
			case 6:save(head);break;
			case 7:print(head);break;
			case 1:head=creat(head);break;
			case 8:head=del(head);break;
			case 9:head=change(head);break;
			case 10:exit(0);break;
			
		}
	}
}

int main()
{
	choose();
		
}










初始界面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值