如何用C语言编写一个学生管理系统

 我来答
nyj1117
2010-06-20
知道答主
回答量:12
采纳率:0%
帮助的人:0
展开全部
以前做的,应该可以运行
#include<stdio.h>
#include<string.h>
struct S
{
char name[20]; /*姓名*/
int number; /*学号*/
float score_yuwen; /*语文成绩*/
float score_shuxue; /*数学成绩*/
float score_yingyu; /*英语成绩*/
}T; /*建立学生成绩信息的结构体*/
/*信息维护========将学生信息数据以文件的形式保存*/
void writefile(T *student,int n)
{
FILE *fp;
int i,j;
if((fp=fopen("d:\\kanwei.txt","w+"))==NULL)
{
printf("can't open file");
exit(0);
}
for(i=0;i<=n;i++)
fprintf(fp,"%s %d %f %f %f\n",student[i].name,student[i].number,
student[i].score_yuwen,student[i].score_shuxue,student[i].score_yingyu);
fclose(fp);
}
/* 信息维护========增加学生信息 */
void add(T*student,int n)
{
int I;
printf("输入要增加的学生的姓名、学号、语文成绩、数学成绩、英语成绩:");
scanf("%s %d %f %f %f\n",student[n+1].name,&student[n+1].number,&student
[n+1].score_yuwen,&student[n+1].score_shuxue,&student[n+1].scor_yingyu);
getchar();
while(student[n+1].number!=0) /*输入学号为0时退出*/
{
if(student.number==NULL)
{
printf("\n没有任何学生资料!\n");
return(sutdent);
}
endif
for(i=0;i<=n;i++)
{
if(student[n+1].number==student[i].number)
printf(“此学生已存在!\n”);
else if(student[n+1].number<student[i].number)
{
student=student[i];
student[i]=student[n+1];
student[n+1]=student;
break;
}
}
for(;i<=n;i++)
{
Student=student[i+1];
student[i+1]=student[n+1];
student[n+1]=student;
}
n=n+1;
}
printf("已经增加了!\n")
printf("现在的学生数为:%d个!\n",n);
return(student);
}
/* 信息维护========删除学生信息 */
delete(T *head)
{
score *p1,*p2;
int number;
printf("输入要删除的学生的学号:");
scanf("%d",&number);
getchar();
while(number!=0) /*输入学号为0时退出*/
{
if(head==NULL)
{
printf("\n没有任何学生资料!\n");
return(head);
}
p1=head.number;
while(number!=p1->number&&p1->next!=NULL)
/*p1指向的不是所要找的首结点,并且后面还有结点*/
{
p2=p1;p1=p1->next; /*p1后移一个结点*/
}
if(number==p1->number)
{
if(p1==head)
head=p1->next;
/*若p1指向的是首结点,把后一个结点地址赋予head*/
else
p2->next=p1->next;
/*否则将下一个结点地址赋给前一结点地址*/
printf("删除:%d\n",number);n=n-1;
}
else
printf("%d不存在此学生!\n",number);
/*找不到该结点*/
endif
}
printf("已经删除了!\n")
printf("现在的学生数为:%d个!\n",n);
return(head);
}
/*信息维护========修改学生信息*/
void modify(T *student,int n,)
{
delet(student,n,);
addfile(student,n);
}
/*信息查询========按学生姓名查询*/
int find1(T *student,int n,int *tp)
{
char name[20];
int i;
printf(“输入要查询的学生的名字:”);
scanf(“%s,name\n”);
for(i=0;i<=20;i++)
{
if(name==student[i].name)
printf(“此学生的信息:%s %d %f %f %f\n”,student[i].name,
student[i].number,student[i].score_yuwen,student[i].score_shuxue,
student[i].score_yingyu);
else
{
printf(“无此学生信息!请重新输入:\n”);
find1(T*student,int n,int *tp);
}
return()
}
/*信息查询========按学生学号查询*/
int find2(T *student,int n,int *tp)
{
int number;
int i;
printf(“输入要查询的学生的学号:”);
scanf(“%d”,number);
for(i=0;i<=20;i++)
{
if(number==student[i].number)
printf(“此学生的信息:%s %d %f %f %f\n”,student[i].name,
student[i].number,student[i].score_yuwen,student[i].score_shuxue,student[i].score_yingyu);
else
{
printf(“无此学生信息!请重新输入:\n”);
find2(T*student,int n,int *tp);
}
return()
}
/*=========成绩统计========*/
void count(T*student,int n+1)
{
int i,score1,score2;
char class;
printf(“输入课程名和分数段:”);
scanf(“%s %d %d”,class,score1,score2);
if(score1>score2)
{
i=score1;
score1=score2;
score2=i;
}
if(class==yuwen)
yuwen(T*student,n+1,score1,score2);
if(class==shuxue)
shuxue(T*student,n+1,score1,score2);
if(class==yingyu)
yingyu(T*student,n+1,score1,score2);
}
/*========按语文成绩统计========*/
void yuwen(T*student,int n+1,int score1,int score2)
{
int i,j,a,b;
for(i=0;i<=n;i++)
for(j=0;j<=n;j++)
if(student[i].score_yuwen>student[j].score_yuwen)
{
student[n+1]=student[i];
student[i]=student[j];
student[j]=student[n+1];
}
for(i=0;i<=n;i++)
{
if(student[i].score_yuwen<=score1)
a=i;
if(student[i].score_yuwen<=score2)
b=i;
}
for(i=a;i<=b;i++)
printf(“%s %d %f %f %f\n”,student[i].name,student[i].number,
student[i].score_yuwen,student[i].score_shuxue,student[i].score_yingyu);
return()
}
/*========按数学成绩统计========*/
void shuxue(T*student,int n+1,int score1,int score2)
{
int i,j,a,b;
for(i=0;i<=n;i++)
for(j=0;j<=n;j++)
if(student[i].score_shuxue>student[j].score_shuxue)
{
student[n+1]=student[i];
student[i]=student[j];
student[j]=student[n+1];
}
for(i=0;i<=n;i++)
{
if(student[i].score_shuxue<=score1)
a=i;
if(student[i].score_shuxue<=score2)
b=i;
}
for(i=a;i<=b;i++)
printf(“%s %d %f %f %f\n”,student[i].name,student[i].number,
student[i].score_yuwen,student[i].score_shuxue,student[i].score_yingyu);
return()
}
/*========按英语成绩统计========*/
void yingyu(T*student,int n+1,int score1,int score2)
{
int i,j,a,b;
for(i=0;i<=n;i++)
for(j=0;j<=n;j++)
if(student[i].score_yingyu>student[j].score_yingyu)
{
student[n+1]=student[i];
student[i]=student[j];
student[j]=student[n+1];
}
for(i=0;i<=n;i++)
{
if(student[i].score_yingyu<=score1)
a=i;
if(student[i].score_yingyu<=score2)
b=i;
}
for(i=a;i<=b;i++)
printf(“%s %d %f %f %f\n”,student[i].name,student[i].number,
student[i].score_yuwen,student[i].score_shuxue,student[i].score_yingyu);
return()
}
/*========显示成绩========*/
void display(T *student,int *tp,int n)
{
int i,j;
char a[3]=" ";
printf("***********************************************************\n");
printf(" name number grade class average order\n");
for(i=0;i<n;i++)
{
printf("-----------------------------------------------------------\n");
printf("%d:\n",i+1);
printf(" %s %d %d %d %f %d\n",student[tp[i]].name,student[tp[i]].number,
student[tp[i]].grade,student[tp[i]].class,student[tp[i]].average,tp[i]+1);
printf("mark:");
for(j=0;j<2;j++)
printf("%s%d:%f",a,j+1,student[tp[i]].mark[j]);
printf("\n");
}
}
void main() /* 主程序 */
{
int i=1;
while(i)
{
printf(" Choose the operate:\n");
printf("******************************************************\n");
printf(" find add delete modify showall exit\n");
printf(" 1 2 3 4 5 0\n");
printf("******************************************************\n");
scanf("%d",&i);
readfile(i);
}
}
pengtaonuli
2010-06-20 · TA获得超过180个赞
知道小有建树答主
回答量:81
采纳率:100%
帮助的人:93万
展开全部
写了一个,不行可以改一下,,,
#include <stdio.h>
#include <string.h>
struct stu
{
char sname[20];
int snum;
char ssex[10];
int age;
}student[100];
char name[20];
int num;
char sex[10];
int age;
int size=sizeof(struct stu);
static int n=0;;
int choice;

void enter(struct stu student[],FILE *p);
void looking(struct stu student[],FILE *p);
void search(struct stu student[]);
void xiugai(struct stu student[],FILE *p);
void delete_(struct stu student[],FILE *p);
main()
{
FILE *p;
do
{
printf("[1]:输入学生信息\n[2]:浏览学生信息\n[3]:查询学生信息\n[4]:修改学生信息\n[5]:删除学生信息\n[0]:退出\n");
printf("选择-->");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:
if((p=fopen("student.txt","w"))==NULL)
printf("NO FILE!!!");
enter(student,p);
fclose(p);
break;
case 2:
looking(student,p);break;
case 3:
search(student);break;
case 4:
xiugai(student,p);break;
case 5:
delete_(student,p);break;
case 0:break;
default:printf("error error error...");break;
}
printf("\n继续吗--->[1]:YES [2]:NO");
printf("\n选择-->");
scanf("%d",&choice);
switch(choice)
{
case 1:continue;
case 2:goto next;
default:printf("error error error...");break;
}
}while(1);
next:
printf("\n谢谢使用!!!");
getch();
}

void enter(struct stu student[],FILE *p)
{
printf("姓名:");
gets(student[n].sname); /*可以加一个学号报错系统,即输入的相同的学号就报错*/
strcpy(name,student[n].sname);
fputs(name,p);
printf("\n学号:");
scanf("%d",&student[n].snum);
num=student[n].snum;
fprintf(p," %d ",num);
getchar();
printf("\n性别:");
gets(student[n].ssex);
strcpy(sex,student[n].ssex);
fputs(sex,p);
printf("\n年龄:");
scanf("%d",&student[n].age);
age=student[n].age;
fprintf(p," %d\n",age);
n++;
}

void looking(struct stu student[],FILE *p)
{
int i;
printf("[1]:直接从文件中读入 [2]选择读入\n");
printf("选择:");
scanf("%d",&choice);
switch(choice)
{
case 1:
if((p=fopen("student.txt","r"))==NULL)
printf("NO FILE!!!");
while(!feof(p))
{

fscanf(p,"%s%d%s%d",name,&num,sex,&age);
printf("学号:%d 姓名:%s 性别:%s 年龄:%d\n",num,name,sex,age);
}
fclose(p);
break;
case 2:
if(n==0)
printf("无学生信息!!!");
else
{
printf("[1]:从系统调用 [2]:从文件调用\n");
printf("选择-->");
scanf("%d",&choice);
switch(choice)
{
case 1:

for(i=0;i<n;i++)
printf("学号:%d 姓名:%s 性别:%s 年龄:%d\n",student[i].snum,student[i].sname,student[i].ssex,student[i].age);
break;
case 2:
if((p=fopen("student.txt","r"))==NULL)
{
printf("NO FILE!!");
break;
}
while(!feof(p))
{
fscanf(p,"%s%d%s%d",name,&num,sex,&age);
printf("学号:%d 姓名:%s 性别:%s 年龄:%d\n",num,name,sex,age);
}
fclose(p);
break;
default:printf("error error error...");break;
}
}
break;
default:printf("error error...");break;
}
}

void search(struct stu student[])
{
int i;
if(n==0)
printf("无学生信息!!!");
else
{
printf("[1]:按学号 [2]:按姓名\n");
printf("选择-->");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("输入学号:");
scanf("%d",&num);
for(i=0;i<n;i++)
if(student[i].snum==num)
break;
printf("学号:%d 姓名:%s 性别:%s 年龄:%d",student[i].snum,student[i].sname,student[i].ssex,student[i].age);
break;
case 2:
getchar();
printf("输入姓名:");
gets(name);
for(i=0;i<n;i++)
if(strcmp(name,student[i].sname)==0)
break;
printf("学号:%d 姓名:%s 性别:%s 年龄:%d",student[i].snum,student[i].sname,student[i].ssex,student[i].age);
break;
default:printf("error error error...");break;
}
}
}

void xiugai(struct stu student[],FILE *p)
{
int i,m,num1,agee;
char m1[10];
if(n==0)
printf("无学生信息!!!");
else
{
printf("[1]:按学号 [2]:按姓名\n");
printf("选择-->");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("输入学号:");
scanf("%d",&num1);
for(i=0;i<n;i++)
if(student[i].snum==num1)
break;
break;
case 2:
getchar();
printf("输入姓名:");
gets(name);
for(i=0;i<n;i++)
if(strcmp(name,student[i].sname)==0)
break;
default:printf("error error error...");break;
}
printf("[1]:修改学号 [2]:修改性别 [3]:修改年龄\n");
printf("选择:");
scanf("%d",&choice);
switch(choice)
{
case 1:
getchar();
printf("输入新学号:");
scanf("%d",&num);
student[i].snum=num;
if((p=fopen("student.txt","w+"))==NULL)
printf("NO FILE!!!");
while(!feof(p))
{
fscanf(p,"%d",&m);
if(m==num1)
fprintf(p,"%d",num);
}
fclose(p);
break;
case 2:
getchar();
printf("输入性别:");
scanf("%s",sex);
strcpy(student[i].ssex,sex);
if((p=fopen("student.txt","w+"))==NULL)
printf("NO FILE!!!");
while(!feof(p))
{
fscanf(p,"%s",m1);
if(strcmp(student[i].ssex,sex)==0)
fprintf(p,"%s",m1);
}
fclose(p);
break;
case 3:
printf("输入年龄:");
scanf("%d",&agee);
student[i].age=agee;
if((p=fopen("student.txt","w+"))==NULL)
printf("NO FILE!!!");
while(!feof(p))
{
fscanf(p,"%d",&m);
if(m==agee)
fprintf(p,"%d",agee);
}
fclose(p);
break;
default:printf("error error error...");break;
}
printf("\n修改成功!!!");
}
}
void delete_(struct stu student[],FILE *p)
{
struct stu *s;
int i,j,m;
char name1[10];
if(n==0)
printf("无学生信息!!!");
else
{
printf("[1]:按学号 [2]:按姓名");
printf("\n选择:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n学号:");
scanf("%d",&num);
for(i=0;i<n;i++)
if(num==student[i].snum)
break;
for(j=i;j<n;j++)
student[i]=student[i+1];
n--;
if((p=fopen("student.txt","w+"))==NULL)
printf("NO FILE!!!");
while(!feof(p))
{
fscanf(p,"%d",&m);
if(num==m)
{
fread(&s,size,1,p);
free(s);
}
}
break;
case 2:
getchar();
printf("\n输入姓名:");
gets(name);
for(i=0;i<n;i++)
if(strcmp(name,student[i].sname)==0)
break;
for(j=i;j<n;j++)
student[i]=student[i+1];
n--;
if((p=fopen("student.txt","w+"))==NULL)
printf("NO FILE!!!");
while(!feof(p))
{
fscanf(p,"%s",name1);
if(strcmp(name1,name)==0)
{
fread(&s,size,1,p);
free(s);
}
}
break;
default:printf("error error error...");break;
}
printf("\n删除成功!!!");
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
热度一百
2010-06-20 · TA获得超过834个赞
知道小有建树答主
回答量:422
采纳率:0%
帮助的人:268万
展开全部
书上就有
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式