用c语言写学生信息管理系统,C语言学生信息管理系统

1,C语言学生信息管理系统我不会我也在求高手来帮忙....对的话你告诉我啊我期末作业啊 改好了,运行正确!#include <stdio.h>#include <stdlib.h>#include <string.h>#define SIZE 50#define LENGTH sizeof(struct student)enum studentsex struct student char number[15]; char name[10]; enum studentsex sex; float chinese,maths,english;}stud[SIZE];void main() void input(); void add(); void edit(); void del(); void query(); void report(); int c1,c2; printf("1.create new file\n2.edit existed file\n3.query\n4.report\n5.exit\n"); printf("Please input your choice:"); scanf("%d",&c1); switch(c1)case 1:input();break;} case 2:printf("1.add a student\n2.edit a student\n3.delete a student\n4.write to file and back to main menu\n");printf("Please input your choice:");scanf("%d",&c2);switch(c2)case 1:add();break;}case 2:edit();break;}case 3:del();break;}case 4:main();break;}default:break;}break;} case 3:query();break;} case 4:report();break;} case 5:exit(0);break;} default:break; }}void input() int i,j,n,m; char st[SIZE][10]; FILE *fp; if((fp=fopen("D:\\rj0901.txt","wb"))==NULL)printf("cannot open file\n");return; } printf("How many students do you want to input:"); scanf("%d",&n); if(n>SIZE) printf("error\n"); else if(n<=SIZE)for(i=0;i<n;i++)printf("Please input the information of the %dth student\n",i+1);printf("No.:");scanf("%s",stud[i].number);printf("Name:");scanf("%s",stud[i].name);printf("Sex(1.male;2.female.Please input 1 or 2):");scanf("%d",&m);if(m==1)else if(m==2)printf("The score of Chinese:");scanf("%f",&stud[i].chinese);printf("The score of Maths:");scanf("%f",&stud[i].maths);printf("The score of English:");scanf("%f",&stud[i].english);printf("\n");printf("The information of the %dth student is:\n");printf("No.:%s Name:%s Sex:%s Chinese:%.1f Maths:%.1f English:%.1f\n\n",stud[i].number,stud[i].name,st[i],stud[i].chinese,stud[i].maths,stud[i].english);}for(j=0;j<n;j++)if(fwrite(&stud[j],LENGTH,1,fp)!=1)printf("file write error\n");} } fclose(fp);}void add() char st[SIZE][10]; int i,t,n; FILE *fp; for(i=0;i<SIZE;i++)if(stud[i].number!="\0")t=i; } if((fp=fopen("D:\\rj0901.txt","ab+"))==NULL)printf("file open error\n");return; } printf("Please input a student information\n"); printf("No.:"); scanf("%s",stud[t].number); printf("Name:"); scanf("%s",stud[t].name); gets(stud[t].name); printf("Sex(1.male;2.female.Please input 1 or 2)"); scanf("%d",&n); if(n==1)else if(n==2)printf("Chinese:"); scanf("%f",&stud[t].chinese); printf("Maths:"); scanf("%f",&stud[t].maths); printf("English:"); scanf("%f",&stud[t].english); if(fwrite(&stud[t],LENGTH,1,fp)!=1)printf("write file error\n"); fclose(fp);}void edit() char st[SIZE][10]; char num[15]; int i,t,n; FILE *fp; if((fp=fopen("D:\\rj0901.txt","rb+"))==NULL)printf("file open error\n");return; } printf("Please input a student number:"); scanf("%s",num); for(i=0;i<SIZE;i++)if(strcmp(stud[i].number,num)==0)t=i; } printf("Please input a student information\n"); printf("No:"); scanf("%s",stud[t].number); printf("Name:"); scanf("%s",stud[t].name); printf("Sex(1.male;2.female.Please input 1 or 2)"); scanf("%d",&n); if(n==1)else if(n==2)printf("Chinese:"); scanf("%f",&stud[t].chinese); printf("Maths:"); scanf("%f",&stud[t].maths); printf("English:"); scanf("%f",&stud[t].english); if(fwrite(&stud[t],LENGTH,1,fp)!=1)printf("write file error\n"); fclose(fp);}void del() char num[15]; int i,t; FILE *fp; if((fp=fopen("D:\\rj0901.txt","rb"))==NULL)printf("file open error\n");return; } printf("Please input a student number:"); scanf("%s",num); for(i=0;i<SIZE;i++)if(strcmp(stud[i].number,num)==0)t=i; } for(;stud[t].number!=" ";t++)stud[t]=stud[t+1]; } fclose(fp);}void query() FILE *fp; char num[15]; int i,j,q; float total[SIZE],average[SIZE]; fp=fopen("D:\\rj0901.txt","rb"); printf("1.output the required student information\n2.output the total score and the average score of a class\n"); printf("Please input your choice:"); scanf("%d",&j); switch(j)case 1:printf("Please input a student number:\n");scanf("%s",num);for(i=0;i<SIZE;i++)if(strcmp(stud[i].number,num)==0)printf("The information of the student:\n");printf("No:%s Name:%s Sex:%s Chinese:%f Maths:%f English:%f\n",stud[i].number,stud[i].name,stud[i].sex,stud[i].chinese,stud[i].maths,stud[i].english);}break;} case 2:for(i=0;i<SIZE;i++)if(stud[i].number=="\0")}for(i=0;i<q;i++)total[i]=stud[i].chinese+stud[i].maths+stud[i].english;average[i]=total[i]/3;printf("The total score of the %dth student:%.1f\n",i+1,total[i]);printf("The average score of the %dth student:%.1f\n",i+1,average[i]);}break;} default:break;fclose(fp); }}void report() FILE *fp; int i,j,m,q,p; float total[SIZE],t; fp=fopen("D:\\rj0901.txt","rb"); fseek(fp,0,0); for(i=0;i<SIZE;i++)fread(&stud[i],LENGTH,1,fp);total[i]=stud[i].chinese+stud[i].maths+stud[i].english; } for(i=0;i<SIZE-1;i++)for(j=1;j<SIZE;j++)if(total[i]<total[j])t=total[i];total[i]=total[j];total[j]=t;}}for(p=0;p<SIZE;p++)if(stud[p].number==" ")}for(m=0;m<q;m++)printf("%f\n",total[m]);fclose(fp);}好好对比下,祝你成功~
2,用c语言编写学生管理系统/*好吧,其实你可以上网看看,那么多的,你可以自己修改下*/#include #include #include #include #define NULL 0 #define LEN sizeof(struct student) struct student { char name[20]; long int num; char sex[4]; int age; char address[30]; double tele_num; char aihao[20]; struct student *next; };//定义一个结构题 int TOTAL_NUM = 0;//学生总数 struct student *head = NULL; void welcome (); //欢迎界面 void mainmenu (); //主界面 void record (); //记录数据 void insert(struct student *stu); //插入数据 void display(struct student *stu); //显示一个学生的信息 void displayAll (); //显示所有学生的信息 void query_by_num (); //按学号查询学生信息 void readData (); //读取文件里学生的信息 void writeData (); //向文件写入学生信息 void freeAll (); //清空链表内容 void del (); //删除学生信息 void change (); //更改学生信息 void devise (struct student *p); //选择更改内容 int main (void) { welcome (); //显示主菜单 mainmenu (); return 0; } //显示欢迎信息 void welcome () { printf ("+----------------------------------------------------+\n"); printf ("| |\n"); printf ("| 欢迎使用网络工程学院信息安全092班学生信息管理系统 |\n"); printf ("| |\n"); printf ("+----------------------------------------------------+\n"); } //系统主菜单 void mainmenu () { int choice; choice = -1; readData (); printf ("\n温馨提示:为保证您的操作得到保存,请按正常顺序退出系统^_^\n"); do { printf ("\n\n\n"); printf ("\t\t\t--------------------------------------------\n"); printf ("\t\t\t+ 信息安全092班学生信息管理系统 |\n"); printf ("\t\t\t--------------------------------------------\n"); printf ("\t\t\t+ [1]----录入学生信息 |\n"); printf ("\t\t\t+ [2]----浏览学生信息 |\n"); printf ("\t\t\t+ [3]----查询学生信息 |\n"); printf ("\t\t\t+ [4]----删除学生信息 |\n"); printf ("\t\t\t+ [5]----修改学生信息 |\n"); printf ("\t\t\t+ [0]----退出系统 |\n"); printf ("\t\t\t+*·*·*·*·*·*·*·*·*·*·*·*·*·*·*|\n"); printf ("\t\t\t--------------------------------------------\n"); printf ("请输入您的选择:"); scanf ("%d", &choice); switch (choice) { case 0: writeData (); freeAll (); exit (0); case 1: record (); break; case 2: displayAll (); break; case 3: query_by_num (); break; case 4: del (); break; case 5: change (); break; default: printf ("\n无效选项!"); break; } } while (choice != 0); } //录入学生信息 void record () { struct student *p0; p0 = (struct student *)malloc(LEN); printf ("请输入学生的姓名:"); scanf ("%s",p0->name); printf ("请输入学生的学号:"); scanf ("%ld",&p0->num); printf ("请输入学生的性别:"); scanf ("%s",p0->sex); printf ("请输入学生的年龄:"); scanf ("%d",&p0->age); printf ("请输入学生的地址:"); scanf ("%s",p0->address); printf ("请输入学生的电话:"); scanf ("%lf",&p0->tele_num); printf ("请输入学生的爱好:"); scanf ("%s",p0->aihao); insert (p0); printf ("该学生的信息为:\n"); printf ("-------------------------------------------------------------------------------\n"); printf ("姓名\t学号\t\t年龄\t性别\t地址\t\t电话\t\t爱好\n"); display (p0); } void insert (struct student *stu) { struct student *p0, *p1, *p2; p1 = head; p0 = stu; if (head == NULL) { head = p0; p0->next = NULL; } else { while ((p0->num > p1->num)&&(p1->next != NULL)) { p2 = p1; p1 = p1->next; } if (p0->num <= p1->num) { if (head == p1) head = p0; else p2->next = p0; p0->next = p1; } else { p1->next = p0; p0->next = NULL; } } TOTAL_NUM++; } void display (struct student *p) { printf ("%s\t%ld\t%d\t%s\t%s\t\t%.0f\t%s\n", p->name, p->num, p->age, p->sex, p->address, p->tele_num, p->aihao); } //浏览学生信息 void displayAll() { struct student *p; printf("学生总数:%d\n", TOTAL_NUM); p = head; if (head != NULL) { printf("\n姓名\t学号\t\t年龄\t性别\t地址\t\t电话\t\t爱好\n"); printf("-------------------------------------------------------------------------------\n"); do { display(p); p = p->next; } while(p != NULL); } printf ("\n"); } //按学号查询学生信息 void query_by_num () { int num; struct student *p1; printf("请输入学生的学号:"); scanf("%ld", &num); if(head==NULL) { printf("无学生记录!\n"); return; } p1 = head; while (num!=p1->num && p1->next!=NULL) p1 = p1->next; if (num == p1->num) { printf ("姓名\t学号\t\t年龄\t性别\t地址\t\t电话\t\t爱好\n"); printf ("-------------------------------------------------------------------------------\n"); display (p1); } else printf ("没有该学生记录,请核对!"); } //写入文件 void writeData () { FILE* fp;//文件指针 struct student *p; fp = fopen("1.txt", "w"); if (!fp) { printf("文件打开错误!"); return; } fprintf(fp,"%d\n", TOTAL_NUM); for(p = head; p!= NULL; p= p->next) { fprintf(fp,"%s\t%ld\t%s\t%d\t%s\t%.0f\t%s\n", p->name, p->num, p->sex, p->age, p->address, p->tele_num, p->aihao); } fclose (fp); } void freeAll () { struct student *p1, *p2; p1 = p2=head; while(p1) { p2=p1->next; free (p1); p1 = p2; } } //读取文件 void readData () { FILE* fp;//文件指针 struct student *p1, *p2; fp = fopen("1.txt", "r"); if (!fp) { printf("文件打开错误!"); return; } fscanf(fp,"%d\n", &TOTAL_NUM); head = p1 = p2 = (struct student *)malloc(LEN); fscanf(fp,"%s\t%ld\t%s\t%d\t%s\t%lf\t%s\n", p1->name, &p1->num, p1->sex, &p1->age, p1->address, &p1->tele_num, p1->aihao); while(!feof(fp)) { p1 = (struct student *)malloc(LEN); fscanf(fp,"%s\t%ld\t%s\t%d\t%s\t%lf\t%s\n", p1->name, &p1->num, p1->sex, &p1->age, p1->address, &p1->tele_num, p1->aihao); p2->next = p1; p2 = p1; } p2->next = NULL; fclose(fp); } //删除学生信息 void del () { struct student *p1, *p2; long int num; if (head == NULL) { printf("无学生记录!\n"); return; } printf("请输入您要删除的学生的学号:"); scanf("%ld", &num); p1 = head; while (num != p1->num && p1->next != NULL) { p2 = p1; p1 = p1->next; } if(num == p1->num) { if(p1 == head) head = p1->next; else p2->next = p1->next; free(p1); TOTAL_NUM--; } else printf("没有该学生记录,请核对!\n"); } //修改学生信息 void change () { struct student *p1, *p2; long int num; if (head == NULL) { printf ("无学生记录!\n"); return; } printf ("请输入您要修改的学生的学号:"); scanf ("%ld", &num); p1 = head; while (num != p1->num && p1->next != NULL) { p2 = p1; p1 = p1->next; } if(num == p1->num) devise (p1); else printf("没有该学生记录 , 请核对!\n"); } void devise (struct student *p) { int choice; choice = -1; do { printf("请选择您要修改的学生的信息内容:\n"); printf("+----------------------+\n"); printf("| 姓名 请按 1 |\n"); printf("| 学号 请按 2 |\n"); printf("| 性别 请按 3 |\n"); printf("| 年龄 请按 4 |\n"); printf("| 地址 请按 5 |\n"); printf("| 电话 请按 6 |\n"); printf("| 爱好 请按 7 |\n"); printf("| 取消 请按 0 |\n"); printf("+----------------------+\n"); printf("请输入您的选择:"); scanf("%d", &choice); switch (choice) { case 0: return; case 1: printf("请输入新姓名:"); scanf("%s", p->name); break; case 2: printf("请输入新学号:"); scanf("%d", &p->num); break; case 3: printf("请输入新性别:"); scanf("%s", p->sex); break; case 4: printf("请输入新年龄:"); scanf("%s", &p->age); break; case 5: printf("请输入新地址:"); scanf("%s", p->address); break; case 6: printf("请输入新电话:"); scanf("%lf", &p->tele_num); break; case 7: printf("请输入新爱好:"); scanf("%s", p->aihao); break; default: printf("\n无效选项!"); break; } } while(choice != 0); } 打字不易,如满意,望采纳 。【用c语言写学生信息管理系统,C语言学生信息管理系统】

    推荐阅读