链表实现学生录入系统

今天老师布置实训作业在这里插入图片描述
感觉很简单自己加了几个。操作分享给大家若有不足请多多包含!!!
在这里插入图片描述

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include<windows.h> 
void show();//显示菜单 
void entering();//录入学生信息 
void find();//查找学生信息 
void Delete();//删除学生信息 
void modify();//修改学生信息 
void sort();//成绩排序 
void add();//增加学生信息 
void math();//数学单科排序 
void chinese();//语文单科排序 
void english(); //英语单科排序 
void copty();//打印学生信息成文本 
struct student
{
	char name[20];
	char student_id[10];
	int math;
	int chinese;
	int  english;
	int score;
	struct student *next;
 };
 struct student *p,*head,*tail;
 int n;
int main()
{
	system("title,学生信息录入系统");
	int a,b=0;
	int aa;
	while(1)
	{
		show();
		scanf("%d",&a);
		switch(a)
		{
			case 1:	
					entering();
					break;
			case 2:
					find();
					break;
			case 3:
					Delete();
					break;
			case 4:
					modify();
					break;
			case 5:
					sort();
					break;
			case 6:
					add();
					break;
			case 7:
					system("cls");
					printf("\t\t\t\t\t**********************************\n");
					printf("\t\t\t\t\t************1.语文****************\n");
					printf("\t\t\t\t\t************2.数学****************\n");	
					printf("\t\t\t\t\t************3.英语****************\n");	
					printf("\t\t\t\t\t**********************************\n");
					scanf("%d",&aa);
					switch(aa)
					{
						case 1:
								chinese();
								break;
						case 2:
								math();
								break;
						case 3:
								english();
								break;
								
					} break;			
			case 8:
					copty();
					break;
			case 9:
					 b=1;
					 break;		
		}
		fflush(stdin);
		system("cls");
		if(b==1) break;	
	}
}
void show()
{
	printf("\t\t\t\t\t**************************************\n");
	printf("\t\t\t\t\t**************1.录入学生信息**********\n");
	printf("\t\t\t\t\t**************2.查找学生信息**********\n"); 
	printf("\t\t\t\t\t**************3.删除学生信息**********\n");
	printf("\t\t\t\t\t**************4.修改学生信息**********\n");
	printf("\t\t\t\t\t**************5.学生成绩排序**********\n");
	printf("\t\t\t\t\t**************6.增加学生信息**********\n");
	printf("\t\t\t\t\t**************7.单课成绩排序**********\n");
	printf("\t\t\t\t\t**************8.打印学生信息成文本****\n");
	printf("\t\t\t\t\t**************9.退出该系统  **********\n");
	printf("\t\t\t\t\t**************************************\n"); 
}
void entering()
{
	int i;
	printf("请输入您要录入学生的个数\n");
	scanf("%d",&n);
	fflush(stdin);
	p=(struct student*)malloc(sizeof(struct student));
	printf("姓名:");
	scanf("%s",p->name);
	printf("学号:");
	scanf("%s",p->student_id);
	printf("语文:"); 
	scanf("%d",&p->chinese);
	printf("数学:");
	scanf("%d",&p->math);
	printf("英语:");
	scanf("%d",&p->english);
	p->score=p->chinese+p->english+p->math;
	p->next=NULL;
	head=tail=p;
	for(i=1;i<n;i++)
	{
		p=(struct student*)malloc(sizeof(struct student));
		printf("姓名:");
		scanf("%s",p->name);
		fflush(stdin);
		printf("学号:");
		scanf("%s",p->student_id);
		printf("语文:"); 
		scanf("%d",&p->chinese);
		printf("数学:");
		scanf("%d",&p->math);
		printf("英语");
		scanf("%d",&p->english);
		p->score=p->chinese+p->english+p->math;
		p->next=head;
		head=p;
	}
	printf("录入成功!!! ");
	system("pause");
}
void find()
{
	char Name[20];
	int a=0;
	printf("请输入您要查找的学生姓名:\n");
	fflush(stdin);
	gets(Name);
	while(p!=NULL)
	{
		if(strcmp(Name,p->name)==0)
		{
			printf("姓名\t学号\t语文\t数学\t英语\n");
			printf("%s\t",p->name);
			printf("%s\t",p->student_id);
			printf("%d\t",p->chinese);
			printf("%d\t",p->math);
			printf("%d\n",p->english);
			a=1;
		}
		p=p->next;
	}
	if(a==0) printf("查无此人");
	p=head; 
	system("pause");
}
void Delete()
{
	char Name[10];
	int i=0;
	struct student *before,*now;
	printf("请输入您要删除的学生姓名\n");
	fflush(stdin);
	scanf("%s",Name);
	while(p!=NULL)
	{
		if(strcmp(Name,p->name)==0)
		{
			before->next=p->next;
			now=p;
			i=1;
		}
		before=p;
		p=p->next;
	}
	if(i==0)
	{
		printf("查无此人\n");
	}
	else
	{
		n=n-1;
	}
	free(now);
	p=head;
	printf("删除完成");
	system("pause");
	
}
void modify()
{
	char Name[20];
	int j=0;
	printf("请输入您要修改的学生姓名:\n");
	fflush(stdin);
	gets(Name);
	while(p!=NULL)
	{
		if(strcmp(Name,p->name)==0)
		{
			printf("姓名\t学号\t语文\t数学\t英语\n");
			printf("%s\t",p->name);
			printf("%s\t",p->student_id);
			printf("%d\t",p->chinese);
			printf("%d\t",p->math);
			printf("%d\n",p->english);
			printf("请输入修改后的成绩\n");
			printf("语文:");
			scanf("%d",&p->chinese) ;
			printf("数学:");
			scanf("%d",&p->math);
			printf("英语:");
			scanf("%d",&p->english); 
			printf("修改完成");
			system("pause");
			j=1;
			
		}
		p=p->next;
	}
	if(j==1)
	{
		printf("查无此人\n");
	}
	p=head;
 } 
void sort()
{	
	struct student *q,t,*temp;
	int i ,j;
	q=p;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(p->score>q->score)
			{
				t=*p;
				*p=*q;
				*q=t;
				temp=p->next;
				p->next=q->next;
				q->next=temp;	
			}
			q=q->next;
		}
		p=p->next;
		q=head;
	} 
	p=head;
	printf("姓名\t学号\t语文\t数学\t英语\t总分\n");
	while(p!=NULL)
	{
			printf("%s\t",p->name);
			printf("%s\t",p->student_id);
			printf("%d\t",p->chinese);
			printf("%d\t",p->math);
			printf("%d\t",p->english);
			printf("%d\n",p->score);
			p=p->next;
	}
	p=head;
	system("pause");
 } 
void add()
{
	int s;
	printf("请输入你要添加学生个数");
	scanf("%d",&s);
	for(int i=0;i<s;i++)
	{
		p=(struct student*)malloc(sizeof(struct student));
		printf("姓名:");
		scanf("%s",p->name);
		fflush(stdin);
		printf("学号:");
		scanf("%s",p->student_id);
		printf("语文:"); 
		scanf("%d",&p->chinese);
		printf("数学:");
		scanf("%d",&p->math);
		printf("英语");
		scanf("%d",&p->english);
		p->score=p->chinese+p->english+p->math;
		p->next=head;
		head=p;
		
	}
	 n=n+s;
}
void math()
{
		struct student *q,t,*temp;
	int i ,j;
	q=p;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(p->math>q->math)
			{
				t=*p;
				*p=*q;
				*q=t;
				temp=p->next;
				p->next=q->next;
				q->next=temp;	
			}
			q=q->next;
		}
		p=p->next;
		q=head;
	} 
	p=head;
	printf("姓名\t学号\t数学\n");
	while(p!=NULL)
	{
			printf("%s\t",p->name);
			printf("%s\t",p->student_id);
			printf("%d\n",p->math);
			p=p->next;
	}
	p=head;
	system("pause");
 } 
void chinese()
{
		struct student *q,t,*temp;
	int i ,j;
	q=p;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(p->chinese>q->chinese)
			{
				t=*p;
				*p=*q;
				*q=t;
				temp=p->next;
				p->next=q->next;
				q->next=temp;	
			}
			q=q->next;
		}
		p=p->next;
		q=head;
	} 
	p=head;
	printf("姓名\t学号\t语文\n");
	while(p!=NULL)
	{
			printf("%s\t",p->name);
			printf("%s\t",p->student_id);
			printf("%d\n",p->chinese);
			p=p->next;
	}
	p=head;
	system("pause");
 } 
void english()
{
		struct student *q,t,*temp;
	int i ,j;
	q=p;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(p->english>q->english)
			{
				t=*p;
				*p=*q;
				*q=t;
				temp=p->next;
				p->next=q->next;
				q->next=temp;	
			}
			q=q->next;
		}
		p=p->next;
		q=head;
	} 
	p=head;
	printf("姓名\t学号\t英语\n");
	while(p!=NULL)
	{
			printf("%s\t",p->name);
			printf("%s\t",p->student_id);
			printf("%d\n",p->english);
			p=p->next;
	}
	p=head;
	system("pause");
 } 
void copty()
 {
 	FILE *fs;
	fs=fopen("D://成绩排名.txt","wb");
	if(fs==NULL) 
	{
		printf("can not the file!\n");
		exit(1);	
	}
	char aaa[]="姓名	学号	语文	数学	英语"; 
	fprintf(fs,"%s\n\r\n",aaa);	
	while(p!=NULL)
	{
		fprintf(fs,"%s\t%s\t%d\t%d\t%d\n\r\n",p->name,p->student_id,p->chinese,p->math,p->english);
		p=p->next;
	}
	printf("你的文件已经保存了在D盘中文件名为:成绩排名\n");
	fclose(fs);
	system("pause");
	p=head;
 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值