C语言实现学生信息管理系统(附原码)-创新互联
本人的C语言学习完后,用所学的知识自己实现了一个学生管理系统,新手一个,代码还有待完善,欢迎大家在评论区指出错误!
成都创新互联主要从事成都网站制作、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务洛川,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792一、流程图二、函数的目录 三、程序介绍1.主要功能:添加学生信息、打印学生信息、查找学生信息、添加学生信息、修改学生信息、计算学生成绩、删除学生信息。
2.实现思路:本系统用的是链表(个人感觉链表很好用)来实现添加、查找、添加等操作,没用使用数据库,所有数据都放在了堆区。
3.文件介绍:本系统中使用了三个文件 main.c、Func.c、Func.h。
四、系统原码main.c介绍
main函数这里只调用了login();这个函数
#define _CRT_SECURE_NO_WARNINGS 1
#include#include#include#include "Func.h"
int main()
{
//账号登陆
login();
system("pause");
return 0;
}
Func.h介绍
主要就是函数还有结构体的声明
#pragma once
#define MAX 64 //将数组大小统一
typedef struct user //管理员的id 和 密码
{
char id[MAX];
char password[MAX];
}User;
typedef struct student
{
char name[MAX]; //学生姓名
char sex[MAX]; //学生性别
char num[MAX]; //学生学号
int Chinese; //语文成绩
int Mathematics; //数学成绩
int English; //英语成绩
int Computer; //计算机成绩
}STU;
//学生链表
struct stu_LinkList
{
//数据域
STU student;
//指针域
struct stu_LinkList* next;
};
//主函数声明
//登陆函数
extern void login();
//打印主界面
extern void print_manu();
//添加学生信息
extern struct stu_LinkList* input_information();
//打印学生信息
extern void print_information();
//查找学生信息
extern void search_information();
//添加学生信息
extern void increase_information();
//修改学生信息
extern void modify_information();
//计算学生成绩
extern void calc();
//删除学生信息
extern void del_information();
//退出程序
extern void exit_project();
/
//自定义函数声明
//表头
extern void print_table();
//总成绩表头
extern void print_table_add();
//平均数表头
extern void print_table_ave();
/
//查询子函数声明
//姓名查询
extern void search_by_name();
//性别查询
extern void search_by_sex();
//学号查询
extern void search_by_num();
//
//计算子函数声明
//计算总成绩
extern void calc_sum();
//计算平均数
extern void calc_ave();
//
//删除子函数声明
//删除单个学生
extern void del_priv_stu();
//删除所有学生
extern void del_all_stu();
Func.c介绍
这里主要是函数效果的实现
#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable : 6031) //消除c6031警告,C6031返回值被忽略:“scanf”解决办法
#include#include#include#include "Func.h"
//学生链表头节点(全局变量)
struct stu_LinkList* Header = NULL;
//登陆函数
void login()
{
//初始化管理员的id和密码
User user[2] = { { "Leo", "123456" }, {"bob", "123456"} };
char password[MAX] = {0}; //密码
char id[MAX] = {0}; //用户名
int num = 1; //记录登录次数
int chance = 3; //机会次数
while (1)
{
int isTrue = 0; //用来判断是否登录成功
printf("---------- 请输入用户名 ----------\n");
scanf("%s", id);
getchar();
printf("---------- 请输入密码 ----------\n");
scanf("%s", password);
getchar();
if (num<= 3)
{
for (int i = 0; i< sizeof(user) / sizeof(user[0]); i++)
{
if (strcmp(user[i].id, id) == 0 && strcmp(user[i].password, password) == 0)
{
printf("登陆成功!\n");
//打印界面
print_manu();
isTrue = 1;
}
}
if (isTrue != 1)
{
num++;
printf("输入错误,您还有%d次机会\n", --chance);
if (chance == 0)
{
printf("三次均输入失败,退出程序\n");
break;
}
}
else
{
break;
}
}
printf("按回车重新输入\n");
getchar();
system("cls");
}
}
//打印主界面
void print_manu()
{
system("cls");
int num = 0; //选择要执行的序号
printf("**********************************************\n");
printf("***********欢迎使用高校学生管理系统***********\n");
printf("**********************************************\n");
printf("\t\t1.输入学生信息\t\t\n");
printf("\t\t2.查找学生信息\t\t\n");
printf("\t\t3.打印学生信息\t\t\n");
printf("\t\t4.添加学生信息\t\t\n");
printf("\t\t5.修改学生信息\t\t\n");
printf("\t\t6.计算学生成绩\t\t\n");
printf("\t\t7.删除学生信息\t\t\n");
printf("\t\t8.退出系统\t\t\n");
printf("**********************************************\n");
printf("**********************************************\n");
printf("请输入您要执行的操作序号:");
scanf("%d", &num);
getchar();
switch (num)
{
case 1:
//添加学生信息
Header = input_information();
print_manu();
break;
case 2:
//查找学生信息
search_information();
break;
case 3:
//打印学生信息
print_information(Header);
break;
case 4:
//添加学生信息
increase_information();
break;
case 5:
//修改学生信息
modify_information();
break;
case 6:
//计算学生成绩
calc();
break;
case 7:
//删除学生信息
del_information();
break;
case 8:
//退出系统
exit_project();
break;
default:
printf("对不起,没有该操作,按回车可以重新选择\n");
getchar();
print_manu();
break;
}
}
//输入学生信息
struct stu_LinkList* input_information()
{
char isAgain; //用来判断是否继续输入
//创建一个头节点
struct stu_LinkList* pHeader = (struct stu_LinkList*)malloc(sizeof(struct stu_LinkList));
if (pHeader == NULL)
{
printf("抱歉,创建失败\n");
return;
}
//初始化头节点
pHeader->next = NULL;
memset(&pHeader->student, 0, sizeof(STU));
//创建一个尾节点指针,用来记录尾节点的位置,方便插尾
struct stu_LinkList* pTail = pHeader;
//设置一个学生结构体来接收输入的值
STU tmp;
memset(&tmp, 0, sizeof(STU));
again:
system("cls");
//输入学生信息
printf("输入学生姓名:\n");
scanf("%s", tmp.name);
getchar();
printf("输入学生性别:\n");
scanf("%s", tmp.sex);
getchar();
printf("输入学生学号:\n");
scanf("%s", tmp.num);
getchar();
printf("输入学生语文成绩:\n");
scanf("%d", &tmp.Chinese);
getchar();
printf("输入学生数学成绩:\n");
scanf("%d", &tmp.Mathematics);
getchar();
printf("输入学生英语成绩:\n");
scanf("%d", &tmp.English);
getchar();
printf("输入学生计算机成绩:\n");
scanf("%d", &tmp.Computer);
getchar();
//创建一个新的学生节点
struct stu_LinkList* stu_Node = (struct stu_LinkList*)malloc(sizeof(struct stu_LinkList));
stu_Node->student = tmp;
stu_Node->next = NULL;
//建立关系
pTail->next = stu_Node;
pTail = stu_Node;
//是否继续添加学生信息
printf("继续添加学生信息请按Y\t返回主页面请按N\n");
scanf("%c", &isAgain);
if (isAgain == 'Y')
{
goto again;
}
else if(isAgain == 'N')
{
return pHeader;
}
}
//表头
void print_table()
{
system("cls");
printf("+--------+--------+--------+--------+--------+--------+----------+\n");
printf("| 姓名 | 性别 | 学号 | 语文 | 数学 | 英语 | 计算机 |\n");
printf("+--------+--------+--------+--------+--------+--------+----------+\n");
}
//打印学生信息
void print_information()
{
system("cls");
int isReturn; //是否返回
//判断系统里是否有学生信息(没有输入过信息)
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按 1\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
}
//判断已经进行过信息的输入,但是又将全部数据删除的情况
if (Header->next == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按 1\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
}
print_table();
struct stu_LinkList* pCurrent = Header->next;
while (pCurrent != NULL)
{
printf("|%5s |%5s |%5s |%5d |%5d |%5d |%5d |\n", pCurrent->student.name, pCurrent->student.sex, pCurrent->student.num,
pCurrent->student.Chinese, pCurrent->student.Mathematics,
pCurrent->student.English, pCurrent->student.Computer);
pCurrent = pCurrent->next;
printf("+--------+--------+--------+--------+--------+--------+----------+\n");
}
printf("返回上一级请输入 1\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
}
//查找学生信息
void search_information()
{
char isAgain;
int num;
system("cls");
printf("**********************************************\n");
printf("**********************************************\n");
printf("\t\t1.按姓名查询\t\t\n");
printf("\t\t2.按性别查询\t\t\n");
printf("\t\t3.按学号查询\t\t\n");
printf("\t\t4.返回主界面\t\t\n");
printf("**********************************************\n");
printf("**********************************************\n");
printf("请输入您要执行的操作:");
scanf("%d", &num);
getchar();
if (num == 1)
{
//姓名查询
search_by_name();
}
else if (num == 2)
{
//性别查询
search_by_sex();
}
else if (num == 3)
{
//学号查询
search_by_num();
}
else if (num == 4)
{
print_manu();
}
else
{
printf("抱歉,没有该选项\n");
printf("重新选择请按 Y,返回上一级请按 N\n");
scanf("%c", &isAgain);
getchar();
if (isAgain == 'Y')
{
search_information();
}
else if (isAgain == 'N')
{
print_manu();
}
}
}
//姓名查询
void search_by_name()
{
system("cls");
int isReturn = 0; //是否返回
int isLive = 0; //该学生是否存在
char name[MAX];
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按1\t返回上一级请按2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
search_information();
}
}
printf("请输入您要查询的姓名:\n");
scanf("%s", name);
getchar();
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
print_table();
while (pCurrent != NULL)
{
//判断时候有该姓名的学生
if (strcmp(name, pCurrent->student.name) == 0)
{
printf("|%5s |%5s |%5s |%5d |%5d |%5d |%5d |\n", pCurrent->student.name, pCurrent->student.sex, pCurrent->student.num,
pCurrent->student.Chinese, pCurrent->student.Mathematics,
pCurrent->student.English, pCurrent->student.Computer);
printf("+--------+--------+--------+--------+--------+--------+----------+\n");
isLive++;
}
pCurrent = pCurrent->next;
}
if (isLive == 0)
{
system("cls");
printf("抱歉,并未找到该学生\n");
}
//结束返回
printf("重新查找请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
search_by_name();
}
else if (isReturn == 2)
{
search_information();
}
}
//按照性别查询
void search_by_sex()
{
system("cls");
int isReturn = 0; //是否返回
int isLive = 0; //该学生是否存在
char sex[MAX];
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按1\t返回上一级请按2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
search_information();
}
}
printf("请输入您要查询的性别:\n");
scanf("%s", sex);
getchar();
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
print_table();//打印表头
while (pCurrent != NULL)
{
//判断时候有该性别的学生
if (strcmp(sex, pCurrent->student.sex) == 0)
{
printf("|%5s |%5s |%5s |%5d |%5d |%5d |%5d |\n", pCurrent->student.name, pCurrent->student.sex, pCurrent->student.num,
pCurrent->student.Chinese, pCurrent->student.Mathematics,
pCurrent->student.English, pCurrent->student.Computer);
printf("+--------+--------+--------+--------+--------+--------+----------+\n");
isLive++;
}
pCurrent = pCurrent->next;
}
if (isLive == 0)
{
system("cls");
printf("抱歉,并未找到该学生\n");
}
//结束返回
printf("重新查找请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
search_by_sex();
}
else if (isReturn == 2)
{
search_information();
}
}
//按学号查询
void search_by_num()
{
system("cls");
int isReturn = 0; //是否返回
int isLive = 0; //该学生是否存在
char num[MAX];
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按1\t返回上一级请按2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
search_information();
}
}
printf("请输入您要查询的学号:\n");
scanf("%s", num);
getchar();
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
print_table();
while (pCurrent != NULL)
{
//判断时候有该性别的学生
if (strcmp(num, pCurrent->student.num) == 0)
{
printf("|%5s |%5s |%5s |%5d |%5d |%5d |%5d |\n", pCurrent->student.name, pCurrent->student.sex, pCurrent->student.num,
pCurrent->student.Chinese, pCurrent->student.Mathematics,
pCurrent->student.English, pCurrent->student.Computer);
printf("+--------+--------+--------+--------+--------+--------+----------+\n");
isLive++;
}
pCurrent = pCurrent->next;
}
if (isLive == 0)
{
system("cls");
printf("抱歉,并未找到该学生\n");
}
//结束返回
printf("重新查找请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
search_by_num();
}
else if (isReturn == 2)
{
search_information();
}
}
//添加学生信息
void increase_information()
{
system("cls");
int isReturn = 0; //是否返回
char isAgain; //用来判断是否继续输入
if (Header == NULL)
{
printf("请先输入学生信息!\n");
printf("返回主页面请按1\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
}
//创建一个尾节点指针,用来记录尾节点的位置,方便插尾
struct stu_LinkList* pTail = Header;
//输入要添加的学生信息
STU tmp;
memset(&tmp, 0, sizeof(STU));
again:
system("cls");
//输入学生信息
printf("输入学生姓名:\n");
scanf("%s", tmp.name);
getchar();
printf("输入学生性别:\n");
scanf("%s", tmp.sex);
getchar();
printf("输入学生学号:\n");
scanf("%s", tmp.num);
getchar();
printf("输入学生语文成绩:\n");
scanf("%d", &tmp.Chinese);
getchar();
printf("输入学生数学成绩:\n");
scanf("%d", &tmp.Mathematics);
getchar();
printf("输入学生英语成绩:\n");
scanf("%d", &tmp.English);
getchar();
printf("输入学生计算机成绩:\n");
scanf("%d", &tmp.Computer);
getchar();
//进行信息比对,如果有重复信息输入,将会提示
struct stu_LinkList* pCurrent = Header->next;
while (pCurrent != NULL)
{
if (strcmp(tmp.name, pCurrent->student.name) == 0 && strcmp(tmp.sex, pCurrent->student.sex) == 0 && strcmp(tmp.num, pCurrent->student.num) == 0)
{
printf("抱歉,系统已有该同学信息\n");
printf("重新输入请按 Y\t返回主界面请按 N\n");
scanf("%c", &isAgain);
getchar();
if (isAgain == 'Y')
{
increase_information();
}
else if (isAgain == 'N')
{
print_manu();
}
}
pCurrent = pCurrent->next;
}
//遍历链表找到尾节点
while (pTail->next != NULL)
{
pTail = pTail->next;
}
//创建一个新的学生节点
struct stu_LinkList* stu_Node = (struct stu_LinkList*)malloc(sizeof(struct stu_LinkList));
stu_Node->student = tmp;
stu_Node->next = NULL;
//建立关系
pTail->next = stu_Node;
pTail = stu_Node;
//是否继续添加学生信息
printf("继续添加学生信息请按 Y,返回主界面请按 N\n");
scanf("%c", &isAgain);
if (isAgain == 'Y')
{
goto again;
}
else if (isAgain == 'N')
{
print_manu();
}
}
//修改学生信息
void modify_information()
{
system("cls");
char isAgain; //用来判断是否继续输入
int isReturn = 0; //是否返回
//判断系统里是否有学生信息
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按 1\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
}
//输入要修改的学生信息
STU tmp;
again:
system("cls");
printf("请输入你要查找的学生信息\n");
printf("输入学生姓名:\n");
scanf("%s", tmp.name);
getchar();
printf("输入学生性别:\n");
scanf("%s", tmp.sex);
getchar();
printf("输入学生学号:\n");
scanf("%s", tmp.num);
getchar();
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
//该信息的位置
struct stu_LinkList* information_pos = NULL;
while (pCurrent != NULL)
{
if (strcmp(tmp.name, pCurrent->student.name) == 0 && strcmp(tmp.sex, pCurrent->student.sex) == 0 && strcmp(tmp.num, pCurrent->student.num) == 0)
{
printf("找到该同学信息\n");
printf("打印学生信息Y\t不打印N\n");
scanf("%c", &isAgain);
if (isAgain == 'Y')
{
print_table();
printf("|%5s |%5s |%5s |%5d |%5d |%5d |%5d |\n", pCurrent->student.name, pCurrent->student.sex, pCurrent->student.num,
pCurrent->student.Chinese, pCurrent->student.Mathematics,
pCurrent->student.English, pCurrent->student.Computer);
printf("+--------+--------+--------+--------+--------+--------+----------+\n");
}
else if (isAgain == 'N')
{
system("cls");
}
//记录信息位置
information_pos = pCurrent;
}
pCurrent = pCurrent->next;
}
if (information_pos == NULL)
{
system("cls");
printf("未找到该同学信息\n");
//是否继续修改学生信息
printf("继续修改学生信息Y\t返回主界面N\n");
scanf("%c", &isAgain);
getchar();
if (isAgain == 'Y')
{
goto again;
}
else if (isAgain == 'N')
{
print_manu();
}
}
printf("请修改学生信息\n");
printf("输入学生姓名:\n");
scanf("%s", tmp.name);
getchar();
printf("输入学生性别:\n");
scanf("%s", tmp.sex);
getchar();
printf("输入学生学号:\n");
scanf("%s", tmp.num);
getchar();
printf("输入学生语文成绩:\n");
scanf("%d", &tmp.Chinese);
getchar();
printf("输入学生数学成绩:\n");
scanf("%d", &tmp.Mathematics);
getchar();
printf("输入学生英语成绩:\n");
scanf("%d", &tmp.English);
getchar();
printf("输入学生计算机成绩:\n");
scanf("%d", &tmp.Computer);
getchar();
//修改学生信息
information_pos->student = tmp;
printf("修改成功!\n");
printf("继续修改学生信息Y\t返回主界面N\n");
scanf("%c", &isAgain);
getchar();
if (isAgain == 'Y')
{
goto again;
}
else if (isAgain == 'N')
{
print_manu();
}
}
//总成绩表头
void print_table_add()
{
system("cls");
printf("+--------+--------+--------+--------+--------+--------+----------+----------+\n");
printf("| 姓名 | 性别 | 学号 | 语文 | 数学 | 英语 | 计算机 | 总成绩 |\n");
printf("+--------+--------+--------+--------+--------+--------+----------+----------+\n");
}
//平均数表头
void print_table_ave()
{
system("cls");
printf("+--------+--------+--------+--------+--------+--------+----------+----------+\n");
printf("| 姓名 | 性别 | 学号 | 语文 | 数学 | 英语 | 计算机 | 平均数 |\n");
printf("+--------+--------+--------+--------+--------+--------+----------+----------+\n");
}
//计算学生成绩
void calc()
{
char isAgain;//是否继续
int num;
system("cls");
printf("**********************************************\n");
printf("**********************************************\n");
printf("\t\t1.计算总成绩\t\t\n");
printf("\t\t2.计算平均数\t\t\n");
printf("\t\t3.返回主界面\t\t\n");
printf("**********************************************\n");
printf("**********************************************\n");
printf("请输入您要执行的操作:");
scanf("%d", &num);
getchar();
if (num == 1)
{
//计算总成绩
calc_sum();
}
else if (num == 2)
{
//计算平均数
calc_ave();
}
else if (num == 3)
{
print_manu();
}
else
{
printf("抱歉,没有该选项\n");
printf("重新选择请按 Y,返回主界面请按 N\n");
scanf("%c", &isAgain);
getchar();
if (isAgain == 'Y')
{
calc();
}
else if (isAgain == 'N')
{
print_manu();
}
}
}
//计算总成绩
void calc_sum()
{
system("cls");
int sum = 0;//总成绩变量
int isReturn = 0; //是否返回
//判断系统里是否有学生信息
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
calc();
}
}
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
print_table_add();
while (pCurrent != NULL)
{
sum = pCurrent->student.Chinese + pCurrent->student.Mathematics + pCurrent->student.English + pCurrent->student.Computer;
printf("|%5s |%5s |%5s |%5d |%5d |%5d |%5d | %5d |\n", pCurrent->student.name, pCurrent->student.sex, pCurrent->student.num,
pCurrent->student.Chinese, pCurrent->student.Mathematics,
pCurrent->student.English, pCurrent->student.Computer, sum);
printf("+--------+--------+--------+--------+--------+--------+----------+----------+\n");
pCurrent = pCurrent->next;
}
printf("返回主页面请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
calc();
}
}
//计算平均数
void calc_ave()
{
system("cls");
float ave = 0;//平均数变量
int isReturn = 0; //是否返回
//判断系统里是否有学生信息
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
calc();
}
}
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
print_table_ave();
while (pCurrent != NULL)
{
ave = ((float)(pCurrent->student.Chinese + pCurrent->student.Mathematics + pCurrent->student.English + pCurrent->student.Computer)) * (float)0.25;
printf("|%5s |%5s |%5s |%5d |%5d |%5d |%5d |%5.2lf |\n", pCurrent->student.name, pCurrent->student.sex, pCurrent->student.num,
pCurrent->student.Chinese, pCurrent->student.Mathematics,
pCurrent->student.English, pCurrent->student.Computer, ave);
printf("+--------+--------+--------+--------+--------+--------+----------+----------+\n");
pCurrent = pCurrent->next;
}
printf("返回主页面请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
calc();
}
}
//删除学生信息
void del_information()
{
char isAgain;//是否继续
int num;
system("cls");
printf("**********************************************\n");
printf("**********************************************\n");
printf("\t\t1.删除单个学生\t\t\n");
printf("\t\t2.删除全部学生\t\t\n");
printf("\t\t3.返回主界面\t\t\n");
printf("**********************************************\n");
printf("**********************************************\n");
printf("请输入您要执行的操作:");
scanf("%d", &num);
getchar();
if (num == 1)
{
//删除单个学生
del_priv_stu();
}
else if (num == 2)
{
//删除所有学生
del_all_stu();
}
else if (num == 3)
{
print_manu();
}
else
{
printf("抱歉,没有该选项\n");
printf("重新选择请按 Y,返回主界面请按 N\n");
scanf("%c", &isAgain);
getchar();
if (isAgain == 'Y')
{
del_information();
}
else if (isAgain == 'N')
{
print_manu();
}
}
}
//删除单个学生
void del_priv_stu()
{
int isReturn = 0; //是否返回
int isExist = 0;//判断信息是否存在
char isAgain = 0;//是否继续删除
//判断系统里是否有学生信息
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
del_information();
}
}
//输入要修改的学生信息
STU tmp;
system("cls");
printf("请输入你要删除的学生信息\n");
printf("输入学生姓名:\n");
scanf("%s", tmp.name);
getchar();
printf("输入学生性别:\n");
scanf("%s", tmp.sex);
getchar();
printf("输入学生学号:\n");
scanf("%s", tmp.num);
getchar();
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
//记录上一个节点的位置
struct stu_LinkList* pPrev = Header;
while (pCurrent != NULL)
{
if (strcmp(tmp.name, pCurrent->student.name) == 0 && strcmp(tmp.sex, pCurrent->student.sex) == 0 && strcmp(tmp.num, pCurrent->student.num) == 0)
{
pCurrent = pCurrent->next;
free(pPrev->next);
pPrev->next = NULL;
//建立关系
pPrev->next = pCurrent;
isExist++;
break;
}
pPrev = pCurrent;
pCurrent = pCurrent->next;
}
if (isExist == 0)
{
system("cls");
printf("未找到该同学信息\n");
//是否继续删除学生信息
printf("继续删除学生信息 Y\t返回上一级 N\n");
scanf("%c", &isAgain);
getchar();
if (isAgain == 'Y')
{
del_priv_stu();
}
else if (isAgain == 'N')
{
del_information();
}
}
if (isExist == 1)
{
system("cls");
printf("删除成功\n");
printf("继续删除学生信息 Y\t返回上一级 N\n");
scanf("%c", &isAgain);
getchar();
if (isAgain == 'Y')
{
del_priv_stu();
}
else if (isAgain == 'N')
{
del_information();
}
}
}
//删除所有学生
void del_all_stu()
{
system("cls");
int isReturn = 0; //是否返回
//判断系统里是否有学生信息
if (Header == NULL)
{
printf("系统还没有学生信息!\n");
printf("返回主页面请按 1\t返回上一级请按 2\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
print_manu();
}
else if (isReturn == 2)
{
del_information();
}
}
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
//记录下一个节点
struct stu_LinkList* next_Node = NULL;
while (pCurrent != NULL)
{
next_Node = pCurrent->next;
free(pCurrent);
pCurrent = NULL;
pCurrent = next_Node;
}
Header->next = NULL;
printf("删除成功\n");
printf("返回上一级请按 1\n");
scanf("%d", &isReturn);
getchar();
if (isReturn == 1)
{
del_information();
}
}
//退出程序
void exit_project()
{
system("cls");
if (Header == NULL)
{
printf("感谢您的使用,已退出!\n");
exit(0);
}
else if (Header->next == NULL)
{
//释放头节点
free(Header);
Header = NULL;
printf("感谢您的使用,已退出!\n");
exit(0);
}
else
{
//进行遍历
struct stu_LinkList* pCurrent = Header->next;
//记录下一个节点
struct stu_LinkList* next_Node = NULL;
while (pCurrent != NULL)
{
next_Node = pCurrent->next;
free(pCurrent);
pCurrent = NULL;
pCurrent = next_Node;
}
Header->next = NULL;
//释放头节点
free(Header);
Header = NULL;
printf("感谢您的使用,已退出!\n");
exit(0);
}
}
五、总结
到这里这个学生管理系统就完成啦!这个当作自己的一个C语言结课作业,在写的过程中有一些逻辑参考了学生信息管理系统这篇文章,希望以上内容可以帮助到大家,如果有错误欢迎大家指出。
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
当前文章:C语言实现学生信息管理系统(附原码)-创新互联
本文网址:http://lswzjz.com/article/jhiec.html