C语言下简单的学籍管理系统源代码

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include

#include

#include

#include

#include

#define N 10000

void window();

typedef struct student

{

char ID[10];

char name[20];

char sex;

float score[5];

float total;

float ag;

} STU;

FILE *fp;

STU stu[N];

STU stu1[N];

void tj(int i)

{

int j,k,m=0,flag=0,n=0,flag1;

printf("请输入第%d个学生信息\n",i+1);

do

{

flag=0;

printf("请输入学生学号(学号小于9位数字组成)\n");

scanf("%s",&stu[i].ID);

for(k=i-1; k>=0; k--)

if(strcmp(stu[k].ID,stu[i].ID)==0)

{

printf("输入错误,请重新输入\n");

flag=1;

break;

}

if(strlen(stu[i].ID)>8)

{

printf("输入错误,请重新输入\n");

flag=1;

}

for(k=0; k

if(strcmp(stu1[k].ID,stu[i].ID)==0)

{

printf("输入错误,请重新输入\n");

flag=1;

break;

}

}

while(flag);

do

{

flag=0;

printf("请输入学生姓名\n");

scanf("%s",stu[i].name);

}

while(flag);

do

{

getchar();

printf("请输入学生性别(f或m f代表女性m代表男性)\n");

scanf("%c",&stu[i].sex);

if((stu[i].sex)!='f'&&(stu[i].sex)!='m')

{

printf("输入错误,请重新输入\n");

flag=1;

}

else flag=0;

}

while(flag);

printf("请输入五门课成绩(输入成绩无顺序,成绩0~100)\n"); printf("每次只输入一门\n");

stu[i].total=0;

for(j=0; j<5; j++)

{

do

{

printf("输入第%d科",j+1);

scanf("%f",&stu[i].score[j]);

if(stu[i].score[j]<0.0||stu[i].score[j]>100.0)

{

flag1=1;

printf("第%d科成绩输入错误,请重新输入\n",j+1);

}

else

flag1=0;

stu[i].total=stu[i].total+stu[i].score[j];

}

stu[i].ag=stu[i].total/5;

}

}

void add()

{

int i=0,j,n=0,be;

char ch;

if((fp=fopen("d:\\student.dat","a+"))==NULL)

{

printf("打开文件失败\n");

system("pause");

window();

}

for(i=0; fread(&stu1[i],sizeof(STU),1,fp)!=0; i++);

be=n=i;

fclose(fp);

while(1)

{

tj(n++);

printf("是否继续添加(yes--y or Y,no--others)\n");

getchar();

scanf("%c",&ch);

if(ch!='y'&&ch!='Y') break;

}

if((fp=fopen("d:\\student.dat","a"))==NULL)

{

printf("打开失败\n");

exit(0);

}

for(i=be; i

if (fwrite(&stu[i],sizeof(struct student),1,fp)!=1)

printf("文件保存失败\n");

fclose(fp);

window();

}

void output()

{

int i,j,m;

i=0;

if((fp=fopen("d:\\student.dat","r"))==NULL)

{

printf("文件打开失败\n");

system("pause");

相关文档
最新文档