大部分人做学生证信息管理系统的时候通常是使用结构体数组做的,这样方法适合已知数量的学生证文件,但是不适用于位置数量或者数量较大的学生证信息,而使用链表则适用于此种情况,话不多说,先摆上题目
设计一个学生证的管理程序。该程序具有以下功能:
(1)录入某位学生的学生证信息(学生证应该包括的内容请参看自己的学生证);(2)给定学生的学号,修改该学生的学生证信息;
(3)给定学生的学号,删除该学生的学生证信息;
(4)根据输入的学生的学号,显示该学生的学生证信息;
(5)根据输入的班级的编号,显示该班所有学生的学生证信息;
(6)统计功能:提供一些统计各类信息的功能。
注:必须要用链表以及文件读写!
这包括了链表的增删查改,还有文件的读写动作。这涉及到了fprintf以及fscanf两个格式,这里不详细介绍二者的使用方法,可以通过我的代码来学习。
代码如下:
#include <stdio.h>
#include <stdlib.h>
#define STUDENT_HEAD
typedef struct node /*定义结构体*/
{
char name[100];//姓名
char sex[10]; //性别
char college[100];//学院
char major[100];//专业
char identity[100];//身份
long long num; //学号
long long card_num;//卡号
char term_of_validity[100];//有效期
struct node *next; //链表指针域
}student_info;
//学生信息链表
extern student_info* student_list; //全局变量声明
//初始化函数声明
//初始化学生信息链表 void init_student_info_list();
//判断学生信息链表是否为空
int student_list_empty();
//操作函数声明
//向学校信息表中添加学生信息记录
int add_student_info();
//根据学号删除学生信息
int delete_student_info(long long num);
//根据学号修改学生信息
int modify_student_info(long long num);
//根据学号查找学生信息
student_info* search_student_info(long long num);
//输出单个学生的信息
void Show();
//显示所有学生信息
void display_student_info();
//将学生信息保存到文件
int save_file();
//从文件中读取学生信息
int read_file();
//初始化学生信息链表
void init_student_info_list()
{
//学生信息链表头结点
student_list = (student_info*)malloc(sizeof(student_info));
student_list->next = NULL;
}
//判断学生信息链表是否为空
int student_list_empty()
{
return student_list->next == NULL;
}
//操作函数实现
//向学校信息表中添加学生信息记录
int add_student_info()
{
student_info *pstu = (student_info*)malloc(sizeof(student_info));
if(pstu == NULL)
{
printf("内存分配失败.\n");
return 0;
}
printf("请按要求一次输入学生的信息.\n");
printf("请输入学号: ");
scanf("%lld",&pstu->num);
//判断该学号是否已经存在
if((pstu=search_student_info(pstu->num)) != NULL)
{
printf("该学号已经存在学生信息表中.\n");
return 0;
}
else
{
printf("请输入姓名: ");
getchar();
gets(pstu->name);
printf("请输入性别: ");
scanf("%s",pstu->sex);
printf("请输入学院: ");
scanf("%s",pstu->college);
printf("请输入专业: ");
scanf("%s",pstu->major);
printf("请输入身份: ");
scanf("%s",pstu->identity);
printf("请输入学号: ");
scanf("%lld",&pstu->num);//每次从学生信息链表的头部插入;
printf("请输入卡号:");
scanf("%lld",&pstu->card_num);
printf("请输入有效期:");
scanf("%s",pstu->term_of_validity);
pstu->next = student_list->next;
student_list->next = pstu;
return 1;
}
}
//根据学号删除学生信息
int delete_student_info(long long num)
{
student_info *pstu;
student_info *qstu;
if(search_student_info(num) == NULL)
{
printf("不存在该学号为%d的学生信息.\n",num);
return 0;
}
pstu = student_list->next;
qstu = student_list;
while(pstu->num != num)
{
qstu = pstu;
pstu = pstu->next;
}
qstu->