|
|
|
@ -1,10 +1,11 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <conio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
//定义一个学生
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
int num; // 学号
|
|
|
|
|
char num[12]; // 学号
|
|
|
|
|
char name[20]; // 姓名
|
|
|
|
|
char sex[4]; // 性别
|
|
|
|
|
int age; // 年龄
|
|
|
|
@ -12,27 +13,35 @@ typedef struct
|
|
|
|
|
char home[100]; // 住址
|
|
|
|
|
char tel[15]; // 电话
|
|
|
|
|
}student;
|
|
|
|
|
|
|
|
|
|
//节点
|
|
|
|
|
typedef struct Node
|
|
|
|
|
{
|
|
|
|
|
student stu;//学生信息
|
|
|
|
|
struct Node *pnext;//指向下一个节点的指针
|
|
|
|
|
struct Node* pnext;//指向下一个节点的指针
|
|
|
|
|
}node;
|
|
|
|
|
node *phead=NULL; //头节点(空链表)
|
|
|
|
|
node* phead=NULL; //头节点(空链表)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//录入学生信息
|
|
|
|
|
void Inputstudent();
|
|
|
|
|
//打印学生信息
|
|
|
|
|
void Printstudent();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//保存学生信息
|
|
|
|
|
void Savestudent();
|
|
|
|
|
//查找学生信息
|
|
|
|
|
void Lookstudent();
|
|
|
|
|
//修改学生信息
|
|
|
|
|
void Modifystudent();
|
|
|
|
|
//读取学生信息
|
|
|
|
|
void Readstudent();
|
|
|
|
|
//删除学生信息
|
|
|
|
|
void Deletestudent();
|
|
|
|
|
int count=0;
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
system("color 2A");
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
{ system("color 2A");
|
|
|
|
|
printf("\t\t\t*****************************************************************\n");
|
|
|
|
|
printf("\t\t\t|\t\t欢迎使用湖南工业大学学生信息管理系统\t\t|\n");
|
|
|
|
|
printf("\t\t\t*****************************************************************\n");
|
|
|
|
@ -47,7 +56,7 @@ int main()
|
|
|
|
|
printf("\t\t\t|\t\t\t7.删除学生信息\t\t\t\t|\n");
|
|
|
|
|
printf("\t\t\t|\t\t\t0.退出系统\t\t\t\t|\n");
|
|
|
|
|
printf("\t\t\t*****************************************************************\n");
|
|
|
|
|
|
|
|
|
|
printf("请输入:\n\n");
|
|
|
|
|
char ch=getch();//从键盘输入一个字符
|
|
|
|
|
switch(ch)
|
|
|
|
|
{
|
|
|
|
@ -58,34 +67,45 @@ int main()
|
|
|
|
|
Printstudent();
|
|
|
|
|
break;
|
|
|
|
|
case '3'://保存学生信息
|
|
|
|
|
|
|
|
|
|
Savestudent();
|
|
|
|
|
break;
|
|
|
|
|
case '4'://读取学生信息
|
|
|
|
|
|
|
|
|
|
Readstudent();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '5'://查找学生信息
|
|
|
|
|
|
|
|
|
|
Lookstudent();
|
|
|
|
|
break;
|
|
|
|
|
case '6'://修改学生信息
|
|
|
|
|
|
|
|
|
|
Modifystudent();
|
|
|
|
|
break;
|
|
|
|
|
case '7'://删除学生信息
|
|
|
|
|
Deletestudent();
|
|
|
|
|
break;
|
|
|
|
|
case '0'://退出系统
|
|
|
|
|
|
|
|
|
|
printf("ByeBye 欢迎再次使用!\n\n");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("您输入有误,请重新输入!\n\n");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
system("pause");
|
|
|
|
|
system("cls");
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
//录入学生信息
|
|
|
|
|
void Inputstudent()
|
|
|
|
|
{
|
|
|
|
|
//创建一个节点来存储新的学员
|
|
|
|
|
node *pnewnode=(node*)malloc(sizeof(node));
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color 6F");
|
|
|
|
|
//创建一个节点来存储新的学生
|
|
|
|
|
node* pnewnode=(node*)malloc(sizeof(node));
|
|
|
|
|
pnewnode->pnext=NULL;
|
|
|
|
|
|
|
|
|
|
//要将新节点插入到链表中
|
|
|
|
@ -104,9 +124,9 @@ void Inputstudent()
|
|
|
|
|
phead=pnewnode;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf("请输入学生学号:\n");
|
|
|
|
|
scanf("%d",&pnewnode->stu.num);
|
|
|
|
|
scanf("%s",pnewnode->stu.num);
|
|
|
|
|
|
|
|
|
|
printf("请输入学生姓名:\n");
|
|
|
|
|
scanf("%s",pnewnode->stu.name);
|
|
|
|
@ -126,36 +146,252 @@ void Inputstudent()
|
|
|
|
|
printf("请输入学生电话:\n");
|
|
|
|
|
scanf("%s",pnewnode->stu.tel);
|
|
|
|
|
|
|
|
|
|
printf("录入学生信息成功.\n");
|
|
|
|
|
printf("录入学生信息成功!\n\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
system("pause");
|
|
|
|
|
system("cls");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//打印学生信息
|
|
|
|
|
void Printstudent()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color 1A");
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
printf("\t\t|\t\t\t欢迎使用湖南工业大学学生信息管理系统\t\t\t\t|\n");
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
printf("\t\t|学号\t|姓名\t|性别\t|年龄\t|生日\t|家庭住址\t\t|本人电话\t\t|\n");
|
|
|
|
|
//遍历链表
|
|
|
|
|
node *p=phead;
|
|
|
|
|
int n=0;
|
|
|
|
|
node* p=phead;//定义一个当前节点
|
|
|
|
|
|
|
|
|
|
while(p!=NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
|
|
|
printf("\t\t|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t\t|\n",p->stu.num,p->stu.name,p->stu.sex,p->stu.age,p->stu.birth,p->stu.home,p->stu.tel);
|
|
|
|
|
printf("\t\t|%s\t|%s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t\t|\n",p->stu.num,p->stu.name,p->stu.sex,p->stu.age,p->stu.birth,p->stu.home,p->stu.tel);
|
|
|
|
|
|
|
|
|
|
p=p->pnext;
|
|
|
|
|
n++;
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
printf("\t\t当前总人数: %d\t\t\t\n",n);
|
|
|
|
|
printf("\t\t当前总人数: %d\t\t\t\n",count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//保存学生信息
|
|
|
|
|
void Savestudent()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color 1B");
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=fopen("stu.dat","w"); //打开文件
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("打开文件失败!\n\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//写入数据
|
|
|
|
|
node* p=phead;//当前节点
|
|
|
|
|
while(p!=NULL)
|
|
|
|
|
{
|
|
|
|
|
fwrite(&p->stu,sizeof(student),1,fp);
|
|
|
|
|
p=p->pnext;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
printf("\n\n数据存入成功!\n\n");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//查找学生信息
|
|
|
|
|
void Lookstudent()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color 1B");
|
|
|
|
|
char name[20];
|
|
|
|
|
char num[12];
|
|
|
|
|
int j=0;
|
|
|
|
|
node* p=phead;//定义一个当前节点
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color 2F");
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
printf("\t\t|\t\t\t欢迎使用湖南工业大学学生信息管理系统\t\t\t\t|\n");
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
printf("\t\t|\t\t\t\t请选择查找方式\t\t\t\t\t\t|\n");
|
|
|
|
|
printf("\t\t|***************************************************************************************|\n");
|
|
|
|
|
printf("\t\t|\t\t\t\t1.按姓名查找\t\t\t\t\t\t|\n");
|
|
|
|
|
printf("\t\t|\t\t\t\t2.按学号查找\t\t\t\t\t\t|\n");
|
|
|
|
|
printf("\t\t|\t\t\t\t0.退出查找系统\t\t\t\t\t\t|\n");
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
printf("请输入:\n\n");
|
|
|
|
|
char ch=getch();//从键盘输入一个字符
|
|
|
|
|
switch(ch)
|
|
|
|
|
{
|
|
|
|
|
case '1':// 按姓名查找
|
|
|
|
|
|
|
|
|
|
printf("请输入学生姓名:\n");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
while(p!=NULL)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(strcmp(p->stu.name,name)==0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
|
|
|
printf("\t\t|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t\t|\n",p->stu.num,p->stu.name,p->stu.sex,p->stu.age,p->stu.birth,p->stu.home,p->stu.tel);
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
}
|
|
|
|
|
p=p->pnext;
|
|
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case '2'://按学号查找
|
|
|
|
|
printf("请输入学生学号:\n");
|
|
|
|
|
scanf("%s",num);
|
|
|
|
|
while(p!=NULL)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(strcmp(p->stu.num,num)==0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
|
|
|
printf("\t\t|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t\t|\n",p->stu.num,p->stu.name,p->stu.sex,p->stu.age,p->stu.birth,p->stu.home,p->stu.tel);
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
}
|
|
|
|
|
p=p->pnext;
|
|
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case '0'://退出系统
|
|
|
|
|
printf("ByeBye 欢迎再次使用!\n\n");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("您输入有误,请重新输入!\n\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(j==count)
|
|
|
|
|
{
|
|
|
|
|
printf("没有您要查找的学生信息!\n\n");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//修改学生信息
|
|
|
|
|
void Modifystudent()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color 1B");
|
|
|
|
|
char name[20];
|
|
|
|
|
int j=0;
|
|
|
|
|
node* p=phead;//定义一个当前节点
|
|
|
|
|
printf("请输入要修改的学生姓名:\n");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
while(p!=NULL)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(p->stu.name,name)==0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
|
|
|
printf("\t\t|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t\t|\n",p->stu.num,p->stu.name,p->stu.sex,p->stu.age,p->stu.birth,p->stu.home,p->stu.tel);
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
printf("请修改学生信息!");
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf("请输入学生学号:\n");
|
|
|
|
|
scanf("%d",p->stu.num);
|
|
|
|
|
|
|
|
|
|
printf("请输入学生姓名:\n");
|
|
|
|
|
scanf("%s",p->stu.name);
|
|
|
|
|
|
|
|
|
|
printf("请输入学生性别:\n");
|
|
|
|
|
scanf("%s",p->stu.sex);
|
|
|
|
|
|
|
|
|
|
printf("请输入学生年龄:\n");
|
|
|
|
|
scanf("%d",&p->stu.age);
|
|
|
|
|
|
|
|
|
|
printf("请输入学生生日:\n");
|
|
|
|
|
scanf("%s",p->stu.birth);
|
|
|
|
|
|
|
|
|
|
printf("请输入学生住址:\n");
|
|
|
|
|
scanf("%s",p->stu.home);
|
|
|
|
|
|
|
|
|
|
printf("请输入学生电话:\n");
|
|
|
|
|
scanf("%s",p->stu.tel);
|
|
|
|
|
|
|
|
|
|
printf("修改学生信息成功!\n\n");
|
|
|
|
|
system("pause");
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
|
|
|
printf("\t\t|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t\t|\n",p->stu.num,p->stu.name,p->stu.sex,p->stu.age,p->stu.birth,p->stu.home,p->stu.tel);
|
|
|
|
|
printf("\t\t*****************************************************************************************\n");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
p=p->pnext;
|
|
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
if(j==count)
|
|
|
|
|
{
|
|
|
|
|
printf("没有您要修改的学生信息!\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//读取学生信息
|
|
|
|
|
void Readstudent()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color 0F");
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=fopen("stu.dat","r");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("打开文件失败!\n\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//读取数据
|
|
|
|
|
node* p=phead;//当前节点
|
|
|
|
|
while(p!=NULL)
|
|
|
|
|
{
|
|
|
|
|
fread(&p->stu,sizeof(student),1,fp);
|
|
|
|
|
p=p->pnext;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
printf("数据读取完毕!!!\n\n");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//删除学生信息
|
|
|
|
|
void Deletestudent()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
system("color 6A");
|
|
|
|
|
char name[20];
|
|
|
|
|
int j=0;
|
|
|
|
|
node* p=phead;//定义一个当前节点
|
|
|
|
|
printf("\n\n请输入要删除的学生姓名:\n");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
while(p!=NULL)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(strcmp(p->stu.name,name)==0)
|
|
|
|
|
{
|
|
|
|
|
p=p->pnext;
|
|
|
|
|
printf("删除学生信息成功!\n\n");
|
|
|
|
|
}
|
|
|
|
|
p=p->pnext;
|
|
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
if(j==count)
|
|
|
|
|
{
|
|
|
|
|
printf("没有您要删除的学生信息!\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -163,3 +399,11 @@ void Printstudent()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|