first commit

master
易美美 6 years ago
commit cc4ca16329

220
01.cpp

@ -0,0 +1,220 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#define N 100
struct student
{
char id[10];
char name[25];
char sex[10];
int age;
char jiguan[25];
char xibie[25];
char zhuanye[25];
int ban;
}stu[N];
void menu()
{
int choice,w1;
void add();void find();void shanchu();void change();void tongji();void read();void input();
do
{
puts("\t--------------------------------------------------------");
puts("\t| 欢迎使用学籍管理系统 |");
puts("\t|------------------------------------------------------|");
puts("\t| 1.录入学生资料 |");
puts("\t| 2.查找学生资料 |");
puts("\t| 3.删除学生资料 |");
puts("\t| 4.修改学生资料 |");
puts("\t| 5.按学号或专业输出学生资料 |");
puts("\t| 6.查看所有学生资料 |");
puts("\t| 7.退出系统 |");
puts("\t--------------------------------------------------------");
printf("想选择的功能:");
scanf("%d",&choice);
if(choice<1||choice>8)
{w1=1;system("cls");printf("菜单选择错,请重新选择!\n");}
else w1=0;
}while(w1==1);
switch (choice)
{
case 1:
add();
break;
case 2:
find();
break;
case 3:
shanchu();
break;
case 4:
change();
break;
case 5:
tongji();
break;
case 6:
read();
break;
case 7:
break;
default: exit(0);
}
}
int load()
{
FILE *fp;
int i;
if ((fp=fopen("results.txt","rb"))==NULL)
{
printf("文件打开错误");
return 0;
}
for (i=0;!feof(fp);i++)fread(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
return(i-1);
}
void save(int n)
{
int i;
FILE *fp;
if ((fp=fopen("results.txt","wb"))==NULL)
{
printf("文件打开错误:");
}
for (i=0;i<n;i++)fwrite(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
}
void read()
{
int n,m;
n=load();
printf("学号\t姓名\t性别\t年龄\t籍贯\t系别\t专业\t班级\t");
for (m=0;m<n;m++)
{
printf("\n%s",stu[m].id);
printf("\t%s",stu[m].name);
printf("\t%s",stu[m].sex);
printf("\t%d",stu[m].age);
printf("\t%s",stu[m].jiguan);
printf("\t%s",stu[m].xibie);
printf("\t%s",stu[m].zhuanye);
printf("\t%d",stu[m].ban);
}
{
int xz,choice;
do
{
printf("\n1-返回主菜单2-退出系统\n");
scanf("%d",&choice);
if(choice<1||choice>2)
{xz=1;system("cls");printf("输入错误,请重新选择!\n");}
else xz=0;
}while(xz==1);
switch(choice)
{
case 1:
menu(); break;
case 2:
exit(0); break;
}
}
}
void add()
{
FILE *fp;
int i,n,m;
n=load();
if ((fp=fopen("results.txt","wb"))==NULL)
{
printf("文件打开错误!\n");
exit(1);
}
printf("你想要录入多少个学生信息?");
scanf("%d",&m);
for (i=0;i<m;i++)
{
printf("\n学号:");
scanf("%s",stu[n+i].id);
printf("姓名:");
scanf("%s",stu[n+i].name);
printf("性别:");
scanf("%s",stu[n+i].sex);
printf("年龄:");
scanf("%d",&stu[n+i].age);
printf("籍贯:");
scanf("%s",stu[n+i].jiguan);
printf("系别:");
scanf("%s",stu[n+i].xibie);
printf("专业:");
scanf("%s",stu[n+i].zhuanye);
printf("班级:");
scanf("%d",&stu[n+i].ban);
printf("输入完成");
save(n+m);
}
for (i=0;i<m;i++)fwrite(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
{
int xz,choice;
do
{
printf("\n1-返回主菜单2-退出系统\n");
scanf("%d",&choice);
if(choice<1||choice>2)
{xz=1;system("cls");printf("输入错误,请重新选择!\n");}
else xz=0;
}while(xz==1);
switch(choice)
{
case 1:
menu(); break;
case 2:
exit(0); break;
}
}
}
void find()
{
int meau();
int n,i;
char m[10];
n=load();
printf("\t\t\t欢迎使用学号查找功能\n请输入你需要查找的学生的学号:");
scanf("%s",&m);
for (i=0;i<n;i++)
{ if (!strcmp(stu[i].id,m))
{
printf("学号\t姓名\t性别\t年龄\t籍贯\t系别\t专业\t班级\n");
printf("%s",stu[i].id);
printf("\t%s",stu[i].name);
printf("\t%s",stu[i].sex);
printf("\t%d",stu[i].age);
printf("\t%s",stu[i].jiguan);
printf("\t%s",stu[i].xibie);
printf("\t%s",stu[i].zhuanye);
printf("\t%d\n",stu[i].ban);
}
}
{
int xz,choice;
do
{
printf("\n1-返回主菜单2-退出系统\n");
scanf("%d",&choice);
if(choice<1||choice>2)
{xz=1;system("cls");printf("输入错误,请重新选择!\n");}
else xz=0;
}while(xz==1);
switch(choice)
{
case 1:
menu(); break;
case 2:
exit(0); break;
}
}
}
Loading…
Cancel
Save