|
|
|
@ -0,0 +1,295 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <conio.h>
|
|
|
|
|
#define N 2
|
|
|
|
|
struct student
|
|
|
|
|
{
|
|
|
|
|
char name[10];
|
|
|
|
|
char no[100];
|
|
|
|
|
char sex;
|
|
|
|
|
int age;
|
|
|
|
|
char bnote[100];
|
|
|
|
|
};
|
|
|
|
|
void print(bool menu)//打印基本信息
|
|
|
|
|
{
|
|
|
|
|
if (!menu)
|
|
|
|
|
{
|
|
|
|
|
printf(" \t \t \t (欢迎使用本班级档案管理系统)\t\t\t\t\n");
|
|
|
|
|
printf("★*★*★*★*★*★*★*★*★*★ 欢迎进入我们的系统 ★*★*★*★*★*★*★*★*★*★\n\n");
|
|
|
|
|
printf("学生基本信息录入 ,press 1\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("学生基本信息显示 ,press 2\n");
|
|
|
|
|
printf("学生基本信息保存 ,press 3\n");
|
|
|
|
|
printf("学生基本信息删除 ,press 4\n");
|
|
|
|
|
printf("学生基本信息修改 ,press 5\n");
|
|
|
|
|
printf("学生基本信息查询 ,press 6\n");
|
|
|
|
|
}
|
|
|
|
|
printf("退出学生信息系统 ,press 7\n");
|
|
|
|
|
}
|
|
|
|
|
bool Check(char pas[6])//密码验证
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char ch;
|
|
|
|
|
char a[7]={" "};
|
|
|
|
|
int i = 0;
|
|
|
|
|
if ((fp=fopen("D:\\1.txt","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("打开文件失败!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
ch=fgetc(fp);
|
|
|
|
|
while (ch!=EOF&&i<6)
|
|
|
|
|
{
|
|
|
|
|
a[i] = ch;
|
|
|
|
|
ch=fgetc(fp);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
a[6] = '\0';
|
|
|
|
|
if (!strcmp(pas,a))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("密码错误\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void GetInfo(struct student *arr,int n)//学生基本信息录入
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for (int i = 0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("输入学生的基本信息:name no sex age bnote\n");
|
|
|
|
|
scanf("%s %s %c %d %s",arr[i].name,arr[i].no,&arr[i].sex,&arr[i].age,arr[i].bnote);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void Display(struct student* arr,int n)//学生基本信息显示
|
|
|
|
|
{
|
|
|
|
|
printf("学生信息: Name NO Sex age Note\n");
|
|
|
|
|
for (int i = 0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("%12s%12s%12c%12d%12s\n",arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Save(struct student* arr,int n)//学生基本信息保存,保存在c:\\student.txt
|
|
|
|
|
{
|
|
|
|
|
FILE * fp;
|
|
|
|
|
fp= fopen("student.txt","w+");
|
|
|
|
|
if (fp == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("文件不存在!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fwrite(arr,sizeof(struct student)*n,n,fp);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Modfiy(struct student* arr,int n)//学生基本信息修改
|
|
|
|
|
{
|
|
|
|
|
char number[100];
|
|
|
|
|
bool flag=false;
|
|
|
|
|
char pass[6];
|
|
|
|
|
printf("请输入密码:\n");
|
|
|
|
|
scanf("%s",pass);
|
|
|
|
|
if (Check(pass))
|
|
|
|
|
{
|
|
|
|
|
printf("修改学生信息:\n");
|
|
|
|
|
printf("请输入学号:\n");
|
|
|
|
|
scanf("%s",number);
|
|
|
|
|
for (int i =0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(number,arr[i].no))
|
|
|
|
|
{
|
|
|
|
|
printf("infor: name no sex age note\n");
|
|
|
|
|
printf("%s %s %c %d %s\n",arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
|
|
|
|
|
printf("please input information:\n");
|
|
|
|
|
scanf("%s%s%c%d%s",arr[i].name,arr[i].no,&arr[i].sex,&arr[i].age,arr[i].bnote);
|
|
|
|
|
Save(arr,n);
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flag == false)
|
|
|
|
|
{
|
|
|
|
|
printf("该学生不存在!:\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Delete(struct student* arr,int n)//学生基本信息删除
|
|
|
|
|
{
|
|
|
|
|
char number[100];
|
|
|
|
|
bool flag=false;
|
|
|
|
|
printf("Delete information:\n");
|
|
|
|
|
printf("请输入学号:\n");
|
|
|
|
|
scanf("%s",number);
|
|
|
|
|
for (int i =0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(number,arr[i].no))
|
|
|
|
|
{
|
|
|
|
|
strcpy(arr[i].name," ");
|
|
|
|
|
strcpy(arr[i].no," ");
|
|
|
|
|
strcpy(arr[i].bnote," ");
|
|
|
|
|
arr[i].sex = ' ';
|
|
|
|
|
arr[i].age =0;
|
|
|
|
|
Save(arr,n);
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flag == false)
|
|
|
|
|
{
|
|
|
|
|
printf("该学生不存在!:\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void Search(struct student* arr,int n)//学生基本信息查询
|
|
|
|
|
{
|
|
|
|
|
int temp,i;
|
|
|
|
|
bool flag=false;
|
|
|
|
|
printf("--------------通过学号查询,press 1-------------\n");
|
|
|
|
|
printf("---------------通过姓名查询,press 2-----------\n");
|
|
|
|
|
printf("---------------通过性别查询,press 3------------\n");
|
|
|
|
|
printf("---------------通过年龄查询,press 4------------\n");
|
|
|
|
|
printf("---------------退出,press 5 ------------\n");
|
|
|
|
|
scanf("%d",&temp);
|
|
|
|
|
switch (temp)
|
|
|
|
|
{
|
|
|
|
|
case 1://按照学号查询
|
|
|
|
|
{
|
|
|
|
|
char num[100];
|
|
|
|
|
printf("请输入学号:\n");
|
|
|
|
|
scanf("%s",num);
|
|
|
|
|
for ( i =0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(num,arr[i].no))
|
|
|
|
|
{
|
|
|
|
|
printf("%12s%12s%12c%12d%12s\n",arr[i].name,arr[i].no,
|
|
|
|
|
arr[i].sex,arr[i].age,arr[i].bnote);
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
printf("该学生不存在.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2://按照名字查询
|
|
|
|
|
{
|
|
|
|
|
char num[10];
|
|
|
|
|
printf("please input name:\n");
|
|
|
|
|
scanf("%s",num);
|
|
|
|
|
for ( i =0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(num,arr[i].name))
|
|
|
|
|
{
|
|
|
|
|
printf("%-12s%-12s%-12c%-12d%-12s",arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
printf("该学生不存在.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3://按照性别查询
|
|
|
|
|
{
|
|
|
|
|
char ch;
|
|
|
|
|
printf("请输入性别:\n");
|
|
|
|
|
//scanf("%c",&ch);
|
|
|
|
|
ch = getch();
|
|
|
|
|
for ( i =0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
if (ch == arr[i].sex)
|
|
|
|
|
{
|
|
|
|
|
printf("%12s%12s%12c%12d%12s\n",arr[i].name,arr[i].no,
|
|
|
|
|
arr[i].sex,arr[i].age,arr[i].bnote);
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
printf("t该学生不存在.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4://按照年龄查询
|
|
|
|
|
{
|
|
|
|
|
char num_age;
|
|
|
|
|
printf("请输入年龄:\n");
|
|
|
|
|
scanf("%d",&num_age);
|
|
|
|
|
for ( i =0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
if (num_age == arr[i].age)
|
|
|
|
|
{
|
|
|
|
|
printf("%12s%12s%12c%12d%12s\n",arr[i].name,arr[i].no,
|
|
|
|
|
arr[i].sex,arr[i].age,arr[i].bnote);
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
printf("该学生不存在.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
struct student arr[N];
|
|
|
|
|
char ps[6];
|
|
|
|
|
bool flag =false;
|
|
|
|
|
printf("请输入密码:\n");
|
|
|
|
|
scanf("%s",ps);
|
|
|
|
|
flag = Check(ps);
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
int select;
|
|
|
|
|
print(false);
|
|
|
|
|
scanf("%d",&select);
|
|
|
|
|
while (0<select && select <7 )
|
|
|
|
|
{
|
|
|
|
|
switch (select)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
GetInfo(arr,N);
|
|
|
|
|
print(true);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
Display(arr,N);
|
|
|
|
|
print(true);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
Save(arr,N);
|
|
|
|
|
print(true);
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
Delete(arr,N);
|
|
|
|
|
print(true);
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
Modfiy(arr,N);
|
|
|
|
|
print(true);
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
Search(arr,N);
|
|
|
|
|
print(true);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
printf("请选择:\n");
|
|
|
|
|
scanf("%d",&select);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|