C语言使用单链表的学生成绩管理系统


本系统的代码冗余还是蛮多的,其实可以再精简很多,可是后期自己懒得改了,这里强调一个思想----代码复用,这会大大节约自己的编程量,也可以使自己看待一个向项目有宏观的思想。关于这个系统,是采用单链表和文件写的,单链表在数据录入部分已经按照学号排好序,后期的数据输出也即很方便看待数据,其实可以在后期进行排序,我的想法有两种,①创建一个结构体数组,把数据重新导入结构体数组中,再进行快速排序;②使用指针,不过这对数据结构以及指针的要求很高,基础不扎实还是不要乱试;不然会出现大量改也不知道怎么改的bug;关于文件部分 其实文件有大量的方法写入 比如二进制也可以 ,写起来都差不多 不过从文件读出来 和 写进去文件 的部分得多种方法试试 这样就可以加强基础了。 关于指针 这是头疼的问题 总之不能乱用 。关于链表的部分 看数据结构的基础了 这是数据结构最简单的部分 不过得细心和足够的耐心。

系统的图片如下:


 
以下为本系统的部分源码内含注释:
# include <stdio.h>
# include <conio.h>
# include <malloc.h>
# include <stdlib.h>

struct Node
{
	int num;
	int age;
	char name[30];
	char sex[5];
	int sroce;
	struct Node *next;
};

Node *head;

Node *Load()								//载入文件中的数据到结构体中
{
	FILE *fp;  
 	Node *cur,*p,*q; 
 	cur = NULL; 
 	fp = fopen("Student","r");   		//以"r"形式打开student的文件 
 	if(fp == NULL)						//如果文件不存在 
 	{		
  		fp = fopen("Student","w");		//创立一个student文件 
  		fclose(fp);						//关闭文件 
  		return cur;						//返回链表中,存入head 
 	} 
 	p=(struct Node*)malloc(sizeof(struct Node)); 	//如果存在 
	if(fread(p,sizeof(struct Node),1,fp) != 1)		//判断文件中的数据 是否只有1个 
		return  cur;								//是就返回
	cur = p; 
	while(!feof(fp)) 								//否则就开始从文件中读数据 
	{
	    q = p; 
	    p = (struct Node *)malloc(sizeof(struct Node)); 
	    fread(p,sizeof(struct Node),1,fp); 
	  	q -> next = p; 
	} 
	q -> next = NULL; 
	free(p); 										//释放指针p所指向的内存空间 
	fclose(fp); 
	return cur;									 	//返回链表中,存入head 
} 

void Interface()								//主界面函数
{
	system( "cls" );							//清屏函数 
	printf("\n\n\n");
	printf("\t------------------------------
  • 9
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个简单的单链表学生成绩管理系统C语言代码示例: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> // 定义学生结构体 typedef struct Student { int id; char name[20]; int score_chinese; int score_math; int score_english; int score_politics; int total_score; struct Student* next; } Student; // 创建学生节点 Student* createStudent(int id, char name[], int score_chinese, int score_math, int score_english, int score_politics) { Student* student = (Student*)malloc(sizeof(Student)); student->id = id; strcpy(student->name, name); student->score_chinese = score_chinese; student->score_math = score_math; student->score_english = score_english; student->score_politics = score_politics; student->total_score = score_chinese + score_math + score_english + score_politics; student->next = NULL; return student; } // 插入学生节点 void insertStudent(Student** head, Student* student) { if (*head == NULL) { *head = student; } else { Student* current = *head; while (current->next != NULL) { current = current->next; } current->next = student; } } // 打印学生信息 void printStudent(Student* student) { printf("学号:%d\n", student->id); printf("姓名:%s\n", student->name); printf("语文成绩:%d\n", student->score_chinese); printf("数学成绩:%d\n", student->score_math); printf("英语成绩:%d\n", student->score_english); printf("政治成绩:%d\n", student->score_politics); printf("总分:%d\n", student->total_score); printf("\n"); } // 遍历打印学生链表 void printStudentList(Student* head) { Student* current = head; while (current != NULL) { printStudent(current); current = current->next; } } int main() { Student* head = NULL; // 添加学生节点 Student* student1 = createStudent(1, "张三", 80, 90, 85, 75); insertStudent(&head, student1); Student* student2 = createStudent(2, "李四", 75, 85, 90, 80); insertStudent(&head, student2); Student* student3 = createStudent(3, "王五", 90, 80, 95, 85); insertStudent(&head, student3); // 打印学生链表 printStudentList(head); return 0; } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值