C语言链表模板,学生管理系统(链表数据写入文本) 。

链接:《c语言项目》学生成绩管理系统(devc++)

链表,学生管理系统(链表数据写入文本) 模板。

示例代码:



#include<stdio.h>
#include<stdlib.h>
#define N 4
//输入到文件的函数
void file(struct node*head);
//创建节点函数
struct node*fun();
//删除函数
void del(struct node*);
//查找函数
void find(struct node*);
//全部输出函数
struct node*output(struct node*);

 struct node
{
	int date;
	int score;
	char name[10];
	struct node *next;
};
 //首页函数
int sy()
{
	int i=1;
		printf("\t\t\t\t\t——————————————————\n");
		printf("\t\t\t\t\t*****链表各个功能实验测试		*****\n");
		printf("\t\t\t\t\t*****0.退出系统				*****\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("请选择\n");
		scanf_s("%d",&i);
		while(1)
		{
			if(i<0||i>N)
			{
				printf("***没有此选项。请重新选择***\n");
				system("pause");
			}
			break;
		}

	return i;
}
void main()
{
	int i,j=1;
	struct node*head=NULL;
	while(j)
	{
		i=sy();
		switch(i)
		{
			case 0:
				j=0; 
				printf("退出成功");
				break;
			case 1:
				head=fun();system("pause");break;//创建节点函数
			case 2:
				head=output(head);system("pause");break;//全部输出函数
			case 3:
				del(head);system("pause");break;//删除函数
			case 4:file(head);
			default:break;
	
		}
		printf("\t\t\t\t\t——————————————————\n");
	}
	
	
	
	system("pause");
	
}
//1创建节点
struct node*fun()
{
	int i=0,j=1;
	int date;
	int score;
	char name[10];
	struct node *head,*p,*n;
	struct node *last=NULL;//尾节点
	head=p=(struct node*)malloc(sizeof(struct node));
	//printf("输入多个个学生的编号,用空格隔开,输入0按回车结束输入\n");
	//scanf("%d",&i);
	while(1)
	{

		if(j>0)
		{
			i++;
			
			n=(struct node*)malloc(sizeof(struct node));
			printf("请输入第%d个学生的学号,姓名,分数\n",i);
			scanf("%d %s %d",&n->date,&n->name,&n->score);
			p->next=n;
			p=n;
			printf("是否继续输入下一个同学的信息?输入 1 继续,输入  0  就停止输入\n");
			fflush(stdin);
			scanf("%d",&j);
			fflush(stdin);
		}
	
		else 
		{
			p->next=last;
				p=last;
			break;
		}
	}
	return head;
}
//2输出
struct node* output(struct node*head)
{
	if(head==NULL)
		printf("还没有数据请先输入数据\n");
	else
	{
	struct node *p1;
	p1=head->next;
	printf("学号\t姓名\t分数\n");
	while(p1!=NULL)
	{
		printf("%d\t%s\t%d",p1->date,p1->name,p1->score);
		p1=p1->next;
		printf("\n");
	}
	printf("\n");
	return head;
	}
}
//3删除
void del(struct node*head)
{
	int key,j=0;
	struct node*p,*s;
	s=head->next;
	p=head;
	printf("请输入你要删除的数据\n");
	getchar();//fflush(stdin) ;删除缓存的数据。
	scanf("%d",&key);
	printf("%d\n",key);
	while(s!=NULL)
	{
		if(s->date!=key)
		{
			p=s;
			s=s->next;
		}
		else
			break;	
	}
	if(s!=NULL)
	{
		p->next=s->next;
		free(s);
		printf("yes yes     yes\n");
	}
	else
		printf("no no    no\n");
}
void file(struct node*head){
	int i=0;
	FILE *fp;
	struct node*p=head->next;
	fp=fopen("C:\\Users\\Administrator\\Desktop\\112.txt","wt");

	 while(p!=NULL) 
 {
	 fprintf(fp," %d\t%s\t%d\n",p->date,p->name,p->score);
	 p = p->next;
	 i++;
 }
	 if(i>0)
		 printf("\t\t\t\t\t—————保存成功—————\n");
	 else printf("\t\t\t\t\t—————保存失败—————\n");
	fclose(fp);
}
  • 9
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
数据结构课程设计主要是围绕学生信息管理系统展开,在C语言中使用链表来实现文件的存储和管理。首先,需要设计学生信息的数据结构,包括学生的姓名、学号、年龄、性别等基本信息,并在链表中进行存储。在链表的设计中,可以使用单向链表或双向链表来存储学生信息,每个节点代表一个学生,节点中存储该学生的各项信息。 其次,需要设计各种功能来实现学生信息的管理,例如添加学生信息、删除学生信息、修改学生信息、查询学生信息等操作。这些功能需要通过各种算法来实现,例如遍历链表、插入节点、删除节点等。 另外,在C语言中使用文件来进行数据的存储和读取。因此,需要设计文件的读写功能,将链表中的学生信息存储到文件中,或者从文件中读取学生信息到链表中。这涉及到文件操作的知识,包括文件的打开、关闭、写入、读取等操作。 除此之外,还需要考虑对学生信息的排序功能,可以按照学号、姓名、年龄等排序来展示学生信息。这需要设计相应的排序算法来实现。 综上所述,数据结构课程设计学生信息管理C语言链表文件主要包括学生信息的数据结构设计、链表的实现、文件的读写功能设计、各种操作功能的实现以及排序算法的设计。通过这样一个综合的设计,可以帮助学生深入理解数据结构的应用与实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值