|
|
@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
|
|
|
#include<string.h>
|
|
|
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
|
|
|
#define M 40 //宏定义说明学生人数最多为50
|
|
|
|
|
|
|
|
FILE *fp; //定义文件指针
|
|
|
|
|
|
|
|
struct student /*结构体定义及声明 */
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char id[100]; /*学号*/
|
|
|
|
|
|
|
|
char name[100]; //姓名
|
|
|
|
|
|
|
|
char sex[50]; //性别
|
|
|
|
|
|
|
|
char minzu[100]; //民族
|
|
|
|
|
|
|
|
char jiguan[100];//籍贯
|
|
|
|
|
|
|
|
char adress[100]; //家庭住址
|
|
|
|
|
|
|
|
char num[100]; //联系电话
|
|
|
|
|
|
|
|
char idcard[100]; //身份证号码
|
|
|
|
|
|
|
|
} ;
|
|
|
|
|
|
|
|
void input(struct student stu[M]);//输入学生信息函数
|
|
|
|
|
|
|
|
void show(struct student stu[M]); //浏览所有学生信息函数
|
|
|
|
|
|
|
|
void seek(struct student stu[M]); //查找函数
|
|
|
|
|
|
|
|
void add(struct student stu[M]); //修改学生信息函数
|
|
|
|
|
|
|
|
void reduce(struct student stu[M]);//删除学生信息函数
|
|
|
|
|
|
|
|
void filewrite(struct student stu[M]);//将学生信息写入文件函数
|
|
|
|
|
|
|
|
void fileread(struct student stu[M]);//将学生信息读出文件函数
|
|
|
|
|
|
|
|
int count=0; //定义全局变量保存当前学生数
|
|
|
|
|
|
|
|
struct student stu[M];
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char ce;
|
|
|
|
|
|
|
|
int choice; //定义选择功能数的变量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\t\t\t\t欢迎你使用学生信息管理系统\n");//展示系统功能
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
printf("*****************************************************************\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t+ 学生信息管理系统 +\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t-------------------------------------------------\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t ***************\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t 1、添加学生信息 *\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t 2、浏览学生信息 *\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t 3、查询学生信息 *\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t 4、修改学生信息 *\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t 5、删除学生信息 *\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t 6、保存学生信息到文件 *\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t 7、读取文件中学生信息 *\n");
|
|
|
|
|
|
|
|
printf("*\t\t\t\t 8、退出系统 *\n");
|
|
|
|
|
|
|
|
printf("*****************************************************************\n");
|
|
|
|
|
|
|
|
printf("请输入你的选择\n");
|
|
|
|
|
|
|
|
do{
|
|
|
|
|
|
|
|
scanf("%c", &ce);
|
|
|
|
|
|
|
|
}while(ce>'8' || ce<'1');
|
|
|
|
|
|
|
|
choice = ce - '0';
|
|
|
|
|
|
|
|
switch (choice)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:input(stu);break;
|
|
|
|
|
|
|
|
case 2:show(stu);break;
|
|
|
|
|
|
|
|
case 3:seek(stu);break;
|
|
|
|
|
|
|
|
case 4:add(stu);break;
|
|
|
|
|
|
|
|
case 5:reduce(stu);break;
|
|
|
|
|
|
|
|
case 6:filewrite(stu);break;
|
|
|
|
|
|
|
|
case 7:fileread(stu);break;
|
|
|
|
|
|
|
|
case 8:printf("感谢您的使用");break;
|
|
|
|
|
|
|
|
default:printf("无效的选择,请您重新输入");break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}while(choice!=8);
|
|
|
|
|
|
|
|
printf("the program is over!!!\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void seek(struct student stu[M])//自定义查找函数
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int j;
|
|
|
|
|
|
|
|
FILE *FP;
|
|
|
|
|
|
|
|
//fp=fopen("f1.txt","r+");
|
|
|
|
|
|
|
|
char sh[20];
|
|
|
|
|
|
|
|
system("cls");//清屏作用
|
|
|
|
|
|
|
|
if(count==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("无法查询") ;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("请输入你想要查找的同学学号\n");
|
|
|
|
|
|
|
|
scanf("%s",sh); //输入所查询的内容
|
|
|
|
|
|
|
|
// fp=fopen("f1.txt","r+");
|
|
|
|
|
|
|
|
for (j=0;j<40;j++) ///执行循环查找信息
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strcmp(stu[j].id,sh)==0)//通过字符函数对已经存入的学生信息对比找到相关位置
|
|
|
|
|
|
|
|
printf("学号\t\t姓名\t性别\t民族\t籍贯\t家庭住址\t\t联系电话\t\t身份证号码\t\n");
|
|
|
|
|
|
|
|
printf("%s\t\t",stu[j].id);
|
|
|
|
|
|
|
|
printf("%s\t",stu[j].name);
|
|
|
|
|
|
|
|
printf("%s\t",stu[j].sex);
|
|
|
|
|
|
|
|
printf("%s\t",stu[j].minzu);
|
|
|
|
|
|
|
|
printf("%s\t",stu[j].jiguan);
|
|
|
|
|
|
|
|
printf("%s\t\t",stu[j].adress);
|
|
|
|
|
|
|
|
printf("%s\t\t",stu[j].num);
|
|
|
|
|
|
|
|
printf("%s",stu[j].idcard); break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(j==count)
|
|
|
|
|
|
|
|
printf("未找到您所查找的信息");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(struct student stu[M])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// FILE *FP;
|
|
|
|
|
|
|
|
// fp=fopen("f1.txt","r+");
|
|
|
|
|
|
|
|
char ch[20];
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
if(count==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("没有学生信息存在") ;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("请输入你想要修改的同学学号\n");
|
|
|
|
|
|
|
|
scanf("%s",&ch);
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
// fp=fopen("f1.txt","r+");
|
|
|
|
|
|
|
|
for (i=0;i<40;i++) ///执行循环查找信息
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strcmp(stu[i].id,ch)==0)
|
|
|
|
|
|
|
|
printf("学号\t\t姓名\t性别\t民族\t籍贯\t家庭住址\t\t联系电话\t\t身份证号码\t ");
|
|
|
|
|
|
|
|
printf("%s%s%s%s%s%s%s%s",stu[i].id,stu[i].name,stu[i].sex,stu[i].minzu,stu[i].jiguan,stu[i].adress,stu[i].num,stu[i].idcard);
|
|
|
|
|
|
|
|
printf("是否继续修改学生信息\n");
|
|
|
|
|
|
|
|
printf("请输入修改后的内容\n");
|
|
|
|
|
|
|
|
printf("学号\t\t姓名\t性别\t民族\t籍贯\t家庭住址\t\t联系电话\t\t身份证号码\t");
|
|
|
|
|
|
|
|
scanf("%s%s%s%s%s%s%s%s",stu[i].id,stu[i].name,stu[i].sex,stu[i].minzu,stu[i].jiguan,stu[i].adress,stu[i].num,stu[i].idcard);break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void reduce(struct student stu[M])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i=0,j,k=count;
|
|
|
|
|
|
|
|
char xh[20];
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printf("请输入您要删除的同学姓名");
|
|
|
|
|
|
|
|
scanf("%s",&xh);
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
for (j=0;j<count;j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strcmp(stu[j].name,xh)==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("学号\t\t姓名\t性别\t民族\t籍贯\t家庭住址\t\t联系电话\t\t身份证号码\t");
|
|
|
|
|
|
|
|
printf("%s%s%s%s%s%s%s%s%s",stu[j].id,stu[j].name,stu[j].sex,stu[j].minzu,stu[j].jiguan,stu[j].adress,stu[j].num,stu[j].idcard);
|
|
|
|
|
|
|
|
printf("确认删除该生信息");
|
|
|
|
|
|
|
|
for (j=i;j<count;j++)
|
|
|
|
|
|
|
|
stu[j]=stu[j+1];
|
|
|
|
|
|
|
|
count--;//总人数减少
|
|
|
|
|
|
|
|
if (count<k)
|
|
|
|
|
|
|
|
printf("信息删除成功");
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if(count==j)
|
|
|
|
|
|
|
|
printf("抱歉!!!没有你所需要删除的学生信息!*_*!\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void filewrite(struct student stu[M])//将学生信息写入文件函数
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int j;
|
|
|
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
FILE *fp; //定义文件指针
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printf("请选择是否要存入已输入的学生信息:'y'还是'n'???\n");
|
|
|
|
|
|
|
|
scanf("%s",&c);
|
|
|
|
|
|
|
|
//fflush(stdin);
|
|
|
|
|
|
|
|
// while(c!='y'&&c!='n')
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (c!='y'&&c!='n')
|
|
|
|
|
|
|
|
// printf("输入错误,请重新输入\n");
|
|
|
|
|
|
|
|
// printf("以下操作将会覆盖已存储的数据,确定请输入'y'或'n'???\n");
|
|
|
|
|
|
|
|
// scanf("%c",&c);
|
|
|
|
|
|
|
|
// //fflush(stdin);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//rintf("%s %s %s %s %s %s %s %s %s\n", stu[j].id,stu[j].name,stu[j].sex,stu[j].minzu,stu[j].jiguan,stu[j].adress,stu[j].num,stu[j].idcard);
|
|
|
|
|
|
|
|
if (c=='y')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if((fp=fopen("f1.txt","r+"))==NULL)//判断文件是否打开成功
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("文件打开错误,程序无法进行\n");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(j=0;j<count;j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//fprintf(fp, "%s %s %s %s %s %s %s %s %s\n", stu[j].id,stu[j].name,stu[j].sex,stu[j].minzu,stu[j].jiguan,stu[j].adress,stu[j].num,stu[j].idcard);
|
|
|
|
|
|
|
|
fprintf(fp,"%s\t",stu[j].id);
|
|
|
|
|
|
|
|
fprintf(fp,"%s\t",stu[j].name);
|
|
|
|
|
|
|
|
fprintf(fp,"%\t",stu[j].sex);
|
|
|
|
|
|
|
|
fprintf(fp,"%s\t",stu[j].minzu);
|
|
|
|
|
|
|
|
fprintf(fp,"%s\t",stu[j].jiguan);
|
|
|
|
|
|
|
|
fprintf(fp,"%s\t",stu[j].adress);
|
|
|
|
|
|
|
|
fprintf(fp,"%s\t",stu[j].num);
|
|
|
|
|
|
|
|
fprintf(fp,"%s\t",stu[j].idcard);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
system("pause");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void fileread(struct student stu[M]) //将学生信息读出
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int j=0;
|
|
|
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
printf("请选择是否要存入已输入的学生信息:'y'还是'n'???\n");
|
|
|
|
|
|
|
|
scanf("%s",&c);
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
// fflush(stdin);
|
|
|
|
|
|
|
|
// while(c!='y'&&c!='n')
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (c!='y'&&c!='n')
|
|
|
|
|
|
|
|
// printf("输入错误,请重新输入\n");
|
|
|
|
|
|
|
|
// printf("以下操作将会覆盖已存储的数据,确定请输入'y'或'n'???\n");
|
|
|
|
|
|
|
|
// scanf("%c",&c);
|
|
|
|
|
|
|
|
// fflush(stdin);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (c=='y')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if((fp=fopen("f1.txt","r+"))==NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("文件打开错误,程序无法进行\n");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// fread(&stu[j],sizeof(struct student),1,fp);
|
|
|
|
|
|
|
|
// count=0;
|
|
|
|
|
|
|
|
// count++;
|
|
|
|
|
|
|
|
// j++;
|
|
|
|
|
|
|
|
// while(fread(&stu[j],sizeof(struct student),1,fp))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// j++;
|
|
|
|
|
|
|
|
// count++;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//fprintf(fp, "%s %s %s %s %s %s %s %s %s\n", stu[j].id,stu[j].name,stu[j].sex,stu[j].minzu,stu[j].jiguan,stu[j].adress,stu[j].num,stu[j].idcard);
|
|
|
|
|
|
|
|
while(fscanf(fp,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t",stu[j].id,stu[j].name,stu[j].sex,stu[j].minzu,stu[j].jiguan,stu[j].adress,stu[j].num,stu[j].idcard)!=EOF)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
printf("数据读取完毕!!!\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
system("pause");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void input(struct student stu[M]) //自定义输入函数
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char a;
|
|
|
|
|
|
|
|
system("cls");//清屏作用
|
|
|
|
|
|
|
|
printf("请添加要输入学生的信息\n");
|
|
|
|
|
|
|
|
printf("请输入由6位数字组成的学生学号:\n");
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
scanf("%s",stu[count].id);
|
|
|
|
|
|
|
|
printf("请输入学生姓名:\n");
|
|
|
|
|
|
|
|
fflush(stdin);//
|
|
|
|
|
|
|
|
scanf("%s",stu[count].name);
|
|
|
|
|
|
|
|
printf("请输入学生性别:\n");
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
scanf("%s",stu[count].sex);
|
|
|
|
|
|
|
|
printf("请输入学生民族:\n");
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
scanf("%s",stu[count].minzu);
|
|
|
|
|
|
|
|
printf("请输入学生籍贯:\n");
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
scanf("%s",stu[count].jiguan);
|
|
|
|
|
|
|
|
printf("请输入学生家庭住址:\n");
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
scanf("%s",stu[count].adress);
|
|
|
|
|
|
|
|
printf("电话\n");
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
scanf("%s",stu[count].num);
|
|
|
|
|
|
|
|
printf("请输入由18位数字组成的学生身份证号码:\n");
|
|
|
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
scanf("%s",stu[count].idcard);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
// printf("是否要将此信息保存?y/n");
|
|
|
|
|
|
|
|
// scanf("%s",&a);
|
|
|
|
|
|
|
|
// if(a=='y')
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// //filewrite(stu);
|
|
|
|
|
|
|
|
// input(stu);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else
|
|
|
|
|
|
|
|
// printf("您确定不存储");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void show(struct student stu[M])//自定义输出函数
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int j;
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
if (count==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("当前学生信息为0个\n");
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(j=0; j<count; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("学号\t\t姓名\t性别\t民族\t籍贯\t家庭住址\t\t联系电话\t\t身份证号码\n") ;
|
|
|
|
|
|
|
|
for(j=0; j<10; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%s\t\t",stu[j].id);
|
|
|
|
|
|
|
|
printf("%s\t",stu[j].name);
|
|
|
|
|
|
|
|
printf("%s\t",stu[j].sex);
|
|
|
|
|
|
|
|
printf("%s\t",stu[j].minzu);
|
|
|
|
|
|
|
|
printf("%s\t",stu[j].jiguan);
|
|
|
|
|
|
|
|
printf("%s\t\t",stu[j].adress);
|
|
|
|
|
|
|
|
printf("%s\t\t",stu[j].num);
|
|
|
|
|
|
|
|
printf("%s\n",stu[j].idcard);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|