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.

222 lines
4.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
int n=0,i;
struct address_book
{
char name[20];
int num;
int age;
char place[80];
char sex;
char clas[40];
char department[40];
char domain[40];
char dowhat[20];
}stud[200];
void add()
{
char j;
front1:
system("cls");//清屏
printf("\n请输入要添加的姓名:");
scanf("%s",stud[n].name);
printf("\n请输入要添加的学号8位");
scanf("%d",&stud[n].num);
printf("\n请输入要添加的性别F/M");
scanf("\n%c",&stud[n].sex);
printf("\n请输入要添加的年龄:");
scanf("%d",&stud[n].age);
printf("\n请输入要添加的班级:");
scanf("%s",stud[n].clas);
printf("\n请输入要添加的籍贯:");
scanf("%s",stud[n].place);
printf("\n请输入要添加的系别:");
scanf("%s",stud[n].department);
printf("\n请输入要添加的专业:");
scanf("%s",stud[n].domain);
printf("\n请输入学籍变化:");
scanf("%s",stud[n].dowhat);
getchar();
n++;
printf("是否继续Y/N?");
j=getchar();
getchar();
if(j=='y'||j=='Y') goto front1;//再次输入记录
}
void del()
{
int k=0,m,i;
char j;
front2:
system("cls");//清屏
printf("\n请输入要删除的学号:");
scanf("%d",&m);
getchar();
for(i=0;i<n;i++)//查找记录
if(m==stud[i].num)
{
k=1;
break;
}
if(k==1)//删除记录
{
for(k=i;k<n-1;k++)
stud[k]=stud[k+1];
n--;
printf("已删除\n\n");
}
else
{
printf("找不到要删除的记录!\n");
printf("按回车键返回:");
getchar();
}
printf("是否继续Y/N");
j=getchar();
getchar();
if(j=='y'||j=='Y') goto front2;
getchar();
}
void arrange()
{
int k,i;
struct address_book t;
system("cls");//清屏
printf("学号 专业 籍贯\n");
for(k=0;k<n-1;k++)
for(i=0;i<n-k-1;i++)
if(stud[i].num>stud[i+1].num)
{
t=stud[i];
stud[i]=stud[i+1];
stud[i+1]=t;
}
for(i=0;i<=n-1;i++)
if(stud[i].num!=0)
printf("%-8d %-10s %-10s\n",stud[i].num,stud[i].domain,stud[i].place);
printf("按回车键返回!");
getchar();
getchar();
}
void change()
{
int k=0,m;
char j;
front5:
system("cls");//清屏
printf("\n请输入要修改记录的学号:");
scanf("%d",&m);
getchar();
for(i=0;i<n;i++)//查找
if(m==stud[i].num)
{
k=1;
break;
}
if(k==1)
{
printf("\n请输入要修改的姓名:");
scanf("%s",stud[i].name);
printf("\n请输入要修改的学号8位");
scanf("%d",&stud[i].num);
printf("\n请输入要修改的性别F/M");
scanf("%c",&stud[i].sex);
printf("\n请输入要修改的年龄:");
scanf("%d",&stud[i].age);
printf("\n请输入要修改的班级:");
scanf("%s",stud[i].clas);
printf("\n请输入要修改的籍贯:");
scanf("%s",stud[i].place);
printf("\n请输入要修改的系别:");
scanf("%s",stud[i].department);
printf("\n请输入要修改的专业:");
scanf("%s",stud[i].domain);
printf("\n请输入要修改的学籍变化:");
scanf("%s",stud[n].dowhat);
getchar();
}
if(k==0)
{
printf("找不到要修改的记录!\n");
printf("按回车键返回:");
getchar();
}
getchar();
printf("是否继续Y/N");
j=getchar();
getchar();
if(j=='y'||j=='Y') goto front5;
}
void find()
{
int k=0,m;
char j;
front3:
system("cls");//清屏
printf("\n请输入要查找的学生的学号:");
scanf("%d",&m);
getchar();
for(i=0;i<n;i++)//查找
if(m==stud[i].num)
{
k=1;
break;
}
if(k==1)
{
printf("姓名 学号 性别 年龄 班级 籍贯 系别 专业 学籍变化\n");
printf("%-8s%-8d%8c%-8d%-10s%-10s%-10s%-10s%-8s\n",stud[i].name,stud[i].num,stud[i].sex,stud[i].age,stud[i].clas,stud[i].place,stud[i].department,stud[i].domain,stud[i].dowhat);
}
else
{
printf("找不到该同学!请重新输入!按回车返回!");
getchar();
goto front3;
}
printf("是否继续Y/N");
j=getchar();
getchar();
if(j=='y'||j=='Y') goto front3;
}
void main()
{
char j;
printf("\n\n\n\n\n\n\t\t\t 欢迎使用学生学籍管理系统");
printf("\n\n\n\t\t\t\t制作人:王淑静");
printf("\n\n\n\t\t\t\t 2019年1月");
printf("\n\n\n\n\n\n\n\n\n\n\n\n按回车键进入主菜单:");
getchar();
loop:
system("cls");
printf("\n");
printf("\t\t\t\t ************\n");
printf("\t\t\t\t ***主菜单***\n");
printf("\t\t\t\t ************\n\n\n\n\n\n");
printf("\t\t 1、录入学生信息2、删除学生信息\n\n");
printf("\t\t 3、查找学生信息4、学生信息排序\n\n");
printf("\t\t 5、修改学生信息6、保存退出系统\n\n");
printf("\n\n\n\n\n\n\n\n\n请选择[1/2/3/4/5/6]:");
j=getchar();
if(j=='\n') goto loop;//返回主菜单
switch(j)
{
case '1': add();goto loop;//返回主菜单
case '2': del();goto loop;
case '3': find();goto loop;
case '4': arrange();goto loop;
case '5': change();goto loop;
case '6':
{
FILE *fp;
fp=fopen("student.dat","w");
for(i=0;i<n;i++)
fwrite(&stud[i],sizeof(struct address_book),1,fp);
fclose(fp);
exit(0);
}
default: goto loop;
}
}