教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 外语考试 >

学生管理系统 c语言源代码

来源:网络收集 时间:2026-04-03
导读: 学生管理系统 c语言源代码 #include stdio.h #include dos.h #include string.h #include stdlib.h #include malloc.h #define SIZE 8 struct student { char name[20]; char num[15]; int score[5]; float ave; struct student *next; }stu[SIZE],temp,s; v

学生管理系统 c语言源代码

#include <stdio.h>

#include <dos.h>

#include <string.h>

#include <stdlib.h>

#include <malloc.h>

#define SIZE 8

struct student

{

char name[20];

char num[15];

int score[5];

float ave;

struct student *next;

}stu[SIZE],temp,s;

void shuru()

{

int i,j,sum,length,flag=1,a;

FILE *fp;

while(flag==1)

{

printf("Define a range>class number:");

scanf("%d",&a);

printf("Input the total number of the class(<a):");

scanf("%d",&length);

if(length<a)

flag=0;

}

for(i=0;i<length;i++)

{

printf("\n请输入学生的信息:");

printf("\n输入姓名:");

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

printf("\n输入序号.:");

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

printf("\n输入成绩:\n");

sum=0;

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

{

printf("score %d:",j+1);

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

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

}

stu[i].ave=sum/3.0;

}

学生管理系统 c语言源代码

fp=fopen("stu1.txt","w");

for(i=0;i<length;i++)

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

printf("File write error\n");

fclose(fp);

fp=fopen("stu1.txt","r");

printf("\name\ NO. score1 score2 score3 sum ave\n");

for(i=0;i<length;i++)

{

fread(&stu[i],sizeof(struct student),1,fp);

printf("%3s%5s%7d%7d%7d%7d%10.2f\n",stu[i].name,stu[i].num,stu[i].score[0],

stu[i].score[1],stu[i].score[2],sum=stu[i].score[0]+stu[i].score[1]+stu[i].score

[2],stu[i].ave);

}

}

void chaxun()

{ FILE *fp, *fp1;

char n[15],name[20];

int i,j,k,t,m,flag=1;

if((fp=fopen("stu1.txt","r"))==NULL)

{printf("Can not open the file.");

exit(0);

}

printf("\noriginal data:\n");

k=i;

printf("\nPlease select the menu(1.number ):");

scanf("%d",&m);

switch(m)

{case 1:printf("\nchaxun number:");

scanf("%s",n);

for(flag=1,i=0;i<k;i++)

{if(strcmp(n,stu[i].num)==0)

{j=i;

flag=0;

break;

}

}

break;

case 2:printf("\nchaxun name:");

scanf("%s",name);

for(flag=1,i=0;i<k;i++)

{if(strcmp(name,stu[i].name)==0)

{j=i;flag=0;break;

学生管理系统 c语言源代码

}

}

}

if(!flag)

{printf("\nYou can find:\n");

fp1=fopen("stu2.txt","w");

printf(" name NO. score1 score2 score3ave\n");

fwrite(&stu[j],sizeof(struct student),1,fp1);

printf("%-15s%11s%7d%7d%7d%10.2f",stu[j].name,stu[j].num,stu[j].score[0],stu[j].score[1],

stu[j].score[2],stu[j].ave);

}

else printf("\nNot found!");

fclose(fp);

fclose(fp1);

}

xiugai()

{ int a;

printf("\nplease select the menu(1.CHARU 2.SHANCHU ):");

scanf("%d",&a);

switch(a)

{

case 1:Insert(); break;

case 2:Delete(); break;

}

}

Insert()

{ FILE *fp;

int i,j,t,n;

printf("\nNO.:");

scanf("%s",s.num);

printf("name:");

scanf("%s",);

printf("score1,score2,score3:");

scanf("%d,%d,%d",&s.score[0],&s.score[1],&s.score[2]);

s.ave=(s.score[0]+s.score[1]+s.score[2])/3.0;

if((fp=fopen("stu1.txt","r"))==NULL)

{printf("Can not open the file.");

exit(0);

}

printf("\noriginal data:\n");

for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)

{printf("\n%-15s%11s",stu[i].name,stu[i].num);

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

学生管理系统 c语言源代码

printf("%7d",stu[i].score[j]);

printf("%10.2f",stu[i].ave);

}

fclose(fp);

n=i;

for(t=0;stu[t].ave>s.ave&&t<n;t++);

printf("\nnow:\n");

fp=fopen("stu1.txt","w");

for(i=0;i<t;i++)

{fwrite(&stu[i],sizeof(struct student),1,fp);

printf("\n%-15s%11s",stu[i].name,stu[i].num);

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

printf("%7d",stu[i].score[j]);

printf("%10.2f",stu[i].ave);

}

fwrite(&s,sizeof(struct student),1,fp);

printf("\n%-15s%11s%7d%7d%7d%10.2f",,s.num,s.score[0],s.score[1], s.score[2],s.ave);

for(i=t;i<n;i++)

{fwrite(&stu[i],sizeof(struct student),1,fp);

printf("\n%-15s%11s",stu[i].name,stu[i].num);

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

printf("%7d",stu[i].score[j]);

printf("%10.2f",stu[i].ave);

}

fclose(fp);

}

Delete()

{ FILE *fp;

int i,j,t,n,flag;

char number[15];

if((fp=fopen("stu1.txt","rb"))==NULL)

{printf("Can not open the file.");

exit(0);

}

printf("\noriginal data:");

for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)

{printf("\n%-15s%11s",stu[i].name,stu[i].num);

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

printf("%7d",stu[i].score[j]);

printf("%10.2f",stu[i].ave);

}

fclose(fp);

n=i;

学生管理系统 c语言源代码

printf("\nInput number deleted:");

scanf("%s",number);

for(flag=1,i=0;flag&&i<n;i++)

{if(strcmp(number,stu[i].num)==0)

{fo …… 此处隐藏:3280字,全部文档内容请下载后查看。喜欢就下载吧 ……

学生管理系统 c语言源代码.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/116840.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)