commit
ce0f176644
@ -0,0 +1,248 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
void student_add();
|
||||
void student_ll();
|
||||
void student_xhcx();
|
||||
void student_xmcx();
|
||||
void student_xg();
|
||||
void student_sc();
|
||||
int flag=1;
|
||||
int main()
|
||||
{
|
||||
int xuanze;
|
||||
system("cls");
|
||||
loop:
|
||||
printf("\t\t\t\t********** 学生信息管理系统 **********");
|
||||
printf("\n\n\n\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 0.退出系统 \n");
|
||||
printf("请你选择(0-6): \n");
|
||||
scanf("%d",&xuanze);
|
||||
switch(xuanze)
|
||||
{
|
||||
case 0:break;
|
||||
case 1:student_add();break;
|
||||
case 2:student_ll();break;
|
||||
case 3:student_xhcx();break;
|
||||
case 4:student_xmcx();break;
|
||||
case 5:student_xg();break;
|
||||
case 6:student_sc();break;
|
||||
default:printf("你的选择有误!请重新选择!");goto loop;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct student
|
||||
{
|
||||
char xuehao[20];
|
||||
char xingming[20];
|
||||
char nianling[20];
|
||||
char xingbie[20];
|
||||
char nianyue[20];
|
||||
char dizhi[1000];
|
||||
char dianhua[20];
|
||||
char email[1000];
|
||||
}stu;
|
||||
|
||||
void student_add()
|
||||
{
|
||||
int main();
|
||||
FILE *fp;
|
||||
struct student stu;
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
system("cls");
|
||||
fp=fopen("student.txt","a+");
|
||||
if(fp==NULL)
|
||||
printf("open file error!");
|
||||
else
|
||||
{
|
||||
while(flag)
|
||||
{
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
printf("请依次输入该同学的学号、姓名、年龄、性别、年月、地址、电话、电子邮箱:\n");
|
||||
scanf("%s%s%s%s%s%s%s%s",stu.xuehao,stu.xingming,stu.nianling,stu.xingbie,stu.nianyue,stu.dizhi,stu.dianhua,stu.email);
|
||||
fprintf(fp,"%s %s %s %s %s %s %s %s\n",stu.xuehao,stu.xingming,stu.nianling,stu.xingbie,stu.nianyue,stu.dizhi,stu.dianhua,stu.email);
|
||||
printf(" press '1'to continue,'0' exit:");
|
||||
scanf("%d",&flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
main();
|
||||
}
|
||||
void student_ll()
|
||||
{
|
||||
char a[50],b[50],c[50],d[50],e[50],f[50],g[50],h[50];
|
||||
system("cls");
|
||||
freopen("student.txt","r",stdin);
|
||||
printf("学号 姓名 年龄 性别 年月 地址 电话 电子邮箱\n");
|
||||
while(scanf("%s%s%s%s%s%s%s%s",a,b,c,d,e,f,g,h)!=EOF)
|
||||
{
|
||||
printf("%s %s %s %s %s %s %s %s\n",a,b,c,d,e,f,g,h);
|
||||
}
|
||||
return ;
|
||||
}
|
||||
void student_xhcx()
|
||||
{
|
||||
FILE *fp;
|
||||
struct student stu;
|
||||
char xh[20];
|
||||
system("cls");
|
||||
printf("输入你想要查询的同学学号:\n");
|
||||
scanf("%s",xh);
|
||||
fp=fopen("student.txt","r");
|
||||
if(fp==NULL)
|
||||
printf("open file error!");
|
||||
else
|
||||
{
|
||||
for(;!feof(fp);)
|
||||
{
|
||||
fscanf(fp,"%s%s%s%s%s%s%s%s",stu.xuehao,stu.xingming,stu.nianling,stu.xingbie,stu.nianyue,stu.dizhi,stu.dianhua,stu.email);
|
||||
if(strcmp(xh,stu.xuehao)==0)
|
||||
{
|
||||
printf("以下是该同学的信息:\n");
|
||||
printf("%s %s %s %s %s %s %s %s\n",stu.xuehao,stu.xingming,stu.nianling,stu.xingbie,stu.nianyue,stu.dizhi,stu.dianhua,stu.email);
|
||||
}
|
||||
if(strcmp(xh,stu.xuehao)!=0)
|
||||
printf("没有你想要查看的同学的任何信息!请重新运行程序!\n");break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
void student_xmcx()
|
||||
{
|
||||
FILE *fp;
|
||||
struct student stu;
|
||||
char xm[40];
|
||||
system("cls");
|
||||
printf("输入你想要查询的同学姓名:\n");
|
||||
scanf("%s",xm);
|
||||
fp=fopen("student.txt","r");
|
||||
if(fp==NULL)
|
||||
printf("open file error!");
|
||||
else
|
||||
{
|
||||
for(;!feof(fp);)
|
||||
{
|
||||
fscanf(fp,"%s%s%s%s%s%s%s%s",stu.xuehao,stu.xingming,stu.nianling,stu.xingbie,stu.nianyue,stu.dizhi,stu.dianhua,stu.email);
|
||||
if(strcmp(xm,stu.xingming)==0)
|
||||
{
|
||||
printf("以下是该同学的信息:\n");
|
||||
printf("%s %s %s %s %s %s %s %s\n",stu.xuehao,stu.xingming,stu.nianling,stu.xingbie,stu.nianyue,stu.dizhi,stu.dianhua,stu.email);
|
||||
}
|
||||
if(strcmp(xm,stu.xingming)!=0)
|
||||
printf("没有你想要查看的同学的任何信息!请重新运行程序!\n");break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
void student_xg()
|
||||
{struct student stu;
|
||||
char xh[50],s[100],buf[100][50];
|
||||
memset(buf,0,sizeof(buf));
|
||||
printf("输入你想要修改的同学学号:\n");
|
||||
scanf("%s",xh);int ok=0;
|
||||
int cout,len=strlen(xh),i,p=0;
|
||||
freopen("student.txt","r",stdin);
|
||||
while(gets(s))
|
||||
{cout=0;
|
||||
for(i=0;i<strlen(xh);i++)
|
||||
{
|
||||
if(xh[i]==s[i])cout++;
|
||||
}
|
||||
if(cout==len){ok=1;break;}
|
||||
}
|
||||
freopen("CON","r",stdin);
|
||||
freopen("CON","w",stdout);
|
||||
if(ok)
|
||||
{
|
||||
char f[100];int op;
|
||||
printf("输入你想修改的选项:1.地址 2.电话 3.电子邮箱\n");
|
||||
scanf("%d",&op);
|
||||
printf("输入你想修改的内容:\n");
|
||||
scanf("%s",f);
|
||||
freopen("student.txt","r",stdin);
|
||||
while(scanf("%s%s%s%s%s%s%s%s\n",stu.xuehao,stu.xingming,stu.nianling,stu.xingbie,stu.nianyue,stu.dizhi,stu.dianhua,stu.email)!=EOF)
|
||||
{
|
||||
if(strcmp(stu.xuehao,xh)==0)//找到这个学生了
|
||||
{
|
||||
if(op==1)
|
||||
{
|
||||
strcpy(stu.dizhi,f);
|
||||
|
||||
}
|
||||
else if(op==2)
|
||||
{
|
||||
strcpy(stu.dianhua,f);
|
||||
}
|
||||
else if(op==3)
|
||||
{
|
||||
strcpy(stu.email,f);
|
||||
|
||||
}
|
||||
strcat(buf[p],stu.xuehao);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.xingming);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.nianling);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.xingbie);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.nianyue);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.dizhi);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.dianhua);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.email);buf[p][strlen(buf[p])]=' ';
|
||||
p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat(buf[p],stu.xuehao);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.xingming);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.nianling);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.xingbie);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.nianyue);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.dizhi);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.dianhua);buf[p][strlen(buf[p])]=' ';
|
||||
strcat(buf[p],stu.email);buf[p][strlen(buf[p])]=' ';
|
||||
p++;
|
||||
}
|
||||
}
|
||||
freopen("student.txt","w",stdout);
|
||||
for(i=0;i<p;i++)
|
||||
{
|
||||
printf("%s\n",buf[i]);
|
||||
}
|
||||
freopen("CON","r",stdin);
|
||||
freopen("CON","w",stdout);
|
||||
}
|
||||
else printf("没有找到该学生信息!\n");
|
||||
}
|
||||
void student_sc()
|
||||
{
|
||||
char s[100],a[100],b[300],buf[30][100];
|
||||
printf("你要删除的学生学号:\n");
|
||||
scanf("%s",s);
|
||||
memset(buf,0,sizeof(buf));
|
||||
freopen("student.txt","r",stdin);
|
||||
int i=0,j;
|
||||
while(scanf("%s",a)!=EOF)
|
||||
{
|
||||
|
||||
gets(b);
|
||||
if(strcmp(s,a)!=0)
|
||||
{strcat(buf[i],a);
|
||||
strcat(buf[i++],b);}
|
||||
}
|
||||
freopen("student.txt","w",stdout);
|
||||
for(j=0;j<i;j++)
|
||||
{
|
||||
printf("%s\n",buf[j]);
|
||||
}
|
||||
freopen("CON","r",stdin);
|
||||
freopen("CON","w",stdout);
|
||||
}
|
Loading…
Reference in new issue