学生管理系统主要为管理学生的基本信息
主要功能如下:
- 创建链表录入学生。
- 添加学生(任意插入)。
- 删除学生信息。
- 修改学生信息(整体修改或单个信息修改)。
- 查询学生信息。
- 学生信息排序。
- 统计学生人数。
- 保存学生信息与读取学生信息。
首先需要以下头文件
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
#include<windows.h>
#include<conio.h>
这里就不一个一个的解释自己搜吧。
首先要定义结构体供你程序使用
typedef struct student
{
char name[30];//名字
int num;//学号
int age;//年龄
char sex[5];性别
char dizhi[100];//家庭住址
int ENscore;//英语成绩
int CHscore;//语文成绩
struct student *next;//节点中的指向下一节点的指针(重要!!!)
} stu;
接着就是最重要的创建动态链表:
思路是让p1指向新开辟的结点,p2指向链表中最后一个结点,让p1指向的结点链接在p2所指向结点的后面,用p2->next = p1实现。
在这里插入图片描述
依次连接链表。
本人代码如下:
void creat(student *head)//录入信息
{
system("cls");
stu *p=head;
stu *p1=(student*)malloc(sizeof(student));
system("cls");
printf("请输入姓名\n");
scanf("%s",p1->name);
int x,v,z,b;
pun1:printf("请输入学生的学号\n");
x=scanf("%d",&p1->num);
if(x!=1)
{
printf("学号只能为数字,请重新输入\n");
fflush(stdin);
goto pun1;
}
int c;
stu* q=head->next;
while(q!=NULL)
{
c=q->num;
if(p1->num==c)
{
printf("该学号已注册,请重新输入要输入的学号\n");
goto pun1;
}
q=q->next;
}
pun2:printf("请输入年龄\n");
v=scanf("%d",&p1->age);
if(p1->age<=0&&v==0)
{
printf("年龄不能超自然\n");
fflush(stdin);
goto pun2;
}
printf("请输入性别\n");
scanf("%s",&p1->sex);
while(1)
{
char man[3]={
"男"};
char woman[3]={
"女"};
loop:if(strcmp(p1->sex,man))
{
if(strcmp(p1->sex,woman))
{
printf("性别只能为男或女再次输入性别\n");
scanf("%s",p1->sex);
goto loop;
}
}
if((strcmp(p1->sex,man))||(strcmp(p1->sex,woman)))
{
break;
}
}
printf("请输入家庭住址\n");
scanf("%s",p1->dizhi);
pun3:printf("请输入英语成绩\n");
z=scanf("%d",&p1->ENscore);
if(z!=1)
{
printf("成绩只能为数字,请重新输入\n");
fflush(stdin);
goto pun3;
}
pun4:printf("请输入语文成绩\n");
b=scanf("%d",&p1->CHscore);
if(b!=1)
{
printf("成绩只能为数字,请重新输入\n");
fflush(stdin);
goto pun4;
}
while(p->next!=NULL)
{
p=p->next;
if(strcmp(p1