You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
389 lines
11 KiB
389 lines
11 KiB
//****************************************头文件声明********************************************
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <conio.h>
|
|
#include <string.h>
|
|
#include <windows.h>
|
|
//**********************************************************************************************
|
|
|
|
typedef struct
|
|
{
|
|
char num[12]; // 学号
|
|
char name[20]; // 姓名
|
|
char sex[4]; // 性别
|
|
int age; // 年龄
|
|
char birth[20]; // 生日
|
|
char home[100]; // 住址
|
|
char tel[15]; // 电话
|
|
}student;
|
|
|
|
typedef struct Node //节点
|
|
{
|
|
student stu; //学生信息
|
|
struct Node* pnext;//指向下一个节点的指针
|
|
}node;
|
|
node* phead=NULL; //头节点(空链表)
|
|
|
|
//****************************************函数的声明********************************************
|
|
void Inputstudent(); //录入学生信息
|
|
void Printstudent(); //打印学生信息
|
|
void Savestudent(); //保存学生信息
|
|
void Lookstudent(); //查找学生信息
|
|
void Modifystudent(); //修改学生信息
|
|
void Readstudent(); //读取学生信息
|
|
void Deletestudent(); //删除学生信息
|
|
void yanshi(char *p); //延时函数说明
|
|
//**********************************************************************************************
|
|
|
|
int main()
|
|
{
|
|
yanshi("\n\n\n\t\t**************************欢迎使用学生信息管理系统*****************\n");
|
|
system("cls");
|
|
while(1)
|
|
{
|
|
|
|
system("color 2A"); //调节控制台的背景和字体颜色
|
|
printf("\t\t\t*****************************************************************\n");
|
|
printf("\t\t\t|\t\t欢迎使用湖南工业大学学生信息管理系统\t\t|\n");
|
|
printf("\t\t\t*****************************************************************\n");
|
|
printf("\t\t\t|\t\t\t请选择功能列表\t\t\t\t|\n");
|
|
printf("\t\t\t|***************************************************************|\n");
|
|
printf("\t\t\t|\t\t\t1.录入学生信息\t\t\t\t|\n");
|
|
printf("\t\t\t|\t\t\t2.打印学生信息\t\t\t\t|\n");
|
|
printf("\t\t\t|\t\t\t3.保存学生信息\t\t\t\t|\n");
|
|
printf("\t\t\t|\t\t\t4.读取学生信息\t\t\t\t|\n");
|
|
printf("\t\t\t|\t\t\t5.查找学生信息\t\t\t\t|\n");
|
|
printf("\t\t\t|\t\t\t6.修改学生信息\t\t\t\t|\n");
|
|
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) //根据选择,调用不同的函数来完成不同的任务
|
|
{
|
|
case '1': //录入学生信息
|
|
Inputstudent();
|
|
break;
|
|
case '2': //打印学生信息
|
|
Printstudent();
|
|
break;
|
|
case '3': //保存学生信息
|
|
Savestudent();
|
|
break;
|
|
case '4': //读取学生信息
|
|
Readstudent();
|
|
break;
|
|
case '5': //查找学生信息
|
|
Lookstudent();
|
|
break;
|
|
case '6': //修改学生信息
|
|
Modifystudent();
|
|
break;
|
|
case '7': //删除学生信息
|
|
Deletestudent();
|
|
break;
|
|
case '0': //退出系统
|
|
system("cls");
|
|
yanshi("\n\n\n\n\n\t\t\t\tByeBye 欢迎再次使用!\n\n");
|
|
break;
|
|
default:
|
|
printf("您输入有误,请重新输入!\n\n");
|
|
break;
|
|
}
|
|
system("pause"); //程序暂停
|
|
system("cls"); //清屏语句
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void Inputstudent() //录入学生信息
|
|
{
|
|
system("cls"); //清屏语句
|
|
system("color 6F"); //清屏语句
|
|
node* pnewnode=(node*)malloc(sizeof(node)); //创建一个节点来存储新的学生
|
|
pnewnode->pnext=NULL;
|
|
//要将新节点插入到链表中
|
|
if(phead==NULL)
|
|
{
|
|
phead=pnewnode;
|
|
}
|
|
else
|
|
{
|
|
pnewnode->pnext=phead;
|
|
phead=pnewnode;
|
|
}
|
|
printf("\n");
|
|
printf("请输入学生学号:\n");
|
|
scanf("%s",pnewnode->stu.num);
|
|
|
|
printf("请输入学生姓名:\n");
|
|
scanf("%s",pnewnode->stu.name);
|
|
|
|
printf("请输入学生性别:\n");
|
|
scanf("%s",pnewnode->stu.sex);
|
|
|
|
printf("请输入学生年龄:\n");
|
|
scanf("%d",&pnewnode->stu.age);
|
|
|
|
printf("请输入学生生日:\n");
|
|
scanf("%s",pnewnode->stu.birth);
|
|
|
|
printf("请输入学生住址:\n");
|
|
scanf("%s",pnewnode->stu.home);
|
|
|
|
printf("请输入学生电话:\n");
|
|
scanf("%s",pnewnode->stu.tel);
|
|
|
|
printf("\n录入学生信息成功!\n\n");
|
|
|
|
}
|
|
|
|
void Printstudent() //打印学生信息
|
|
{
|
|
system("cls");
|
|
system("color 1A");
|
|
int count=0;
|
|
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; //定义一个当前节点
|
|
while(p!=NULL)
|
|
{
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
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;
|
|
count++;
|
|
}
|
|
printf("\t\t*****************************************************************************************\n");
|
|
printf("\t\t当前总人数: %d\t\t\t\n",count);
|
|
}
|
|
|
|
void Savestudent() //保存学生信息
|
|
{
|
|
system("cls");
|
|
system("color 1B");
|
|
FILE *fp;
|
|
fp=fopen("stu.dat","ab+"); //打开文件
|
|
if(fp==NULL)
|
|
{
|
|
printf("打开文件失败!\n\n");
|
|
return;
|
|
}
|
|
//写入数据
|
|
node* p=phead; //当前节点
|
|
while(p!=NULL)
|
|
{
|
|
fwrite(&p->stu,sizeof(student),1,fp);
|
|
p=p->pnext;
|
|
}
|
|
fclose(fp);
|
|
printf("\n\n数据存入成功!\n\n");
|
|
}
|
|
|
|
void Lookstudent() //查找学生信息
|
|
{
|
|
char name[20];
|
|
char num[12];
|
|
char ch;
|
|
node* p=phead; //定义一个当前节点
|
|
do{
|
|
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");
|
|
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|学号\t|姓名\t|性别\t|年龄\t|生日\t|家庭住址\t\t|本人电话\t\t|\n");
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
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);
|
|
printf("\t\t*****************************************************************************************\n");
|
|
system("pause");
|
|
}
|
|
p=p->pnext;
|
|
}
|
|
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|学号\t|姓名\t|性别\t|年龄\t|生日\t|家庭住址\t\t|本人电话\t\t|\n");
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
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);
|
|
printf("\t\t*****************************************************************************************\n");
|
|
system("pause");
|
|
}
|
|
p=p->pnext;
|
|
}
|
|
break;
|
|
case '0': //退出系统
|
|
system("cls");
|
|
yanshi("\n\n\n\n\t\t\t\t\tByeBye 欢迎再次使用!\n\n");
|
|
break;
|
|
default:
|
|
printf("您输入有误,请重新输入!\n\n");
|
|
system("pause");
|
|
break;
|
|
}
|
|
}
|
|
while(ch!='0');
|
|
}
|
|
|
|
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|学号\t|姓名\t|性别\t|年龄\t|生日\t|家庭住址\t\t|本人电话\t\t|\n");
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
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);
|
|
printf("\t\t*****************************************************************************************\n");
|
|
printf("\n请修改学生信息!\n");
|
|
|
|
printf("请输入学生学号:\n");
|
|
scanf("%s",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\n");
|
|
system("pause");
|
|
system("cls");
|
|
printf("\t\t*****************************************************************************************\n");
|
|
printf("\t\t|学号\t|姓名\t|性别\t|年龄\t|生日\t|家庭住址\t\t|本人电话\t\t|\n");
|
|
printf("\t\t|---------------------------------------------------------------------------------------|\n");
|
|
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);
|
|
printf("\t\t*****************************************************************************************\n");
|
|
}
|
|
p=p->pnext;
|
|
j++;
|
|
}
|
|
if(j==0)
|
|
{
|
|
printf("没有您要修改的学生信息!\n\n");
|
|
}
|
|
}
|
|
|
|
void Readstudent() //读取学生信息
|
|
{
|
|
system("cls");
|
|
system("color 0F");
|
|
FILE *fp;
|
|
fp=fopen("stu.dat","ab+");
|
|
if(fp==NULL)
|
|
{
|
|
printf("打开文件失败!\n\n");
|
|
return;
|
|
}
|
|
//读取数据
|
|
node* p=phead; //当前节点
|
|
fread(&p->stu,sizeof(student),1,fp);
|
|
while(!feof(fp))
|
|
{
|
|
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);
|
|
fread(&p->stu,sizeof(student),1,fp);
|
|
}
|
|
fclose(fp);
|
|
printf("\n\n数据读取完毕!!!\n\n");
|
|
}
|
|
|
|
void Deletestudent() //删除学生信息
|
|
{
|
|
system("cls");
|
|
system("color 6A");
|
|
char name[20];
|
|
int j=0;
|
|
node* p=phead; //定义一个当前节点
|
|
node* p1=phead;
|
|
printf("\n\n请输入要删除的学生姓名:\n");
|
|
scanf("%s",name);
|
|
while(strcmp(p->stu.name,name)!=0&&p!=NULL)
|
|
{
|
|
p1=p;
|
|
p=p->pnext;
|
|
}
|
|
|
|
if(strcmp(p->stu.name,name)==0)
|
|
{
|
|
if(p=phead)
|
|
{
|
|
phead=p->pnext;
|
|
}
|
|
else
|
|
p1->pnext=p->pnext;
|
|
}
|
|
printf("删除学生信息成功!\n\n");
|
|
printf("别忘记保存!\n\n");
|
|
}
|
|
|
|
void yanshi(char *p) //延时函数的定义
|
|
{
|
|
while (1)
|
|
{
|
|
if (*p!=0)
|
|
printf("%c",*p++);
|
|
else
|
|
break;
|
|
Sleep(100); //延时控制间断语句
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|