C语言之学生管理系统
- 格式:docx
- 大小:146.08 KB
- 文档页数:14
学生成绩管理系统(纯C语言做)完成的功能如下:1) 显示全部的记录(读取文件)2) 删除记录(输入一个学生的学号,删除该学生的信息)3) 插入记录(按约定的格式输入一个学生的信息将它插入)4) 查找记录(输入一个学生学号,输出其各科成绩)5)计算总分和平均分6) 排序(根据平均分排名,总分相同者名次一样)7) 保存文件(插入或删除某个记录后,将文件保存)8) 分类合计(分别统计100—90,90—80,80-70,70,60,60分一下的人数,并求出百分比)只要4个成绩即可,部分源代码给出:#include"stdio。
h"main(){char c;int i;do{clrscr ();for(i=0;i〈80;i++)printf(”*");printf("\t 1: 添加一个学生\n”);printf(”\t 2:删除一个学生\n");printf("\t 3: 查找一个学生\n”);printf(”\t 4: 学生信息排序\n”);printf("\t 5:退出\n”);printf(”\t请选择输入选项[1\\2\\3\\4\\5]:\n");do{c=getchar();}while(c!=’1’&&c!=’2’&&c!='3'&&c!=’4’&&c!=’5');getchar();switch(c){case ’1':input(); break;case '2': del(); break; case ’3’:find();break;case '4': arrange(); break; case ’5’:exit(0);}printf(" 按任意键返回主菜单:\n”);getchar();clrscr();}while(1);}/* Note:Your choice is C IDE */#include "stdio。
/*带有登陆功能的学生信息管理系统,其中管理员账号为:admin 密码为:123456*/ #include<stdio.h>#define STU_NUM 50 //学生数量typedef struct{char ID[50]; //学生学号char name[30]; //学生姓名char password[50]; //学生登录密码char class[20]; //学生班级int math_score; //数学成绩int C_score; // C语言成绩int OS_score; //操作系统成绩int age; //年龄}STU;typedef struct{char user[30];char key[50];}Admin;int Student_Num=0;Admin admin[1]={"admin","123456"};STU student[STU_NUM];char login_user[50]; //存储当前登陆用户名char logpassword[50]; //存储当前登陆密码//保存到文件void save(){FILE *fp;int d;if((fp=fopen("stu.dat","wb"))==NULL){printf("can not open data file!\n");return;}fwrite(&Student_Num,sizeof(int),1,fp);for(d=0;d<STU_NUM;d++)if(fwrite(&student[d],sizeof(STU),1,fp)!=1)printf("file write error\n");fclose(fp);}//将文件内容装载到相应数组void load(){FILE *fp;int e;if((fp=fopen("stu.dat","rb"))==NULL){printf("can not open file\n");return;}fread(&Student_Num,sizeof(int),1,fp);for(e=0;e<STU_NUM;e++)if(fread(&student[e],sizeof(STU),1,fp)!=1){if(feof(fp)){fclose(fp);return;}printf("file read error\n");}fclose(fp);}//管理员登陆int admin_login_confirm(){Admin temp;int wt=0;int confirm=0;do{printf("input your username:");scanf("%s",er);printf("input your password:");scanf("%s",temp.key);if(strcmp(er,admin[0].user)==0 && strcmp(temp.key,admin [0].key)==0){confirm=1;break;}else{confirm=0;wt++;printf("wrong password! \n");}}while(wt<3);return confirm;}int check(char ck[50]){int check=0;int ckflag=0;for(check=0;check<Student_Num;check++){if(strcmp(ck,student[check].ID)==0)ckflag=1;return ckflag;}return ckflag;}//学生登录int student_login(){int a;int ok=0;int wrong=0;STU tem;do{printf("user_ID:");scanf("%s",tem.ID);printf("password:");scanf("%s",tem.password);for(a=0;a<Student_Num;a++){if(strcmp(tem.ID,student[a].ID)==0 && strcmp(tem.password,student[a].password)==0){strcpy(login_user,student[a].ID);strcpy(logpassword,student[a].password);ok=1;break;}else{ok=0;}}if(ok==0){wrong++;printf("wrong password\n");}elsebreak;}while(wrong<3);return ok;}//添加学生信息void Add_student(){printf("ID:");scanf("%s",student[Student_Num].ID);while(check(student[Student_Num].ID)==1){printf("the ID is already have!\n");printf("ID:");scanf("%s",student[Student_Num].ID);}printf("name:");scanf("%s",student[Student_Num].name);printf("password:");scanf("%s",student[Student_Num].password);printf("class:");scanf("%s",student[Student_Num].class);printf("math_score:");scanf("%d",&student[Student_Num].math_score);printf("C_score:");scanf("%d",&student[Student_Num].C_score);printf("OS_score:");scanf("%d",&student[Student_Num].OS_score);printf("age:");scanf("%d",&student[Student_Num].age);Student_Num++;}//显示学生信息void display_student(){int b;printf("ID\tname\tclass\tmath_score\tC_score\t\tOS_score\tage\n");for(b=0;b<Student_Num;b++){printf("%s\t%s\t%s\t%d\t\t%d\t\t%d\t\t%d",student[b].ID,student[b].name,student[b].class,student[b].math_sc ore,student[b].C_score,student[b].OS_score,student[b].age);printf("\n");}}//更改学生信息void alter_student(){char alter[50];STU ch;int al,change=0;printf("the ID you want to change:");scanf("%s",alter);for(al=0;al<STU_NUM;al++){if(strcmp(alter,student[al].ID)==0){printf("ID:");scanf("%s",ch.ID);while(check(ch.ID)==1){printf("the ID is already have!\n");printf("ID:");scanf("%s",ch.ID);}printf("name:");scanf("%s",);printf("password:");scanf("%s",ch.password);printf("class:");scanf("%s",ch.class);printf("math_score:");scanf("%d",&ch.math_score);printf("C_score:");scanf("%d",&ch.C_score);printf("OS_score:");scanf("%d",&ch.OS_score);printf("age:");scanf("%d",&ch.age);printf("are you sure you want to change? (Y/N)[ ]\b\b");if(getchar()=='Y'||getchar()=='y'){student[al]=ch;change=1; break;}}}if(change==0) printf("no such user");save();}//查找void search(){char search[50];int sc;printf("the ID you want to search:");scanf("%s",search);for(sc=0;sc<STU_NUM;sc++){if(strcmp(search,student[sc].ID)==0) {printf("ID\tname\tclass\tmath_score\tC_score\t\tOS_score\tage\n");printf("%s\t%s\t%s\t%d\t\t%d\t\t%d\t\t%d",student[sc].ID,student[sc].name,student[sc].class,student[sc].math_ score,student[sc].C_score,student[sc].OS_score,student[sc].age);printf("\n");break;}}if(sc>=STU_NUM) printf("no such student!\n");}//删除void delete_student(){char del[50];STU dele;int de;printf("the ID you want to delete:");scanf("%s",del);for(de=0;de<STU_NUM;de++){if(strcmp(del,student[de].ID)==0) {printf("ID\tname\tclass\tmath_score\tC_score\t\tOS_score\tage\n");printf("%s\t%s\t%s\t%d\t\t%d\t\t%d\t\t%d",student[de].ID,student[de].name,student[de].class,student[de].mat h_score,student[de].C_score,student[de].OS_score,student[de].age);printf("\n");break;}}if(de>=STU_NUM) printf("no such student!\n");else{printf("are you sure you want to delete? y/n [ ]\b\b");if(getchar()=='Y'||getchar()=='y'){dele=student[de];student[de]=student[Student_Num-1];student[Student_Num-1]=dele;Student_Num--;}}save();}//更改学生登录密码void change_password(){char ps1[50],ps2[50],old[50];int point=0;int inputcnt=1;printf("please input your old password:");scanf("%s",old);while(strcmp(old,logpassword)!=0){printf("old password is wrong!\n");printf("please input your old password:");scanf("%s",old);if(inputcnt>=2) { printf("you have wrong 3 times!\n"); return;}inputcnt++;}printf("input new password:");scanf("%s",ps1);printf("confirm new password:");scanf("%s",ps2);if(strcmp(ps1,ps2)==0){printf("Are you sure to change? y/n [ ]\b\b");if(getchar()=='Y'||getchar()=='y'){for(point=0;point<Student_Num;point++){if(strcmp(login_user,student[point].ID)==0){strcpy(student[point].password,ps1);save();break;}}}}}//显示主菜单void display_Main_Menu(){printf("***************Welcome to Student Management System***************\n");printf("** **\n");printf("** 1.administrator Login er Login 3.exit system **\n");printf("** **\n");printf("******************************************************************\n");printf("your choice:[ ]\b\b");}//管理员功能菜单void display_admin_function(){printf("***********************************************\n");printf("**** M | 1.add student ****\n");printf("**** | 2.save stdudent information ****\n");printf("**** E | 3.alter student information ****\n");printf("**** | 4.search for student information ****\n");printf("**** N | 5.delete student information ****\n");printf("**** | 6.display student information ****\n");printf("**** U | 7.exit ****\n");printf("***********************************************\n");}//学生功能菜单void display_user_function(){printf("============student login============\n");printf("** 1.check information **\n");printf("** 2.change password **\n");printf("** 3.exit **\n");printf("=====================================\n");}//管理员功能选择int Admin_function(){int ach;while(1){display_admin_function();printf("select your choice[ ]\b\b");scanf("%d",&ach);switch(ach){case 1: Add_student(); break;case 2: save(); break;case 3: alter_student(); break;case 4: search(); break;case 5: delete_student(); break;case 6: display_student(); break;case 7: display_Main_Menu(); return 0;default: printf("repeat!\n"); break;}}}//学生功能选择int user_function(){int uch;int back=0;while(1){display_user_function();printf("hello,student make your choice[ ]\b\b");scanf("%d",&uch);switch(uch){case 1: display_student(); break;case 2: change_password(); break;case 3: back=1; return back;default: printf("everything is ok\n"); break;}return back;}int main(){int choice;load();display_Main_Menu();while(1){scanf("%d",&choice);switch(choice){case 1: if(admin_login_confirm()==1) {Admin_function(); break;}else{printf("you have input wrong password 3 times! exit the system...\n");return 0;}case 2: if(student_login()==1) {if(user_function()==1) return 0;elsebreak;}elseprintf("you have input wrong password 3 times! exit the system...\n");return 0;case 3: return 0;default: printf("please input 1~3\n");display_Main_Menu();break;}}}。
学生管理系统c语言简单版学生管理系统c语言简单版介绍:学生管理系统是一种用于管理学生信息的软件,它可以方便地对学生的基本信息、课程成绩等进行录入、查询、修改和删除等操作。
本文将介绍如何使用C语言编写一个简单的学生管理系统。
功能:1. 添加学生信息2. 查询学生信息3. 修改学生信息4. 删除学生信息5. 显示所有学生信息实现方法:1. 添加学生信息添加学生信息需要输入以下内容:姓名、性别、年龄、班级和电话号码。
我们可以定义一个结构体来存储这些信息,代码如下:```struct Student {char name[20];char sex[10];int age;char class[20];char phone[20];};```然后定义一个数组来存储多个学生的信息:```struct Student students[100];int count = 0; // 学生数量```接下来,我们可以编写一个函数来添加新的学生信息:```void addStudent() {struct Student student;printf("请输入姓名:");scanf("%s", );printf("请输入性别:");scanf("%s", student.sex);printf("请输入年龄:");scanf("%d", &student.age);printf("请输入班级:");scanf("%s", student.class);printf("请输入电话号码:");scanf("%s", student.phone);students[count++] = student; // 将新的学生信息存储到数组中 printf("添加成功!\n");}```2. 查询学生信息查询学生信息可以按照姓名或电话号码进行查询。
路漫漫其修远兮,吾将.上F而求索・百度文库用C语言实现线性表的基本操作,能创建一个基于学生信息管理的链表,至少包含数据输入、数据输出、数据处理等操作。
在主函数里能实现以下功能。
运行后出现一个选择提示。
可选择的功能有1)创建新的学生信息链表2)增加一个新的学生信息3)按学号删除某个学生信息4)按学号查找某个学生信息5)可以按照学生成绩对■链表排序6)退出系统#include "stdio.h"#include "stdlib.h"#include "string.h n#include ,,conio.h Hjiemian();struct student(char name[50];char sex[5];int age;char num[50];float scorel;float score2;float score3;float sum;float ave;}stu[50],del;void gnl()(int i=0;char numl;for(i=0;i<50;i++)(printf「请输入要添加的学生资料:\n“);printf(“学号巧;scanf("%s",stu[i].num);printf("姓名巧;scanf("%s",stu[i].name);printf(“性别巧;scanf("%s",&stu[i].sex);printf(“年龄巧;scanf("%d",&stu[i].age);11目上下而求索•百度文库printf(”请输入学生的三门成绩:'俏;printf("语文门;scanf(,,%f,,,&stu[i].scorel);printf(“数学门;scanf(,,%f,,,&stu[i].score2);printf("英语巧;scanf(,,%f,,,&stu[i].score3);printf("是否继续添加:y/n\n“); scanf(,,%c,,,&numl);scanf(,,%c,,,&numl);if(numl==,N, 11 numl=="n,){system(,,cls"); jiemian();)))void gn2()(int i;char num[50];printf「请输入要查找的学生学号:\n“);scanf(,,%s,,/num);for(i=0;i<50;i++)if(strcmp(stu[i].num,num)==O) (stu[i].sum=stu[i].scorel+stu[i].score2+stu[i].score3;stu[i].ave=stu[i].sum^;printf(',%s\t%s\t%s\t%d\t%,2f\t%.2f\t%.2f\t%.2f\t%.2f:\n'l/stu[i].num/stu[i].name/stu[i].sex/stu[i] .age,s tu[i].scorel/stu[i].score2/stu[i].score3/stu[i].sum/stu[i].ave);break;)if(i==50)printf("查找不到!请重新输入!\n");22路漫漫其修远兮,吾将上F而求索・百度文库getch(); systemf'cls"); jiemian();)void gn3()(char numlJ=0;printf("请输入要修改的学生学号:\n“);scanf(,,%s,,/stu[i].num);printf(,l%s\t%s\t%s\t%d\t%,2f\t%.2f\t%.2f\t%.2f\t%.2f:\n'l/stu[i].num/stu[i].name/stu[i].sex/stu[i] .age,s tu[i].scorel/stu[i].score2/stu[i].score3/stu[i].sum/stu[i].ave);printf("姓名门;scanf(,,%s,,/stu[i].name);printf(“性别门;scanf(,,%s,,/stu[i].sex);printf("年龄门;scanf(,,%d,,,&stu[i].age);printf(“请输入学生的三门成绩:\n“);printf("语文门;scanf(,,%f,,,&stu[i].scorel);printf(“数学门;scanf(,,%f,,,&stu[i].score2);printf("英语门;scanf(,,%f,,,&stu[i].score3);printf("是否继续修改:y/n?\n“);scanf(,,%c"/&numl);scanf(,,%c,\&numl);if(numl==,N, 11 numl==,n,)systemf'cls"); jiemian();)void gn4()(int i;char num[50];printf("请输入要删除的学生学号:\n“);scanf(,,%s,,,num);for(i=0;i<50;i++) 33if(strcmp(num,stu[i].num)==O)(printf(,,%s\t%s\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f:\n,,/stu[i].num/stu[i].name/stu[i].sex/stu[i] .age,stu[i].scorel/stu[i].score2/stu[i].score3/stu[i].sum/stu[i].ave);stu[i]=del;printf("信息已删除,按任意键返回..\n“); break;)if(i==50)printf ("您输入的信息不存在!\n”);getch();system("cls"); jiemian();)void gn5()(int i=0;stu[i].sum=stu[i].scorel+stu[i].score2+stu[i].score3;stu[i].ave=stu[i].sum/3;printf("学号\t姓名\t性别\t年龄\t语文\t数学\t英语\t总成绩\t平均成绩\n");for(i=0;i<50;i++)(if(stu[i].age==O)break;printf(,,%s\t%s\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f:\n,,/stu[i].num/stu[i].name/stu[i].sex/stu[i] .age,stu[i].scorel/stu[i].score2/stu[i].score3/stu[i].sum/stu[i].ave);)printf("按任意键返回.getch();system(,,cls n);jiemian();)void gn6()(FILE *fp;int i;char filename[50];printf(,,\n N); 44路漫漫其修远兮,吾将上F而求索・百度文库printf(,,\n M);printf(“请输入要保存的文件名:");scanf(”%s”,filename);if((fp=fopen(filename/,wb,,))==NULL)printf("文件名为空,不能保存!\n");for(i=0;i<50;i++)(if(fwrite(&stu[i],sizeof(struct student),l,fp)!=l) printf("文件保存失败!\n”);)fclose(fp);printf (“文件己保存!\n“);printf。
C实现简单的学生信息管理系统控制台程序学生信息管理系统是一种用于管理学生的基本信息的应用程序。
在这个系统中,可以实现学生信息的录入、修改、查询和删除等功能,以便对学生信息进行有效的管理和维护。
下面是一个用C语言实现的简单学生信息管理系统的示例代码。
```c#include <stdio.h>#include <stdlib.h>//定义学生结构体struct studentint id;char name[50];int age;};//全局变量,用于存储学生信息struct student students[100];int count = 0;//函数声明void menu(;void addStudent(;void listStudents(;void searchStudent(;void deleteStudent(;void updateStudent(;//主函数int maimenu(;return 0;//菜单函数void menint choice;doprintf("\n====== Student Information Management System ======\n");printf("1. Add student\n");printf("2. List students\n");printf("3. Search student\n");printf("4. Delete student\n");printf("5. Update student\n");printf("0. Exit\n");printf("Please enter your choice: "); scanf("%d", &choice);switch (choice)case 1:addStudent(;break;case 2:listStudents(;break;case 3:searchStudent(;break;case 4:deleteStudent(;break;case 5:updateStudent(;break;case 0:printf("Exit the system\n");break;default:printf("Invalid choice! Please try again\n");break;}} while (choice != 0);//添加学生函数void addStudenif (count >= 100)printf("The number of students has reached the upper limit!\n");return;}struct student newStudent;printf("Please enter student ID: ");scanf("%d", &newStudent.id);printf("Please enter student name: ");scanf("%s", );printf("Please enter student age: ");scanf("%d", &newStudent.age);students[count] = newStudent;count++;printf("Add student successfully!\n");//列出学生函数void listStudentif (count == 0)printf("No student information is available!\n");return;}printf("====== Student List ======\n");printf("ID\tName\t\tAge\n");for (int i = 0; i < count; i++)printf("%d\t%s\t\t%d\n", students[i].id, students[i].name, students[i].age);}void searchStudenif (count == 0)printf("No student information is available!\n"); return;}int id;printf("Please enter student ID: ");scanf("%d", &id);for (int i = 0; i < count; i++)if (students[i].id == id)printf("Student Information:\n");printf("ID: %d\n", students[i].id);printf("Name: %s\n", students[i].name);printf("Age: %d\n", students[i].age);return;}}printf("Student with ID %d does not exist!\n", id);void deleteStudenif (count == 0)printf("No student information is available!\n"); return;}int id;printf("Please enter student ID: ");scanf("%d", &id);for (int i = 0; i < count; i++)if (students[i].id == id)for (int j = i; j < count - 1; j++)students[j] = students[j+1]; // 将后面的学生信息往前移动}count--;printf("Delete student successfully!\n");return;}}printf("Student with ID %d does not exist!\n", id); //更新学生函数void updateStudenif (count == 0)printf("No student information is available!\n"); return;}int id;printf("Please enter student ID: ");scanf("%d", &id);for (int i = 0; i < count; i++)if (students[i].id == id)printf("Please enter student name: ");scanf("%s", students[i].name);printf("Please enter student age: ");scanf("%d", &students[i].age);printf("Update student information successfully!\n"); return;}}printf("Student with ID %d does not exist!\n", id);```这是一个简单的学生信息管理系统控制台程序,实现了学生的添加、列出、查询、删除和更新等功能。
学生信息管理系统c语言1学生信息管理系统C语言学生信息管理系统C语言是一个以全校学生信息为对象,以c 语言为编程语言,以windows或linux系统环境下操作的具有管理功能的软件系统。
它的主要功能是实现学校的学生信息的管理和处理,如查询、添加、修改、删除学生信息等功能。
2学生信息管理系统C语言的成熟度目前,用c语言开发出来的学生信息管理系统已经具备较高的成熟度,它可以实现大多数主流学校的学生信息管理系统的基本需求,如学生信息查询、增加、删除、修改等,同时也可以实现更多复杂的功能,比如报表统计、统一登录和权限管理等。
3学生信息管理系统C语言的主要功能学生信息管理系统C语言的主要功能有:学生信息查询、增加、删除、修改,录入、报表统计、统一登录和权限管理等功能,其中学生信息查询的功能可以实现学生的基本信息,学习成绩,校园缴费,报到服务等查询;增加、删除和修改功能可以方便学校对学生信息进行管理;报表统计使用Excel或Access或界面精密Tsort对学生信息进行统计;统一登录和权限管理是指学校可以给不同用户赋予不同的权限,不同用户只能访问其角色所拥有的功能。
4学生信息管理系统C语言的优缺点学生信息管理系统用c语言编写的优点是:代码调试方便,程序运行速度快,新手也能上手,而且对于数据库实现也比较容易;优点也有缺点,首先,C语言是一门面向过程编程语言,缺乏面向对象、动态内存分配等特性,可维护性和可扩展性较差,其次,C语言的数据类型容易混乱,入口函数的嵌套层次太深容易出错。
5改进建议为了提高学生信息系统C语言的安全性、可扩展性和可维护性,让系统更加智能,建议:①使用现代化的Java、Python或C++编写代码;②采用组件式设计,将模块分开,单独编程;③支持多种浏览器,支持动态页面显示;④采用更多的设计模式,做到安全易用、可扩展、可维护;⑤建立事务系统,实现系统的智能化,通过人工智能实现系统的可维护性和安全性。
C语言课程设计报告 --学生管理系统一、实验目的:通过本次实验,学习C语言的语法和数据类型,设计一个简单的学生管理系统,结合文件I/O所学,可以将学生信息保存至文件中,再读取时自动填充至程序中。
同时,体验软件开发的流程,从需求分析到具体实现。
二、需求分析:1、学生信息包括:学号、姓名、性别、年龄、成绩。
2、学生信息需要添加、删除、修改、查找和显示。
3、程序启动时自动从文件中读取数据,退出时自动保存数据。
三、实验过程:1、确定数据结构和变量类型通过分析需求,学生信息包含多个属性,可以使用结构体来保存每个学生的信息。
同时,为了便于程序运行,需要定义一个链表来保存所有学生信息。
/* 学生信息结构体 */typedef struct _Student {char id[12]; // 学号char name[20]; // 姓名char gender; // 性别int age; // 年龄double score; // 成绩} Student;/* 学生信息链表节点 */typedef struct _StudentNode {Student data; // 学生信息struct _StudentNode *next; // 下一节点指针} StudentNode;/* 学生信息链表头节点 */StudentNode *head = NULL;2、设计主菜单功能考虑学生管理系统的主要功能,可以设计以下主菜单:---------------------------1. 添加学生2. 删除学生3. 修改学生信息4. 查找学生5. 显示所有学生6. 退出---------------------------可以使用一个while循环来循环处理,直到用户选择退出。
3、实现主菜单功能添加学生:先从用户输入中获取学生信息,然后创建一个新的学生信息节点,并将其添加到链表的末尾。
1. 定义变量/* 输入缓存区大小 */#define BUFFER_SIZE 2562. 实现函数/* 添加学生到链表末尾 */void add_student() {Student student; // 待添加的学生信息printf("请输入学号:");scanf("%s", student.id);printf("请输入姓名:");scanf("%s", );printf("请输入性别(M/F):");scanf(" %c", &student.gender);printf("请输入年龄:");scanf("%d", &student.age);printf("请输入成绩:");scanf("%lf", &student.score);StudentNode *node =(StudentNode*)malloc(sizeof(StudentNode));node->data = student;node->next = NULL;if (head == NULL) {head = node;} else {StudentNode *p = head;while (p->next != NULL) {p = p->next;}p->next = node;}printf("添加学生成功!\n");}删除学生:先从用户输入中获取学生学号,然后遍历链表,找到该学号对应的学生信息节点,并删除。
C语言学生管理系统#include#include#include#include#include#define LEN sizeof(struct student)#define FORMAT "%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lf\n"#define DATA stu[i].num,stu[i].name,stu[i].elec,stu[i].expe,stu[i].requ,stu[i].sum struct student/*定义学生成绩结构体*/{ int num;/*学号*/char name[15];/*姓名*/double elec;/*选修课*/double expe;/*实验课*/double requ;/*必修课*/double sum;/*总分*/};struct student stu[50];/*定义结构体数组*/void in();/*录入学生成绩信息*/void show();/*显示学生信息*/void order();/*按总分排序*/void del();/*删除学生成绩信息*/void modify();/*修改学生成绩信息*/void menu();/*主菜单*/void insert();/*插入学生信息*/void total();/*计算总人数*/void search();/*查找学生信息*/void main()/*主函数*/{ int n;menu();scanf("%d",&n);/*输入选择功能的编号*/while(n){ switch(n){ case 1: in();break;case 2: search();break;case 3: del();break;case 4: modify();break;case 5: insert();break;case 6: order();break;case 7: total();break;default:break;}getch();menu();/*执行完功能再次显示菜单界面*/scanf("%d",&n);}}void in()/*录入学生信息*/{ int i,m=0;/*m是记录的条数*/char ch[2];FILE *fp;/*定义文件指针*/if((fp=fopen("data.txt","a+"))==NULL)/*打开指定文件*/ { printf("can not open\n");return;}while(!feof(fp)) {if(fread(&stu[m] ,LEN,1,fp)==1)m++;/*统计当前记录条数*/}fclose(fp);if(m==0)printf("No record!\n");else{system("cls");show();/*调用show函数,显示原有信息*/}if((fp=fopen("data.txt","wb"))==NULL){ printf("can not open\n");return;}for(i=0;iscanf("%s",ch);while(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要录入新信息*/ {printf("number:");scanf("%d",&stu[m].num);/*输入学生学号*/ for(i=0;i<m;i++)< p="">if(stu[i].num==stu[m].num){printf("the number is existing,press any to continue!");getch();fclose(fp);return;}printf("name:");scanf("%s",stu[m].name);/*输入学生姓名*/printf("elective:");scanf("%lf",&stu[m].elec);/*输入选修课成绩*/printf("experiment:");scanf("%lf",&stu[m].expe);/*输入实验课成绩*/printf("required course:");scanf("%lf",&stu[m].requ);/*输入必修课成绩*/ stu[m].sum=stu[m].elec+stu[m].expe+stu[m].requ;/*计算出总成绩*/if(fwrite(&stu[m],LEN,1,fp)!=1)/*将新录入的信息写入指定的磁盘文件*/{ printf("can not save!"); getch(); }else { printf("%s saved!\n",stu[m].name);m++;}printf("continue?(y/n):");/*询问是否继续*/scanf("%s",ch);}fclose(fp);printf("OK!\n");}void show(){ FILE *fp;int i,m=0;fp=fopen("data.txt","rb");while(!feof(fp)){if(fread(&stu[m] ,LEN,1,fp)==1)m++;}fclose(fp);printf("number name elective experiment required sum\t\n");for(i=0;i<m;i++)< p="">{printf(FORMAT,DATA);/*将信息按指定格式打印*/}}void menu()/*自定义函数实现菜单功能*/{system("cls");printf("\n\n\n\n\n");printf("\t\t|---------------------STUDENT-------------------|\n");printf("\t\t|\t 0. exit |\n");printf("\t\t|\t 1. input record |\n");printf("\t\t|\t 2. search record |\n");printf("\t\t|\t 3. delete record |\n");printf("\t\t|\t 4. modify record |\n");printf("\t\t|\t 5. insert record |\n");printf("\t\t|\t 6. order |\n");printf("\t\t|\t 7. number |\n");printf("\t\t|-----------------------------------------------|\n\n");printf("\t\t\tchoose(0-7):");}void order()/*自定义排序函数*/{ FILE *fp;struct student t;int i=0,j=0,m=0;if((fp=fopen("data.txt","r+"))==NULL){printf("can not open!\n");return;}while(!feof(fp))if(fread(&stu[m] ,LEN,1,fp)==1)m++;fclose(fp);if(m==0){printf("no record!\n");return;}if((fp=fopen("data.txt","wb"))==NULL){printf("can not open\n");return;}for(i=0;i<m-1;i++)< p="">for(j=i+1;j<="" p="">if(stu[i].sum<stu[j].sum)< p="">{ t=stu[i];stu[i]=stu[j];stu[j]=t;}if((fp=fopen("data.txt","wb"))==NULL){ printf("can not open\n");return;}for(i=0;i{printf("%s can not save!\n");getch();}fclose(fp);printf("save successfully\n");}void del()/*自定义删除函数*/{FILE *fp;int snum,i,j,m=0;char ch[2];if((fp=fopen("data.txt","r+"))==NULL){ printf("can not open\n");return;}while(!feof(fp)) if(fread(&stu[m],LEN,1,fp)==1) m++; fclose(fp);if(m==0){printf("no record!\n");return;}printf("please input the number:");scanf("%d",&snum);for(i=0;i<m;i++)< p="">if(snum==stu[i].num)break;printf("find the student,delete?(y/n)");scanf("%s",ch);if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否要进行删除*/for(j=i;j<m;j++)< p="">stu[j]=stu[j+1];/*将后一个记录移到前一个记录的位置*/m--;/*记录的总个数减1*/if((fp=fopen("data.txt","wb"))==NULL){ printf("can not open\n");return;}for(j=0;j<="" p="">if(fwrite(&stu[j] ,LEN,1,fp)!=1){ printf("can not save!\n");getch();}fclose(fp);printf("delete successfully!\n");}void search()/*自定义查找函数*/{ FILE *fp;int snum,i,m=0;char ch[2];if((fp=fopen("data.txt","rb"))==NULL){ printf("can not open\n");return;}while(!feof(fp)) if(fread(&stu[m],LEN,1,fp)==1) m++;fclose(fp);if(m==0) {printf("no record!\n");return;}printf("please input the number:");scanf("%d",&snum);for(i=0;i<m;i++)< p="">if(snum==stu[i].num)/*查找输入的学号是否在记录中*/{ printf("find the student,show?(y/n)");scanf("%s",ch);if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0){printf("number name elective experiment required sum\t\n");printf(FORMAT,DATA);/*将查找出的结果按指定格式输出*/ break;}}if(i==m) printf("can not find the student!\n");/*未找到要查找的信息*/}void modify()/*自定义修改函数*/{ FILE *fp;int i,j,m=0,snum;if((fp=fopen("data.txt","r+"))==NULL){ printf("can not open\n");return;}while(!feof(fp))if(fread(&stu[m],LEN,1,fp)==1) m++;if(m==0) {printf("no record!\n");fclose(fp);return;}printf("please input the number of the student which do you want to modify!\n"); scanf("%d",&snum);for(i=0;i<m;i++)< p="">if(snum==stu[i].num)/*检索记录中是否有要修改的信息*/break;printf("find the student!you can modify!\n");printf("name:\n");scanf("%s",stu[i].name);/*输入名字*/printf("\nelective:");scanf("%lf",&stu[i].elec);/*输入选修课成绩*/printf("\nexperiment:");scanf("%lf",&stu[i].expe);/*输入实验课成绩*/printf("\nrequired course:");scanf("%lf",&stu[i].requ);/*输入必修课成绩*/stu[i].sum=stu[i].elec+stu[i].expe+stu[i].requ;if((fp=fopen("data.txt","wb"))==NULL){ printf("can not open\n");return;}for(j=0;j<="" p="">if(fwrite(&stu[j] ,LEN,1,fp)!=1){ printf("can not save!"); getch(); }fclose(fp);}void insert()/*自定义插入函数*/{ FILE *fp;int i,j,k,m=0,snum;if((fp=fopen("data.txt","r+"))==NULL){ printf("can not open\n");return;}while(!feof(fp))if(fread(&stu[m],LEN,1,fp)==1) m++;if(m==0) {printf("no record!\n");fclose(fp);return;}printf("please input position where do you want to insert!(input the number)\n"); scanf("%d",&snum);/*输入要插入的位置*/for(i=0;i<m;i++)< p="">if(snum==stu[i].num)break;for(j=m-1;j>i;j--)stu[j+1]=stu[j];/*从最后一条记录开始均向后移一位*/printf("now please input the new information.\n");printf("number:");scanf("%d",&stu[i+1].num);for(k=0;k<m;k++)< p="">if(stu[k].num==stu[i+1].num){printf("the number is existing,press any to continue!");getch();fclose(fp);return;}printf("name:\n");scanf("%s",stu[i+1].name);printf("\nelective:");scanf("%lf",&stu[i+1].elec);printf("\nexperiment:");scanf("%lf",&stu[i+1].expe);printf("\nrequired course:");scanf("%lf",&stu[i+1].requ);stu[i+1].sum=stu[i+1].elec+stu[i+1].expe+stu[i+1].requ;if((fp=fopen("data.txt","wb"))==NULL){ printf("can not open\n");return;}for(k=0;k<=m;k++)if(fwrite(&stu[k] ,LEN,1,fp)!=1)/*将修改后的记录写入磁盘文件中*/{ printf("can not save!"); getch(); }fclose(fp);}void total(){ FILE *fp;int m=0;if((fp=fopen("data.txt","r+"))==NULL){ printf("can not open\n");return;}while(!feof(fp))if(fread(&stu[m],LEN,1,fp)==1)m++;/*统计记录个数即学生个数*/if(m==0) {printf("no record!\n");fclose(fp);return;}printf("the class are %d students!\n",m);/*将统计的个数输出*/ fclose(fp);}</m;k++)<></m;i++)<></m;i++)<></m;i++)<></m;j++)<></m;i++)<></stu[j].sum)<></m-1;i++)<></m;i++)<></m;i++)<>。
#define PRINT0 printf("name:%s\nsex:%s\nage:%d\nID_card:%d\naddress:%s\n",st[i].name,st[i].sex,st[i].age,st[i] .ID_card,st[i].addr)#define PRINT1 printf("prefession:%s\nstudent_number:%d\n*****score*****\nwuli:%d\n",st[i].prefession,st[i] .student_number,st[i].score.wuli)#define PRINT2 printf("gaoshu:%d\nyingyu:%d\ntiyu:%d\naverage: %d\n",st[i].score.gaoshu,st[i].score.yingyu,st[i ].score.tiyu,st[i].score.aver)#define print1 printf("________________________________")#define N 2#include "string.h"#include "stdio.h"int sum=0;struct score{int wuli;int gaoshu;int yingyu;int tiyu;int aver;};struct message{ char name[10];int age;char sex[5];int ID_card;char addr[30];char prefession[30];int student_number;struct score score;}st[100];/*************write message*************/write_message(){ int flag;char chioce;do{system("cls");flag=2; sum++;printf("_______________________________");printf("please input student's message:\n");printf("\n");print1;printf("%dth student message:",sum);print1;printf("\nname:");scanf("%s",st[sum].name);printf("\nsex:");scanf("%s",st[sum].sex);printf("\nage:");scanf("%d",&st[sum].age);printf("\nID_card:");scanf("%d",&st[sum].ID_card);printf("\naddress:");scanf("%s",st[sum].addr);printf("\nprefession:");scanf("%s",st[sum].prefession);printf("\nschool number:");scanf("%d",&st[sum].student_number);printf("\n*****score******\n");printf("wuli:");scanf("%d",&st[sum].score.wuli);printf("\ngaoshu:");scanf("%d",&st[sum].score.gaoshu);printf("\nyingyu:");scanf("%d",&st[sum].score.yingyu);printf("\ntiyu:");scanf("%d",&st[sum].score.tiyu);printf("\naverage:");scanf("%d",&st[sum].score.aver);do{printf("****************************\n");printf("press y/Y continue:\npress n/N stop:\n");getchar();scanf("%c",&chioce);printf("****************************\n");if(chioce=='y'||chioce=='Y') {flag=1; break;}else if(chioce=='n'||chioce=='N') {flag=0; break;}else printf("input error\n");print1;printf("\n");}while(1);}while(flag==1);save_message();}/*************save message****************/save_message(){ FILE *fp;int i;if((fp=fopen("student.txt","wb"))==NULL){printf("read error \n");printf("press any key back to menu\n");getch();exit(1);}for(i=0;i<sum;i++)if(fwrite(&st[i],sizeof(struct message),1,fp)!=1){printf("write error\n");fclose(fp);}fclose(fp);printf("\n********___OK!___**********\n___press any key back___");sum=i;bioskey(0);}/***************add message*****************/add_message(){int i,j,flag; char chioce;i=0;j=sum-1;flag=0;do{ system("cls");i++; j++;print1;printf("add %dth student's meaasge\n",i);print1;printf("\nname:");scanf("%s",st[j].name);printf("\nsex:");scanf("%s",st[j].sex);printf("\nage:");scanf("%d",&st[j].age);printf("\nID_card:");scanf("%d",&st[j].ID_card);printf("\naddress:");scanf("%s",st[j].addr);printf("\nprefession:");scanf("%s",st[j].prefession);printf("\nstudent_number:");scanf("%d",&st[j].student_number);printf("\n*****score******\n");printf("wuli:");scanf("%d",&st[j].score.wuli);printf("\ngaoshu:");scanf("%d",&st[j].score.gaoshu);printf("\nyingyu:");scanf("%d",&st[j].score.yingyu);printf("\ntiyu:");scanf("%d",&st[j].score.tiyu);printf("\naverage:");scanf("%d",&st[j].score.aver);printf("\n\nweather add %dth student's message: \n",i+1);do{printf("****************************\n");printf("press y/Y continue:\npress n/N stop:\n");getchar();scanf("%c",&chioce);printf("****************************\n");if(chioce=='y'||chioce=='Y') {flag=1; break;}else if(chioce=='n'||chioce=='N') {flag=0; break;}else printf("input error\n");print1;}while(1);}while(flag==1);sum=j+1;save_message();}/**********inqiure message******/inqiure_message(){int chioce;do{system("cls");printf("**********choose 0-3**********\n\n\n");printf(" 1:name inquire\n\n\n");printf(" 2:IDcard inqiure\n\n\n");printf(" 3:student_number\n \n\n");printf(" 0:back menu\n\n\n");scanf("%d",&chioce);switch(chioce){case 1: name_inqiure();break;case 2: ID_card_inqiure();break;case 3: grade_inqiure();break;case 0:break;}}while(chioce!=0);}/**********name inqiure*********/name_inqiure(){char NAME[30];int i; int flag,k;char chioce;do{ system("cls");k=0;printf("please input the message you inqiure");printf("\nname:");scanf("%s",NAME);getchar();printf("\n");for(i=0;i<sum;i++){if(strcmp(st[i].name,NAME)==0){PRINT0;PRINT1;PRINT2;k=1;}}if(k==0) printf("without message you inqiure\n");do{ printf("****************************\n");printf("press y/Y continue:\npress n/N stop:\n");scanf("%c",&chioce); getchar();printf("****************************\n");if(chioce=='y'||chioce=='Y') {flag=1; break;}if(chioce=='n'||chioce=='N') {flag=0; break;}else printf("input error\n");print1;printf("\n");}while(1);}while(flag==1);printf("press any key return to menu");bioskey(0);}/**********IDcard inqiure*********/ID_card_inqiure(){int card;int i; int flag,k;char chioce;do{ clrscr(); k=0;printf("please input the message you inqiure");printf("\nIDcard:");scanf("%d",&card);getchar();printf("\n");for(i=0;i<sum;i++){if(st[i].ID_card==card){PRINT0;PRINT1;PRINT2;k=1;}}if(k==0) printf("without message you inqiure\n");do{ printf("****************************\n");printf("press y/Y continue:\npress n/N stop:\n");scanf("%c",&chioce); getchar();printf("****************************\n");if(chioce=='y'||chioce=='Y') {flag=1; break;}if(chioce=='n'||chioce=='N') {flag=0; break;}else printf("input error\n");print1;printf("\n");}while(1);}while(flag==1);printf("press any key return to menu");bioskey(0);}/*********grade inqiure***********/grade_inqiure(){int GRADE;int i; int flag,k;char chioce;do{ system("cls");k=0;printf("please input the message you inqiure");printf("\nstudent_number:");scanf("%d",&GRADE);getchar();printf("\n");for(i=0;i<sum;i++){if(st[i].student_number==GRADE){PRINT0;PRINT1;PRINT2;k=1;}}if(k==0) printf("without message you inqiure\n");do{ printf("****************************\n");printf("press y/Y continue:\npress n/N stop:\n");scanf("%c",&chioce); getchar();printf("****************************\n");if(chioce=='y'||chioce=='Y') {flag=1; break;}if(chioce=='n'||chioce=='N') {flag=0; break;}else printf("input error\n");print1;printf("\n");}while(1);}while(flag==1);printf("press any key return to menu");bioskey(0);}/*********change message**********/change_message(){char pre[30],chioce;int i,gra,flag,num,s;s=0;do{system("cls");printf("please input message you want to change\n ");printf("student_number:");scanf("%d",&gra); getchar();for(i=0;i<sum;i++){if(st[i].student_number==gra){PRINT0;PRINT1;PRINT2;printf("\n********input message you want to change********\n");printf("0:name***1:sex***2:age***3:ID_card***4:address***\n5:prefession***6:wuli***7:stud ent_number***8\n:gaoshu***9:yingyu***10:tiyu***11:average***________\n");printf("choose 0-11\n");scanf("%d",&num); getchar();switch(num){case 0: printf("input the name changed\n");scanf("%s",st[i].name); getchar(); break;case 1: printf("input the sex changed\n");scanf("%s",st[i].sex); getchar(); break;case 2: printf("input the age changed\n");scanf("%d",&st[i].age); getchar(); break;case 3: printf("input the ID_card changed\n");scanf("%d",&st[i].ID_card); getchar(); break;case 4: printf("input the address changed\n");scanf("%s",st[i].addr); getchar(); break;case 5: printf("input the prefession changed\n");scanf("%s",st[i].prefession); getchar(); break;case 6: printf("input the wuli_score changed\n");scanf("%d",&st[i].score.wuli); getchar(); break;case7: printf("input the student_number changed\n");scanf("%d",&st[i].student_number); getchar(); break;case 8: printf("input the gaoshu_score changed\n");scanf("%d",&st[i].score.gaoshu); getchar(); break;case 9: printf("input the yingyu_score changed\n");scanf("%d",&st[i].score.yingyu); getchar(); break;case 10: printf("input the tiyu_score changed\n");scanf("%d",&st[i].score.tiyu); getchar(); break;case 11: printf("input the average_score changed\n");scanf("%d",&st[i].score.aver); getchar(); break;default: printf("input error\n"); break;}printf("\n*********the changed message*********\n\n");PRINT0;PRINT1;PRINT2;s=1;}}if(s!=1) printf("without message you want to change\n");do{ printf("****************************\n");printf("press y/Y continue:\npress n/N stop:\n");scanf("%c",&chioce); getchar();printf("****************************\n");if(chioce=='y'||chioce=='Y') {flag=1; break;}if(chioce=='n'||chioce=='N') {flag=0; break;}else printf("input error\n");print1;printf("\n");}while(1);}while(flag==1);save_message();}/*********delete message**********/delete_message(){ int GRADE;int i,j,flag1,flag;char chioce1,chioce2;flag1=3;flag=3;do{ system("cls");printf("please input student's student_number you want to delete\n");printf("student_number:");scanf("%d",&GRADE); getchar();for(i=0;i<sum;i++)if(st[i].student_number==GRADE){do{PRINT0;PRINT1;PRINT2;printf("\n******************************\n_________________ _________________\n");printf("press y/Y deleted:\npress n/N cancel:\n");scanf("%c",&chioce1);getchar();system("cls");if(chioce1=='y'||chioce1=='Y') flag1=1;else if(chioce1=='n'||chioce1=='N') return;else {printf("***input error***\n___press any ker return___\n"); bioskey(0);}}while(flag1!=1);for(j=i;j<sum;j++){ st[j]=st[j+1];flag=2;printf("message was deleted\n");sum-=1; }}if(flag!=2) printf("without message you want to delete\n");do{printf("press y/Y continue:\npress n/N stop:\n");scanf("%c",&chioce2);printf("****************************\n");if(chioce2=='y'||chioce2=='Y') {flag=1; break;}else if(chioce2=='n'||chioce2=='N') {flag=0; break;}else {system("cls");printf("input error\n");}print1;printf("\n");}while(1);}while(flag==1);save_message();}/************insert message*************/insert_message(){ int chioce,flag,i; flag=2;do{system("cls");printf("please input the number of people you insert\n");scanf("%d",&chioce);if(chioce>=sum){printf("xin xi pai zai zui hou ");chioce=sum;}for(i=sum;i>chioce;i--) st[i]=st[i-1];printf("\nplease input message you insert");printf("\nname:");scanf("%s",st[i].name);printf("\nsex:");scanf("%s",st[i].sex);printf("\nage:");scanf("%d",&st[i].age);printf("\nID_card:");scanf("%d",&st[i].ID_card);printf("\naddress:");scanf("%s",st[i].addr);printf("\nprefession:");scanf("%s",st[i].prefession);printf("\ngrade:");scanf("%d",&st[i].student_number);printf("\n*****score******\n");printf("wuli:");scanf("%d",&st[i].score.wuli);printf("\ngaoshu:");scanf("%d",&st[i].score.gaoshu);printf("\nyingyu:");scanf("%d",&st[i].score.yingyu);printf("\ntiyu:");scanf("%d",&st[i].score.tiyu);printf("\naverage:");scanf("%d",&st[i].score.aver);sum+=1;do{printf("****************************\n");printf("press y/Y continue:\npress n/N stop:\n");getchar();scanf("%c",&chioce);printf("****************************\n");if(chioce=='y'||chioce=='Y') {flag=1; break;}else if(chioce=='n'||chioce=='N') {flag=0; break;}else printf("input error\n");print1;printf("\n");}while(1);}while(flag==1);save_message();}/*********school_number_order***********/grade_order(){int i,j;system("cls");if(sum==0) {printf("**********no message**********\n____press any key return____");getch();return;}for(i=0;i<sum;i++)for(j=i+1;j<sum;j++)if(st[i].student_number>st[j].student_number){ st[sum+1]=st[i];st[i]=st[j];st[j]=st[sum+1];}printf("grade order from min to max\n");for(i=0;i<sum;i++){ print1;printf("\n%dth student's mssage\n",i+1);print1;printf("\n");PRINT0;PRINT1;PRINT2;getch();system("cls");}print1;printf("\ntotle num :%d\npress any key return to menu\n",sum);bioskey(0);}/***********wuli score order***************/wuli_order(){int i,j;system("cls");if(sum==0) {printf("**********no message**********\n____press any key return____");getch();return;}for(i=0;i<sum;i++)for(j=i+1;j<sum;j++)if(st[i].score.wuli>st[j].score.wuli){ st[sum+1]=st[i];st[i]=st[j];st[j]=st[sum+1];}printf("wuli score order from min to max\n");for(i=0;i<sum;i++){print1;printf("\n%dth student's mssage\n",i+1);print1;printf("\n");PRINT0;PRINT1;PRINT2;getch();system("cls");}print1;printf("\ntotle num :%d\npress any key return to menu\n",sum);print1;bioskey(0);}/***********gaoshu score order***************/gaoshu_order(){int i,j;system("cls");if(sum==0) {printf("**********no message**********\n____press any key return____");getch();return;}for(i=0;i<sum;i++)for(j=i+1;j<sum;j++)if(st[i].score.gaoshu>st[j].score.gaoshu){ st[sum+1]=st[i];st[i]=st[j];st[j]=st[sum+1];}printf("gaoshu score order from min to max\n");for(i=0;i<sum;i++){print1;printf("\n%dth student's mssage\n",i+1);print1;printf("\n");PRINT0;PRINT2;getch();system("cls");}print1;printf("\ntotle num :%d\npress any key return to menu\n",sum);print1;bioskey(0);}/***********yingyu score order***************/yingyu_order(){int i,j;system("cls");if(sum==0) {printf("**********no message**********\n____press any key return____");getch();return;}for(i=0;i<sum;i++)for(j=i+1;j<sum;j++)if(st[i].score.yingyu>st[j].score.yingyu){ st[sum+1]=st[i];st[i]=st[j];st[j]=st[sum+1];}printf("yingyu score order from min to max\n");for(i=0;i<sum;i++){print1;printf("\n%dth student's mssage\n",i+1);print1;printf("\n");PRINT0;PRINT1;PRINT2;getch();system("cls");}print1;printf("\ntotle num :%d\npress any key return to menu\n",sum);print1;bioskey(0);}/***********tiyu score order***************/tiyu_order(){int i,j;system("cls");if(sum==0) {printf("**********no message**********\n____press any key return____");getch();return;}for(i=0;i<sum;i++)for(j=i+1;j<sum;j++)if(st[i].score.tiyu>st[j].score.tiyu){ st[sum+1]=st[i];st[i]=st[j];st[j]=st[sum+1];}printf("yitu order from min to max\n");for(i=0;i<sum;i++){print1;printf("\n%dth student's mssage\n",i+1);print1;printf("\n");PRINT0;PRINT1;PRINT2;getch();system("cls");}print1;printf("\ntotle num :%d\npress any key return to menu\n",sum);print1;bioskey(0);}/***********average score order***************/average_order(){int i,j;system("cls");if(sum==0) {printf("**********no message**********\n____press any key return____");getch();return;}for(i=0;i<sum;i++)for(j=i+1;j<sum;j++)if(st[i].score.wuli>st[j].score.wuli){ st[sum+1]=st[i];st[i]=st[j];st[j]=st[sum+1];}printf("average score order from min to max\n");for(i=0;i<sum;i++){print1;printf("\n%dth student's mssage\n",i+1);print1;printf("\n");PRINT0;PRINT1;PRINT2;getch();system("cls");}print1;printf("\ntotle num :%d\npress any key return to menu\n",sum);print1;bioskey(0);}/********order message****************/order_message(){int chioce;do{system("cls");printf("**********choose 0-6**********\n\n");printf(" 1:grade order\n\n");printf(" 2:wuli score order\n\n");printf(" 3:gaoshu score order\n \n");printf(" 4:ying yu score order\n\n");printf(" 5:tiyu score order\n\n");printf(" 6:average score order\n\n");printf(" 0:back menu\n\n");scanf("%d",&chioce);switch(chioce){case 1: grade_order();break;case 2: wuli_order();break;case 3: gaoshu_order();break;case 4: yingyu_order();break;case 5: tiyu_order();break;case 6: average_order();break;case 0:break;}}while(chioce!=0);}/**********answer secretory***********/mima_message(){int flag;char answer[10];char secret[10]="abcd";flag=2;do{system("cls");printf("\n______________________mi ma wei 'abcd'________________\n\n");printf("______________________qing shu ru mi ma:");scanf("%s",answer);getchar();if(strcmp(secret,answer)==0){flag=1;printf("\n\n =====throngh=====\n\n\n");printf("____________________press any key into next:\n");bioskey(0);}else{flag=0;printf("______________________input error:\n");printf("______________________press any key to return:\n");bioskey(0);}}while(flag!=1);}/*********read message****************/read_message(){int i;system("cls");if(sum<=0){ printf("without message\n");getch();return;}for(i=0;i<sum;i++){system("cls");print1;printf("\n%dth student's mssage\n",i+1);print1;printf("\n");PRINT0;PRINT1;PRINT2;printf("\n********press any key -show the next one********\n ");getch();}printf("________________totle num :%d________________\n",sum); printf("_____________press any key return______________\n"); bioskey(0);}/*************************************/main(){int chioce,flag;mima_message();do{system("cls");chioce=9;printf("**********************************************\n");printf("****welcome to system of managing students****\n");printf("**********************************************\n\n");printf("-------------------choose 0-8-----------------\n\n");printf(" 1:write message\n\n");printf(" 2:add message\n\n");printf(" 3:inqiure name\n\n");printf(" 4:change message\n\n");printf(" 5:insert message\n\n");printf(" 6:order message\n\n");printf(" 7:delete message\n\n");printf(" 8:read messaeg\n\n");printf(" 0:***exit***\n\n");scanf("%d",&chioce);getchar();switch(chioce){case 1: write_message();break;case 2: add_message();break;case 3: inqiure_message();break;case 4: change_message();break;case 5: insert_message();break;case 6: order_message();break;case 7: delete_message();break;case 8: read_message();break;case 0: printf("___sure press y/Y:___\n\n___no sure press n/N:___");scanf("%c",&chioce);getchar();if(chioce=='y'||chioce=='Y') flag=0;else flag=1;break;default : printf("\n ___input error___\n\n");printf("***press any key to go on***\n");getch();break;}}while(flag!=0);save_message();system("cls");printf("\n\n___message was saved___\n\n\n*****file name is student.txt*****\n");bioskey(0);}。
学生管理系统c语言源代码学生管理系统c语言源代码#include stdio.h#include dos.h#include string.h#include stdlib.h#include malloc.h#define SIZE 8struct student{char name;char num;int score;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 rangeclass number:");scanf("%d",printf("Input the total number of the class(a):"); scanf("%d",length);if(lengtha)flag=0;}for(i=0;ilength;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;jj++){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;ilength;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;ilength;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,stu[i].score,stu[i].score,sum=stu[i].score+stu[i].score+stu[i].score,stu[i].ave);}}void chaxun(){ FILE *fp, *fp1;char n,name;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",switch(m){case 1:printf("\nchaxun number:");scanf("%s",n);for(flag=1,i=0;ii++){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;ii++){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,stu[j].score,stu[j].score,stu[j].ave);}else printf("\nNot found!");fclose(fp);fclose(fp1);}xiugai(){ int a;printf("\nplease select the menu(1.CHARU 2.__ ):");scanf("%d",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,s.score,s.score);s.ave=(s.score+s.score+s.score)/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;jj++)学生管理系统c语言源代码printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);n=i;for(t=0;stu[t].aves.avett++);printf("\nnow:\n");fp=fopen("stu1.txt","w");for(i=0;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)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,s.score, s.score,s.ave);for(i=t;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)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;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;jj++)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;flagii++){if(strcmp(number,stu[i].num)==0){for(t=i;tt++){strcpy(stu[t].num,stu[t+1].num);strcpy(stu[t].name,stu[t+1].name);for(j=0;jj++)stu[t].score[j]=stu[t+1].score[j];stu[t].ave=stu[t+1].ave;}n=n-1;elseprintf("\n Not found!");printf("\nNow,the content of file:\n");fp=fopen("stu1.txt","wb");for(i=0;ii++)fwrite(stu[i],sizeof(struct student),1,fp);fclose(fp);fp=fopen("stu1.txt","r");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++)printf("%-15s%11s%7d%7d%7d%10.2f\n",stu[i].name,stu[i].num,stu[i].score, stu[i].score,stu[i].score,stu[i].ave);fclose(fp);}paixu(){FILE *fp;int i,j,n;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\nfile'stu1.txt':");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;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);n=i;for(i=0;ii++)for(j=i+1;jj++)学生管理系统c语言源代码if(stu[i].avestu[j].ave){temp=stu[i];stu[i]=stu[j];stu[j]=temp;}printf("\nnow:");fp=fopen("stu1.txt","w");for(i=0;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);tongji(){ FILE *fp;int i,j,k,labe1,b;int a5=0;int a6=0;int a7=0;int a8=0;int a9=0; int a10=0; float t;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\nfile'stu1.txt':");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;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);k=i;for(i=0;ii++){labe1=0;if(stu[i].ave60){labe1++;t=labe1/(float)k*100;}}printf("\nbujigelv:");printf("%f%",t);printf("\n");for(j=0;jj++){a5=0;a6=0;a7=0;a8=0;a9=0;a10=0;k=i;printf("kemu is %d:\n",j);for(i=0;ii++)学生管理系统c语言源代码{b=stu[i].score[j]/10;if(b6)a5++;elseif(b=6b7)a6++;elseif(b=7b8)a7++;elseif(b=8b9)a8++;if(b=9b10)a9++;elseif(b==10)a10++;}printf(" 不及格is %d\n",a5);printf(" 60--69 is %d\n",a6);printf(" 70--79 is %d\n",a7);printf(" 80--89 is %d\n",a8);printf(" 90--99 is %d\n",a9);printf(" 100 is %d\n",a10);}}main(){int a;printf(" ____\n"); printf(" 欢迎进入学生成绩管理系统\n");printf(" ____\n"); while(1){printf("\n选择菜单:\n");printf("\n");printf(" 1.输入 2.查询 3.排序 4.修改 5.统计 6.退出\n"); scanf("%d",switch(a){case 1: shuru();break;case 2: chaxun(); break;case 3: paixu(); break;case 4: xiugai(); break;学生管理系统c语言源代码case 5: tongji();break; case 6: exit(0); }。
#include"stdio.h"#include"stdlib.h"#include"string.h"struct stu_info1{char num[13];//学号char name[10];//姓名char sex[5];//性别char cls[20];//班级}stu1[6];struct stu_info2{char counum[6];//课程号char counam[20];//课程名称int credit;//学分}stu2[6];struct stu_info3{char num[13];//学号char counum[6];//课程号float results;//分数}stu3[12];struct stu_info4{char num[13];//学号char counum[6];//课程号float results;//分数}stu4[12];int n=11;void main(){void gengxin();void input1();void input2();void input3();void output();void xianshi();void chaxun();void printf1();void printf2();input1();input2();output();int i;loop: ;printf("*************欢迎使用分数查询系统*************\n");printf("** 请选择**\n");printf("** 1.录入2.删除无用信息(管理员功能) **\n");printf("** 3.显示4.查询(学生功能) **\n");printf("** 5.显示学生信息6.显示课程信息**\n");printf("** 7.退出**\n");printf("**********************************************\n");scanf("%d",&i);switch(i){case 1: input3();break;case 2:gengxin();break;case 3:xianshi();goto loop;case 4: chaxun();goto loop;case 5: printf1();goto loop;case 6: printf2();goto loop;case 7:break;default:printf("error");break;}}void input1()//录入结构体stu1[]{int i;FILE *fp;if((fp=fopen("A.txt","r"))==NULL){printf("can not open file\n");exit(0);}/* printf(" 学号姓名性别班级\n");*/for(i=0;i<=5;i++){fscanf(fp,"%s%s%s%s",&stu1[i].num,&stu1[i].name,&stu1[i].sex,&stu1[i].cls);/*printf("%-13s %-10s %-5s %-20s\n",stu1[i].num,stu1[i].name,stu1[i].sex,stu1[i] .cls);*/}fclose(fp);}void input2()//录入结构体stu2[]{int i;FILE *fp;if((fp=fopen("B.txt","r"))==NULL){printf("can not open file\n");exit(0);}for(i=0;i<=5;i++){fscanf(fp,"%s%s%d",&stu2[i].counum,&stu2[i].counam,&stu2[i].credit);}fclose(fp);}void input3()//录入成绩{FILE *fp;fp=fopen("C.txt","w");int a,i,j,k;float cetss;char number[13],cnum[6],mima[10];printf("请输入管理员密码\n");scanf("%s",mima);if(strcmp(mima,"abc111")==0){printf("请输入要录入学生成绩的个数\n");scanf("%d",&a);for(i=1;i<=a;i++){printf("请输入要录入的第%d同学的学号:",i);scanf("%s",number);printf("请输入要录入的第%d同学的课程号:",i);scanf("%s",cnum);for(j=0;j<=5;j++)//学号{if((strcmp(number,stu1[j].num)==0))break;}if(j<=5){for(k=0;k<=5;k++)//课程号{if(strcmp(cnum,stu2[k].counum)==0){printf("请输入要录入同学的成绩:");scanf("%f",&cetss);fprintf(fp,"%s %s %f\n",number,cnum,cetss);break;}}}if(j>5||k>5){printf("Error,please input again");i=i-1;}printf("录入成功\n");}}else{printf("密码错误\n");}}void output()// 录入结构体stu3[]{int i;FILE *fp=fopen("C.txt","r");for(i=0;i<n;i++){fscanf(fp,"%s%s%f",&stu3[i].num,&stu3[i].counum,&stu3[i].results);/*printf("%s%s%f\n",stu3[i].num,stu3[i].counum,stu3[i].results);*/ }fclose(fp);}void xianshi()// 显示成绩{int i,j;for(i=0;i<n;i++){for(j=0;j<6;j++){if((strcmp(stu3[i].num,stu1[j].num))==0)printf("%s\t",stu1[j].name);}for(j=0;j<6;j++){if(strcmp(stu3[i].counum,stu2[j].counum)==0)printf("%s\t",stu2[j].counam);}printf("%3.1f\n",stu3[i].results);}}void chaxun()//查询功能{char number[13],c;int i,j,k,a,b,d;while((c=getchar())!='Q'){a=0,b=0;//a记录学分b记录学科printf("请输入要查询同学的学号\n");scanf("%s",number);for(i=0;i<n;i++){if(strcmp(number,stu3[i].num)==0){printf("学号:%s\t",stu3[i].num);for(j=0;j<6;j++){if(strcmp(stu3[i].num,stu1[j].num)==0){printf("姓名:%s\n",stu1[j].name);}}break;}}d=i;for(i=0;i<n;i++)if(strcmp(number,stu3[i].num)==0){b=b+1;for(j=0;j<6;j++){if(strcmp(stu3[i].num,stu1[j].num)==0){for(k=0;k<6;k++){if(strcmp(stu3[i].counum,stu2[k].counum)==0)break;}break;}}if(stu3[i].results>=60){a=a+stu2[k].credit;printf("课程号:%s\t课程名称:%s\t成绩:%3.1f\t实得学分:%d\n",stu3[i].counum,stu2[k].counam,stu3[i].results,stu2[k].credit);}elseprintf("课程号:%s\t课程名称:%s\t成绩:%3.1f\t实得学分:%d\n",stu3[i].counum,stu2[k].counam,stu3[i].results,0);}if(d<n){printf("共修%d科\t\t实得总学分:%d\n",b,a);}else{printf("学号输入错误\n");}getchar();printf("退出请按Q+回车,继续查询请按回车键");}}void gengxin()//更新信息,删除C.txt中无用信息{FILE *fp;int i,j,k;char mima[10];printf("请输入管理员密码\n");scanf("%s",mima);if(strcmp(mima,"abc111")==0){fp=fopen("C.txt","w");for(i=0;i<n;i++){for(j=0;j<6;j++)if(strcmp(stu3[i].num,stu1[j].num)==0){for(k=0;k<=5;k++)if(strcmp(stu3[i].counum,stu2[k].counum)==0)break;if(k<=5){fprintf(fp,"%s %s %f\n",stu3[i].num,stu3[i].counum,stu3[i].results);}}}printf("更新C.txt成功\n");fclose(fp);}else{printf("密码错误\n");}}void printf1()//显示学生信息{int i;printf(" 学号姓名性别班级\n");for(i=0;i<=5;i++){printf("%-13s%-10s%-5s %-20s\n\n",stu1[i].num,stu1[i].name,stu1[i].sex,stu1[i].cls);}}void printf2()//显示课程信息{int i;printf(" 课程编号课程名称学分\n");for(i=0;i<=5;i++){printf("%-6s%-20s %-4d\n\n",stu2[i].counum,stu2[i].counam,stu2[i].credit);}}。
用C语言编写学生信息管理系统Design Purpose:Design Content:1. Problem n:Design a student n management system that includes student n such as student ID, name, age, gender, date of birth, address, phone number, and email.2. nal Requirements:1. The system works in menu mode.2. Student n entry n (student n is saved in a file) - input.3. Student n browsing n - output.4. Student n query n - algorithm according to student ID query and name query.Detailed Design:1. Menu: void menu() {}2. Establish n: void readfile() {}3. Search: void seek() {}4. Modify n: void modify() {}5. Insert n: void insert() {}6. Delete n:void del(){}7. Browse n:void display(){}8. Save:void save(){Debugging and Testing:1. System nal menu.2. Select the menu "", enter the system help and ns n.3. Select menu "4" to add student n. (1) Input the number of people to be added. (2) Enter the student ID, name, age, gender, date of birth, address, phone number, and email in order. After input, the menu pops up.#include#include#include#define BUFLEN 100 #define LEN 15struct record{char code[LEN+1]; char name[LEN+1]; int age;char sex[3];char time[LEN+1];char add[30];char tel[LEN+1];char mail[30];void readfile();void seek();void modify();void modify() {int i, item, num;char sex1[3], s1[LEN+1], s2[LEN+1];printf("请输入要修改的学生的学号:\n"); scanf("%s", s1);for (i = 0; i < n; i++) {if (strcmp(stu[i].code, s1) == 0) {num = i;}}printf("------------------\n");printf("1.修改姓名\n");printf("2.修改年龄\n");printf("3.修改性别\n");printf("4.修改出生年月\n");printf("5.修改地址\n");printf("6.修改电话号码\n");printf("7.修改E-mail地址\n");printf("8.退出本菜单\n");printf("------------------\n");while (1) {printf("请选择子菜单编号:");scanf("%d", &item);switch (item) {case 1:printf("请输入新的姓名:\n"); scanf("%s", s2);strcpy(stu[num].name, s2);break;case 2:printf("请输入新的年龄:\n");scanf("%d", &stu[num].age);break;case 3:printf("请输入新的性别:\n");scanf("%s", sex1);strcpy(stu[num].sex, sex1);break;case 4:printf("请输入新的出生年月:\n"); scanf("%s", s2);strcpy(stu[num].time, s2);break;case 5:printf("请输入新的地址:\n");scanf("%s", s2);strcpy(stu[num].add, s2);break;case 6:printf("请输入新的电话号码:\n");scanf("%s", s2);strcpy(stu[num].phone, s2);break;case 7:printf("请输入新的E-mail地址:\n");scanf("%s", s2);strcpy(stu[num].email, s2);break;case 8:return;default:printf("输入有误,请重新选择子菜单编号\n"); break;}}void input(){int i;char s[10];printf("请输入学生人数:\n"); scanf("%d",&n);for(i=0;i<n;i++){printf("请输入学号:\n");scanf("%s",stu[i].code);printf("请输入姓名:\n");scanf("%s",stu[i].name);printf("请输入性别:\n");scanf("%s",stu[i].sex);printf("请输入年龄:\n");scanf("%d",&stu[i].age);printf("请输入出生日期:\n"); scanf("%s",stu[i].time);printf("请输入家庭住址:\n"); scanf("%s",stu[i].add);printf("请输入电话号码:\n");scanf("%s",stu[i].tel);printf("请输入E-mail地址:\n");scanf("%s",stu[i].mail);}void modify(){int num,choice;char s2[10];printf("请输入要修改信息的学生的学号:\n");scanf("%s",s2);for(num=0;num<n;num++){if(strcmp(stu[num].code,s2)==0){printf("请选择要修改的信息:\n");printf("1.学号 2.姓名 3.性别 4.年龄 5.出生日期\n");printf("6.家庭住址 7.电话号码 8.E-mail地址 9.退出\n");scanf("%d",&choice);switch(choice){case 1:printf("请输入新的学号:\n"); scanf("%s",s2);strcpy(stu[num].code,s2);break;case 2:printf("请输入新的姓名:\n"); scanf("%s",s2);strcpy(stu[num].name,s2);break;case 3:printf("请输入新的性别:\n"); scanf("%s",s2);strcpy(stu[num].sex,s2);break;case 4:printf("请输入新的年龄:\n");scanf("%d",&stu[num].age);break;case 5:printf("请输入新的出生日期:\n"); scanf("%s",s2);strcpy(stu[num].time,s2);break;case 6:printf("请输入新的家庭住址:\n"); scanf("%s",s2);strcpy(stu[num].add,s2);break;case 7:printf("请输入新的电话号码:\n"); scanf("%s",s2);strcpy(stu[num].tel,s2);break;case 8:printf("请输入新的E-mail地址:\n"); scanf("%s",s2);strcpy(stu[num].mail,s2);break;case 9:return;default:printf("请在1-8之间选择\n"); }}}void sort(){int i,j,*p,*q,s;char temp[10];for(i=0;i<n-1;i++){for(j=n-1;j>i;j--){if(strcmp(stu[j-1].code,stu[j].code)>0){strcpy(temp,stu[j-1].code);strcpy(stu[j-1].code,stu[j].code); strcpy(stu[j].code,temp);strcpy(temp,stu[j-1].name);strcpy(stu[j-1].name,stu[j].name); strcpy(stu[j].name,temp);strcpy(temp,stu[j-1].sex);strcpy(stu[j-1].sex,stu[j].sex);strcpy(stu[j].sex,temp);strcpy(temp,stu[j-1].time);strcpy(stu[j-1].time,stu[j].time); strcpy(stu[j].time,temp);strcpy(temp,stu[j-1].add);strcpy(stu[j-1].add,stu[j].add);strcpy(stu[j].add,temp);strcpy(temp,stu[j-1].tel);strcpy(stu[j-1].tel,stu[j].tel);strcpy(stu[j].tel,temp);strcpy(temp,stu[j-1].mail);strcpy(stu[j-1].mail,stu[j].mail);strcpy(stu[j].mail,temp);p=&stu[j-1].age;q=&stu[j].age;s=*q;*q=*p;*p=s;}}}}void insert() {int i = n, j, flag;printf("请输入待增加的学生数:\n");scanf("%d", &m);do {flag = 1;while (flag) {flag = 0;printf("请输入第%d个学生的学号:\n", i + 1);scanf("%s", stu[i].code);for (j = 0; j < i; j++) {if (strcmp(stu[i].code, stu[j].code) == 0) {printf("已有该学号,请检查后重新录入!\n");flag = 1;break;}}}printf("请输入第%d个学生的姓名:\n", i + 1);scanf("%s", stu[i].name);printf("请输入第%d个学生的年龄:\n", i + 1);scanf("%d", &stu[i].age);printf("请输入第%d个学生的性别:\n", i + 1);scanf("%s", stu[i].sex);printf("请输入第%d个学生的出生年月:(格式:年.月)\n", i + 1);scanf("%s", stu[i].time);printf("请输入第%d个学生的地址:\n", i + 1);scanf("%s", stu[i].add);printf("请输入第%d个学生的电话:\n", i + 1); scanf("%s", stu[i].tel);printf("请输入第%d个学生的E-mail:\n", i + 1); scanf("%s", stu[i].mail);if (flag == 0) {i++;}} while (i < n + m);n += m;printf("录入完毕!\n\n");sort();void del() {int i, j, flag = 0;char s1[LEN + 1];printf("请输入要删除学生的学号:\n");scanf("%s", s1);for (i = 0; i < n; i++) {if (strcmp(stu[i].code, s1) == 0) {flag = 1;for (j = i; j < n - 1; j++) {stu[j] = stu[j + 1];}n--;printf("删除成功!\n\n"); break;}}if (flag == 0) {printf("未找到该学号!\n\n"); }。
学生信息管理系统c语言代码以下是一个简单的学生信息管理系统的 C 语言代码示例,包含了学生信息的添加、查询、修改和删除功能。
由于代码超过了 400 字,我将提供一个简化的版本,你可以根据需要进行扩展和改进。
```c#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_STUDENTS 100// 学生结构体struct Student {char id[10];char name[50];int age;};// 学生信息列表struct Student students[MAX_STUDENTS];// 学生数量int studentCount = 0;// 添加学生信息void addStudent() {if (studentCount >= MAX_STUDENTS) {printf("学生数量已满,无法添加更多学生。
\n");return;}printf("请输入学生 ID: ");scanf("%s", students[studentCount].id);printf("请输入学生姓名: ");scanf("%s", students[studentCount].name);printf("请输入学生年龄: ");scanf("%d", &students[studentCount].age);studentCount++;printf("学生信息添加成功。
\n");}// 查询学生信息void queryStudent() {if (studentCount == 0) {printf("没有学生信息可供查询。
学⽣信息管理系统(C语⾔)#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct student{int id;char name[20];int age;char sex;char birthday[20];char address[20];char phone[15];char email[30];struct student *next;}student;student *head = NULL;int length;void create(){student *p1,*p2;length = 0;p1 = (student *)malloc(sizeof(student));p1->id = -1;if(head == NULL){head = p1;}printf("请输⼊学⽣的学号、姓名、年龄、性别、出⽣年⽉、地址、电话、电⼦邮箱:\n");while(1){p2 = (student *)malloc(sizeof(student));scanf("%d %s %d %c %s %s %s %s",&p2->id,p2->name,&p2->age,&p2->sex,&p2->birthday,&p2->address,p2->phone,p2->email);if(p2->id == 0){printf("链表创建完成!\n");break;}length ++;p1->next = p2;p2->next = NULL;p1 = p1->next;}return ;}void LoadStudentInFromFile(){student *p,*q;int c;FILE* f;f = fopen("input.txt","rb");if(f == NULL){return ;}fseek(f,0,SEEK_SET);p = (student *)malloc(sizeof(student));p->next = NULL;head = p;while(!feof(f)){c = fgetc(f);if(c != -1){fseek(f,-1,SEEK_CUR);}else{return ;}q = (student *)malloc(sizeof(student));fscanf(f,"%d",&q->id);fscanf(f,"%s",q->name);fscanf(f,"%d",&q->age);fscanf(f,"%c",&q->sex);fscanf(f,"%s",q->birthday);fscanf(f,"%s",q->address);fscanf(f,"%s",q->phone);fscanf(f,"%s",q->email);q->next = NULL;p->next = q;p = p->next;length ++;//链表长度}}void ModifyStudentInfo(){student *p = head->next;int num;printf("请输⼊要修改的学⽣的学号:");scanf("%d",&num);while(p != NULL){if(p->id == num){printf("修改前,学号为%d的学⽣信息如下:\n",num);printf("%d %s %d %c %s %s %s %s",p->id,p->name,p->age,p->sex,p->birthday,p->address,p->phone,p->email); printf("请输⼊学⽣的新电话:");getchar();gets(p->phone);printf("请输⼊学⽣的新地址:");gets(p->address);printf("修改后,学号为%d的学⽣信息如下:\n",num);printf("%d %s %d %c %s %s %s %s",&p->id,p->name,&p->age,p->sex,p->birthday,p->address,p->phone,p->email);return ;}p = p->next;}if(p == NULL){printf("该学号不存在!\n");return ;}}void display(){student *p = head->next;printf("链表中所有的学⽣信息如下:\n");while(p != NULL){printf("%d %s %d %c %s %s %s %s",p->id,p->name,p->age,p->sex,p->birthday,p->address,p->phone,p->email);printf("\n");p = p->next;}return ;}void search(){int num,x;char name[20];student *p = head->next;printf("请选择查询⽅式:\n");printf("1、按学号查询\t2、按姓名查询\n");scanf("%d",&x);if(x == 1){printf("需要查找的学⽣学号为:");scanf("%d",num);while(p != NULL){if(p->id == num){printf("学号为%d的学⽣信息如下:\n",num);printf("%d %s %d %c %s %s %s %s",p->id,p->name,p->age,p->sex,p->birthday,p->address,p->phone,p->email);return ;}p = p->next;}if(p == NULL){printf("⽆此记录!\n");}}else if(x == 2){printf("需要查找的学⽣姓名为:");getchar();gets(name);p = head->next;while(p != NULL){if(strcmp(p->name,name) == 0){printf("学⽣姓名为%s的学⽣信息如下:\n",name);printf("%d %s %d %c %s %s %s %s",p->id,p->name,p->age,p->sex,p->birthday,p->address,p->phone,p->email);return ;}p = p->next;}if(p == NULL){printf("⽆此记录!\n");}}return ;}void insert(){int num,i;student *p,*q;p = head;printf("请输⼊你要插⼊的位置:");scanf("%d",&num);if(num > length){printf("找不到插⼊的位置\n");return ;}else{printf("请输⼊你要插⼊的学⽣的信息:\n");q = (student *)malloc(sizeof(student));scanf("%d %s %d %c %s %s %s %s",&q->id,q->name,&q->age,&q->sex,q->birthday,q->address,q->phone,q->email);while(p != NULL){if(p->id == q->id){printf("该学号已经存在,⽆法插⼊!\n");return ;}p = p->next;}p = head;for(i=0; i<num; ++i){p = p->next;}q->next = p->next;p->next = q;length ++;printf("插⼊成功!\n");return ;}}void Delete(){int num;student *p,*q;q = head;p = head->next;printf("请输⼊要删除的学⽣的学号:\n");scanf("%d",&num);while(p != NULL){if(p->id == num){q->next = p->next;free(p);length --;printf("删除成功!\n");return ;}p = p->next;q = q->next;}if(p == NULL){printf("找不到要删除的编号!\n");return ;}}void menu(){printf("___________________________________________________\n"); printf("| 学⽣信息管理系统 |\n");printf("| 0、退出系统 |\n");printf("| 1、录⼊学⽣信息 |\n");printf("| 2、建⽴链表 |\n");printf("| 3、显⽰链表 |\n");printf("| 4、查找链表中的某个元素 |\n");printf("| 5、删除链表中指定学号的结点 |\n");printf("| 6、指定位置上插⼊⼀个新结点 |\n");printf("| 7、修改学⽣信息 |\n");printf("__________________________________________________\n"); return ;}int main(void){int a;menu();while(1){printf("请输⼊相应的功能:");scanf("%d",&a);switch(a){case0:return0;case1:LoadStudentInFromFile();menu();break;case2:create();menu();break;case3:if(head){display();menu();}else{printf("链表为空,请先建⽴链表!\n");menu();}break;case4:if(head){search();menu();}else{printf("链表为空,请先建⽴链表!\n");menu();}break;case5:if(head){Delete();menu();}else{printf("链表为空,请先建⽴链表!\n");menu();}break;case6:if(head){insert();menu();}else{printf("链表为空,请先建⽴链表!\n");menu();}break;case7:if(head){ModifyStudentInfo();menu();}else{printf("链表为空,请先建⽴链表!\n"); menu();}break;default:break;}}system("pause");return0;}。
#include<stdio.h>#include<string.h>#include<malloc.h>typedef struct _STUDENTINFOR_ {char Name[20];unsigned int Age;}Stu,*pStu;typedef struct _NODE_{pStu pStuTemp;_NODE_* pNext;}Node,*pNode;pNode pHead = NULL;pNode pTail = NULL;int BOK = 1;int g_count = 0;int count = 0;void MainMenu(); //void MenuOne(); //void MenuTwo();//void CreateList(char* Name,int Age);// void SortList(); //void InsertOneStuInfor();//void DeletOneStuInfor();void DeletStuInforBasisName();// void DeletStuInforBasisAge();void DeletStuInforBasisAgeLimit(); void TravelAllStuInfor();void TravelOneStuInfor();void TravelStuInforBasisName();void TravelStuInforBasisAgeLimit();void WriteFileJudge();void ReadFileJudge();int OneFileJudge();void WriteFile();void ReadFile();void FreeMemory();int Select();//void FreeFile();//pNode InsertCalcNode();//pNode DeletCalcNode(pNode pNodeTemp);//void main(){int i = 0;char Name[20] = {0};unsigned int Age = 0;do{MainMenu();printf("请选择你要执行的功能:\n");scanf("%d",&i);switch(i){BOK = 1;case 1:do{printf("请输入学生信息:\n");scanf("%s",Name);scanf("%d",&Age);CreateList(Name,Age);Select();}while(BOK==1);WriteFileJudge();printf("\n返回至主菜单?\n");Select();break;case 2:do{printf("%d %d\n",g_count,count);ReadFileJudge();FreeFile();printf("%d %d\n",g_count,count);TravelAllStuInfor();InsertOneStuInfor();TravelAllStuInfor();WriteFileJudge();Select();}while(BOK==1);printf("\n返回至主菜单?\n");Select();break;case 3:i = 0;MenuOne();do{printf("请选择删除方法:\n");scanf("%d",&i);switch(i){case 1:ReadFileJudge();FreeFile();DeletStuInforBasisName();WriteFileJudge();break;case 2:ReadFileJudge();FreeFile();DeletStuInforBasisAge();WriteFileJudge();break;case 3:ReadFileJudge();FreeFile();DeletStuInforBasisAgeLimit();WriteFileJudge();break;case 4:ReadFileJudge();FreeFile();DeletOneStuInfor();WriteFileJudge();break;default:break;}Select();}while(BOK==1);printf("\n返回至主菜单?\n");Select();break;case 4:MenuTwo();do{printf("请选择查找方式:\n");scanf("%d",&i);switch(i){case 1:ReadFileJudge();//FreeFile();TravelAllStuInfor();FreeMemory();break;case 2:ReadFileJudge();//FreeFile();TravelOneStuInfor();FreeMemory();break;case 3:ReadFileJudge();//FreeFile();SortList();printf("排序后输出学生信息:\n");TravelAllStuInfor();FreeMemory();break;case 4:ReadFileJudge();//FreeFile();TravelStuInforBasisName();FreeMemory();break;case 5:ReadFileJudge();//FreeFile();TravelStuInforBasisAgeLimit();FreeMemory();break;default:break;}Select();}while(BOK==1);printf("\n返回至主菜单?\n");Select();break;case 5:FreeFile();printf("\n返回至主菜单?\n");Select();break;case 6:BOK = 0;break;default:BOK = 0;break;}}while(BOK==1);}void MainMenu(){int i = 0;printf("学生信息管理系统:\n");for(i=0;i<8;i++){printf(" ");}printf("1》输入学生信息2》添加学生信息3》删除学生信息\n\n");for(i=0;i<8;i++){printf(" ");}printf("4》显示学生信息5》清空文件6》退出系统\n\n");}void MenuOne(){int i = 0;printf("3》删除学生信息:\n");for(i=0;i<6;i++){printf(" ");}printf("1>依据姓名删除2>依据年龄删除3>依据年龄范围删除4>删除单个学生信息\n\n");}void MenuTwo(){int i = 0;printf("4》显示学生信息:\n");for(i=0;i<6;i++){printf(" ");}printf("1>显示全部学生信息2>显示单个学生信息3>按照从大到小的顺序显示学生信息\n\n");for(i=0;i<6;i++){printf(" ");}printf("4>显示姓名相同的学生的信息5>按照年龄分布输出学生信息\n\n");}int Select(){char Select = 0;printf("请问是否继续? Y(Yes) or N(No):\n");scanf(" %c",&Select);switch(Select){case 'Y':BOK = 1;break;case 'N':BOK = 0;break;default:BOK = 0;break;}return BOK;}void FreeFile(){FILE* fp = fopen("StuInfor.txt","w");fclose(fp);fp = fopen("count.txt","w");fclose(fp);g_count = 0;printf("文件已清空!\n");}void CreateList(char* Name,int Age){pNode pNodeTemp = (pNode)malloc(sizeof(Node));if(pNodeTemp==NULL){printf("没有内存可供申请!\n");}else{pNodeTemp->pStuTemp = (pStu)malloc(sizeof(Stu));if(pNodeTemp->pStuTemp==NULL){printf("内存不够!\n\n");free(pNodeTemp);}else{strcpy(pNodeTemp->pStuTemp->Name,Name);pNodeTemp->pStuTemp->Age = Age;pNodeTemp->pNext = NULL;if(pHead==NULL){pHead = pTail = pNodeTemp;}else{pTail->pNext = pNodeTemp;pTail = pNodeTemp;}}}}void SortList(){pNode pNodeTemp = pHead;pNode pNextNodeTemp = NULL;pStu pTemp = NULL;int i = 0;int j = 0;for(i=0;i<count-1;i++){pNextNodeTemp = pNodeTemp->pNext;for(j=i+1;j<count;j++){if(pNextNodeTemp->pStuTemp->Age > pNodeTemp->pStuTemp->Age){pTemp = pNextNodeTemp->pStuTemp;pNextNodeTemp->pStuTemp = pNodeTemp->pStuTemp;pNodeTemp->pStuTemp = pTemp;}pNextNodeTemp = pNextNodeTemp->pNext;}pNodeTemp = pNodeTemp->pNext;}}pNode InsertCalcNode(){unsigned int Num = 0;pNode pNodeTemp = pHead;printf("请输入要插入的位置:\n");scanf("%d",&Num);while(Num>count){printf("你的输入有错误,请重试!\n");scanf("%d",&Num);}Num--;while(Num!=0){pNodeTemp = pNodeTemp->pNext;Num--;}return pNodeTemp;}void InsertOneStuInfor(){char Name[20] = {0};int Age = 0;pNode pNodeTemp = (pNode)malloc(sizeof(Node));if(pNodeTemp==NULL){printf("没有内存可供申请!\n");}else{pNodeTemp->pStuTemp = (pStu)malloc(sizeof(Stu));if(pNodeTemp->pStuTemp==NULL){printf("内存不够!\n");free(pNodeTemp);}else{printf("请输入要插入的学生信息:\n");scanf("%s",pNodeTemp->pStuTemp->Name);scanf("%d",&pNodeTemp->pStuTemp->Age);pNodeTemp->pNext = NULL;pNode pCurrentTemp = InsertCalcNode();if(pCurrentTemp->pNext==NULL){pCurrentTemp->pNext = pNodeTemp;pTail = pNodeTemp;}else{pNodeTemp->pNext = pCurrentTemp->pNext;pCurrentTemp->pNext = pNodeTemp;}count++;}}}pNode DeletCalcNode(pNode pNodeTemp){if(pNodeTemp==pHead){pHead = pNodeTemp->pNext;free(pNodeTemp->pStuTemp);free(pNodeTemp);pNodeTemp = pHead;count--;}else if(pNodeTemp==pTail){pNode pFormerNodeTemp = pHead;while(pFormerNodeTemp ->pNext!=pTail){pFormerNodeTemp = pFormerNodeTemp ->pNext;}pTail = pFormerNodeTemp;pTail->pNext = NULL;free(pNodeTemp->pStuTemp);free(pNodeTemp);pNodeTemp = NULL;count--;}else{pNode pFormerNodeTemp = pHead;while(pFormerNodeTemp ->pNext!=pNodeTemp){pFormerNodeTemp = pFormerNodeTemp ->pNext;}pFormerNodeTemp->pNext = pNodeTemp->pNext;free(pNodeTemp->pStuTemp);free(pNodeTemp);count--;pNodeTemp = pFormerNodeTemp->pNext;}return pNodeTemp;}void DeletStuInforBasisName(){char Name[20] = {0};int a = 0;int n = 0;pNode pNodeTemp = pHead;printf("请输入你所要删除学生的姓名:\n");scanf("%s",Name);do{a = strcmp(pNodeTemp->pStuTemp->Name,Name);if(a!=0){pNodeTemp = pNodeTemp->pNext;}else{pNodeTemp = DeletCalcNode(pNodeTemp);n++;}}while(pNodeTemp!=NULL);if(n==0){printf("没有您所要删除的信息!\n");}TravelAllStuInfor();}void DeletOneStuInfor(){char Name[20] = {0};unsigned int Age = 0;int n = 0;int a = 0;pNode pNodeTemp = pHead;printf("请输入你所要删除学生的姓名:\n");scanf("%s",Name);printf("请输入你要删除的年龄值:\n");scanf("%d",&Age);do{a = strcmp(pNodeTemp->pStuTemp->Name,Name);if(a!=0){pNodeTemp = pNodeTemp->pNext;}else{if(pNodeTemp->pStuTemp->Age!=Age){pNodeTemp = pNodeTemp->pNext;}else{pNodeTemp = DeletCalcNode(pNodeTemp);n++;}}}while(pNodeTemp!=NULL);if(n==0){printf("没有您所要删除的信息!\n");}TravelAllStuInfor();}void DeletStuInforBasisAge(){int Age = 0;int n = 0;pNode pNodeTemp = pHead;printf("请输入你要删除的年龄值:\n");scanf("%d",&Age);do{if(pNodeTemp->pStuTemp->Age!=Age){pNodeTemp = pNodeTemp->pNext;}else{pNodeTemp = DeletCalcNode(pNodeTemp);n++;}}while(pNodeTemp!=NULL);if(n==0){printf("没有您所要删除的信息!\n");}TravelAllStuInfor();}void DeletStuInforBasisAgeLimit(){int Age = 0;int n = 0;pNode pNodeTemp = pHead;printf("删除超过某一年龄值的学生信息,请输入年龄底线值:\n");scanf("%d",&Age);do{if(pNodeTemp->pStuTemp->Age<=Age){pNodeTemp = pNodeTemp->pNext;}else{pNodeTemp = DeletCalcNode(pNodeTemp);n++;}}while(pNodeTemp!=NULL);if(n==0){printf("没有您所要删除的信息!\n");}TravelAllStuInfor();}void TravelAllStuInfor(){int i = 0;pNode pNodeTemp = pHead;//if(pHead==pTail==NULL)if(pHead==NULL){printf("链表为空!\n");}else{while(pNodeTemp!=NULL){printf("%s",pNodeTemp->pStuTemp->Name);printf("%d",pNodeTemp->pStuTemp->Age);pNodeTemp = pNodeTemp->pNext;printf("\n");}}}void TravelOneStuInfor(){char Name[20] = {20};int Age = 0;int a = 0;int n = 0;pNode pNodeTemp = pHead;printf("请输入你要查询的学生姓名:\n");scanf("%s",Name);printf("请输入你要查询的学生年龄:\n");scanf("%d",&Age);do{a = strcmp(pNodeTemp->pStuTemp->Name,Name);if(a!=0){pNodeTemp = pNodeTemp->pNext;}else{if(pNodeTemp->pStuTemp->Age!=Age){pNodeTemp = pNodeTemp->pNext;}else{printf("%s",pNodeTemp->pStuTemp->Name);printf("%d",pNodeTemp->pStuTemp->Age);printf("\n");pNodeTemp = pNodeTemp->pNext;n++;}}}while(pNodeTemp!=NULL);if(n==0){printf("没有您所要查询的信息!\n");}}void TravelStuInforBasisName(){char Name[20] = {0};int a = 0;int n = 0;pNode pNodeTemp = pHead;printf("请输入你要查询的学生姓名:\n");scanf("%s",Name);do{a = strcmp(pNodeTemp->pStuTemp->Name,Name);if(a!=0){pNodeTemp = pNodeTemp->pNext;}else{printf("%s",pNodeTemp->pStuTemp->Name);printf("%d",pNodeTemp->pStuTemp->Age);printf("\n");pNodeTemp = pNodeTemp->pNext;n++;}}while(pNodeTemp!=NULL);if(n==0){printf("没有您所要查询的信息!\n");}}void TravelStuInforBasisAgeLimit(){int Age = 0;int n = 0;pNode pNodeTemp = pHead;printf("输出所有超过某一年龄的所有学生的信息,请输入这一年龄:\n");scanf("%d",&Age);do{if(pNodeTemp->pStuTemp->Age<=Age){pNodeTemp = pNodeTemp->pNext;}else{printf("%s",pNodeTemp->pStuTemp->Name);printf("%d",pNodeTemp->pStuTemp->Age);printf("\n");pNodeTemp = pNodeTemp->pNext;n++;}}while(pNodeTemp!=NULL);if(n==0){printf("没有您所要查询的信息!\n");}}void WriteFileJudge(){FILE* fp = fopen("count.txt","r");if(fp==NULL){fp = fopen("count.txt","w");WriteFile();}else{//int i = 0;// i = OneFileJudge();// if(i==0)// {// printf("原存储学生信息数为0!");// WriteFile();// }// else// {fread(&g_count,1,sizeof(int),fp);fclose(fp);WriteFile();// }}printf("信息已存储至文件!\n");}void ReadFileJudge(){FILE* fp = fopen("count.txt","r");int i = 0;if(fp==NULL){printf("文件不存在!\n");}else{// i = OneFileJudge();// if(i==0)// {// printf("文件为空,无学生信息!\n");//}// else//{fread(&g_count,1,sizeof(int),fp); //刚开始忘记写这句话,造成错误!只是后面读文件,遍历链表都出错误ReadFile();//}}}/*int OneFileJudge(){FILE* fp = fopen("count.txt","r");int a = 0;int i = 0;a = fgetc(fp);while(a!=EOF){a = fgetc(fp);i++;}return i;}*/void WriteFile(){FILE* fp = fopen("StuInfor.txt","a+");pNode pNodeTemp = pHead;while(pNodeTemp!=NULL){fwrite(pNodeTemp->pStuTemp,1,sizeof(Stu),fp);pNodeTemp = pNodeTemp->pNext;g_count++;}fclose(fp);FreeMemory();fp = fopen("count.txt","w");fwrite(&g_count,1,sizeof(int),fp);fclose(fp);}void ReadFile(){FILE* fp = fopen("StuInfor.txt","r");int i = 0;Stu StuInfor = {0};for(i=0;i<g_count;i++){fread(&StuInfor,1,sizeof(Stu),fp);CreateList(,StuInfor.Age);count++;}}void FreeMemory(){pNode pNodeTemp = NULL;while(pNodeTemp!=NULL)//while(pNodeTemp==NULL){pNodeTemp = pHead;pHead = pHead->pNext;free(pNodeTemp->pStuTemp);free(pNodeTemp);}pHead = pTail = NULL;printf("\n已清空整个链表! ");count = 0;}。
学生管理系统C语言#include"stdio.h"#include"string.h"#define N 4struct student{int num;char name[20];int pingshi;int shiyan;int kaoshi;float zonghe;float avg;int paiming;}stu[N];main(){ void input();void output();void tongji();void seek1();void seek2();void delete1();void delete2();void insert1();void insert2();void sort();void renew1();void renew2();char name[20];int a,n,y=1,m,p,q,s;printf("please input name:");scanf("%s",name);printf("%s",name);printf("\nplease input a:");scanf("%d",&a);printf("%d",a);if((name[20]="mahaijun"&&a==3412)||(name[20]="hutianqi"&&a==3406)||(name[20]="jialina" &&a==3407))printf("\nsuccess");while(y){ printf("\n");printf("**********************************************************\n");printf(" \n");printf("==========================================================\n");printf(" student manage system \n");printf("==========================================================\n");printf(" 1.pleaseinput student's .pingshi. shiyan .kaoshi \n");printf(" 2.output studentscore \n");printf(" 3.score tongji \n");printf(" 4.seek \n");printf(" 5.delete \n");printf(" 6.insert \n");printf(" 7.sort \n");printf(" 8.renew \n");printf(" 9.quit \n");printf("**********************************************************\n");printf("please 1~9:\n");scanf("%d",&n);switch(n){case 1:input(stu,N);break;case 2:output(stu,N);break;case 3:tongji(stu,N);break;case 4:{printf("Please input the ways of seek,1.number, :\n");scanf("%d",&m);if(m==1) seek1(stu,N);else seek2(stu,N);};break;case 5:{printf("Please input the ways of delete,1.number,:\n");scanf("%d",&p);if(p==1) delete1(stu,N);else delete2(stu,N);};break;case 6:{printf("Please input the ways of insert,1.zhiding,2.suiji:\n");scanf("%d",&q);if(q==1) insert1(stu,N);else insert2(stu,N);};break;case 7:sort(stu,N);break;case 8:{printf("Please input the ways of update,1.number, :\n");scanf("%d",&s);if(s==1) renew1(stu,N);else renew2(stu,N);};break;case 9:y=0;break;default:printf("please input again");break;}}}void input(){int i;for(i=0;i<N;i++){ printf("please %d student's data:\n",i+1);printf("num:");scanf("%d",&stu[i].num);printf("\nmame:");scanf("%s",stu[i].name);printf("\npingshi:");scanf("%d",&stu[i].pingshi);printf("\nshiyan:");scanf("%d",&stu[i].shiyan);printf("\nkaoshi:");scanf("%d",&stu[i].kaoshi);printf("Display all students data:\n");printf("num\tname\tpingshi\tshiyan\tkaoshi:\n");}}void output(){ int i;for(i=0;i<N;i++)printf("%d\t%s\t%d\t%d\t%d:\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaoshi);}void tongji(){int i,a=0,b=0,c=0,d=0,e=0,max=0,min=0;for(i=0;i<N;i++)stu[i].zonghe=(float)(stu[i].pingshi*0.1+stu[i].kaoshi*0.7+stu[i].shiyan*0.2);for(i=0;i<N;i++)if(stu[max].zonghe<stu[i].zonghe) max=i;printf("the high score student is:\n");printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[max].num,stu[max].name,stu[max].pingshi,stu[max].shiyan,stu[max].kaoshi,stu[max].zonghe);for(i=0;i<N;i++)if(stu[min].zonghe>stu[i].zonghe) min=i;printf("the lower score student is:\n");printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[min].num,stu[min].name,stu[min].pingshi,stu[min].shiya n,stu[min].kaoshi,stu[min].zonghe);for(i=0;i<N;i++){if(stu[i].zonghe>=90) a++;else if(stu[i].zonghe>=80) b++;else if(stu[i].zonghe>=70) c++;else if(stu[i].zonghe>=60) d++;else e++;}printf("90 yi shang de ren gong you:%d\n",a);printf("90~80 jian de ren gong you:%d\n",b);printf("80~70 jian de ren gong you:%d\n",c);printf("70~60 jian de ren gong you:%d\n",d);printf("60 yi xia de ren gong you:%d\n",e);}void seek1(){int i,m;printf("please input the seek student's number:\n");scanf("%d",&m);for(i=0;i<N;i++)if(m==stu[i].num) break;if(i>=N) printf("please seek again!");elseprintf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaosh i,stu[i].zonghe);}void seek2(){int i;char m[15];printf("please input the seek student's name:\n");scanf("%s",m);for(i=0;i<N;i++)if(!strcmp(m,stu[i].name)) break;if(i>=N) printf("no the people!");elseprintf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaoshi,stu[i].zonghe);}void delete1(){int i,j=0,m;printf("please input the delete student's number:\n");scanf("%d",&m);for(i=0;i<N;i++)if(stu[i].num!=m) stu[j++]=stu[i];for(i=0;i<j;i++)printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaosh i,stu[i].zonghe);}void delete2(){int i,j=0;char m[15];printf("please input the delete student's name:\n");scanf("%s",&m);for(i=0;i<N;i++)if(strcmp(stu[i].name,m)!=0) stu[j++]=stu[i];for(i=0;i<j;i++)printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaosh i,stu[i].zonghe);}void insert1(){int i,j=0,m;printf("please input the delete student's number:\n");scanf("%d",&m);for(i=0;i<N;i++)if(stu[i].num!=m) stu[j++]=stu[i];for(i=0;i<j;i++)printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaosh i,stu[i].zonghe);}void insert2(){int i,j=0;char m[15];printf("please input the delete student's name:\n");scanf("%s",&m);for(i=0;i<N;i++)if(strcmp(stu[i].name,m)!=0) stu[j++]=stu[i];for(i=0;i<j;i++)printf("%d\t%s\t%d\t%d\t%d\t%f\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i].kaosh i,stu[i].zonghe);}void sort(){struct student t;int i,j;for(i=0;i<N-1;i++)for(j=i+1;j<N;j++)if(stu[i].zonghe<stu[j].zonghe){t=stu[i];stu[i]=stu[j];stu[j]=t;}for(i=0;i<N;i++)stu[i].paiming=i+1;for(i=0;i<N;i++)printf("%d\t%s\t%d\t%d\t%d\t%f\t%d\n",stu[i].num,stu[i].name,stu[i].pingshi,stu[i].shiyan,stu[i]. kaoshi,stu[i].zonghe,stu[i].paiming);}void renew1(){struct student t;int i,a,j,x;printf("please input the update student's number:\n");scanf("%d",&a);for(i=0;i<N;i++)if(a==stu[i].num){ x=i;printf("%d\t%s\t%d\t%d\t%d\t%d\t%d\n",stu[x].num,stu[x].name,stu[x].pingshi,stu[x].shiyan,stu[ x].kaoshi,stu[x].zonghe,stu[x].paiming);break;}printf("lease input the update student's number:\n");printf("number name pingshi experiment test\n");scanf("%d%s%d%d%d",&stu[x].num,stu[x].name,&stu[x].pingshi,&stu[x].shiyan,&stu[x].kaoshi) ;printf("%d\t%s\t%d\t%d\t%d\n",stu[x].num,stu[x].name,stu[x].pingshi,stu[x].shiyan,stu[x].kaoshi) ;stu[x].zonghe=(float)(stu[x].pingshi*0.1+stu[x].kaoshi*0.7+stu[x].shiyan*0.2);for(i=0;i<N-1;i++)for(j=i+1;j<N;j++)if(stu[i].zonghe<stu[j].zonghe){t=stu[i];stu[i]=stu[j];stu[j]=t;}for(i=0;i<N;i++)stu[i].paiming=i+1;printf("%d\t%s\t%d\t%d\t%d\t%f\t%d\n",stu[x].num,stu[x].name,stu[x].pingshi,stu[x].shiyan,stu[ x].kaoshi,stu[x].zonghe,stu[x].paiming);}void renew2(){struct student t;int i,j,x;char a[15];printf("please input the update student's name:\n");scanf("%s",a);for(i=0;i<N;i++)if(!strcmp(a,stu[i].name)){x=i;printf("%d\t%c\t%d\t%d\t%d\t%f\t%d\n",stu[x].num,stu[x].name,stu[x].pingshi,stu[x].shiyan,stu[ x].kaoshi,stu[x].zonghe,stu[x].paiming);break;}printf("please input the update student's name:\n");printf("number name pingshi experiment test\n");scanf("%d%s%d%d%d",&stu[x].num,stu[x].name,&stu[x].pingshi,&stu[x].shiyan,&stu[x].kaoshi) ;stu[x].zonghe=(float)(stu[x].pingshi*0.1+stu[x].kaoshi*0.7+stu[x].shiyan*0.2);for(i=0;i<N-1;i++)for(j=i+1;j<N;j++)if(stu[i].zonghe<stu[j].zonghe){t=stu[i];stu[i]=stu[j];stu[j]=t;}for(i=0;i<N;i++)stu[i].paiming=i+1;printf("%d\t%s\t%d\t%d\t%d\t%f\t%d\n",stu[x].num,stu[x].name,stu[x].pingshi,stu[x].shiyan,stu[ x].kaoshi,stu[x].zonghe,stu[x].paiming);}。
流程图:运行结果:程序源码:#include <stdio.h>#include <malloc.h>#include <string.h>#include <stdlib.h>#include<conio.h>#define LEN sizeof(struct student)//求字节数运算符struct student{char name[20];long int num;char sex[4];int age;char address[30];float score;struct student *next;//链表};//定义一个结构题int TOTAL_NUM = 0;//学生总数struct student *head = NULL;void mainmenu ();//主界面void record (); //记录数据void insert(struct student *stu); //插入数据void display(struct student *stu); //显示一个学生的信息void displayAll (); //显示所有学生的信息void query(); //查询学生信息void query_by_num(); //按学号查询学生信息void query_by_name();void readData (); //读取文件里学生的信息void writeData (); //向文件写入学生信息void freeAll (); //清空链表内容void del (); //删除学生信息void change (); //更改学生信息void sort();//排序void devise (struct student *p); //选择更改内容int main (void){mainmenu ();return 0;}//系统主菜单void mainmenu (){int choice;choice = -1;readData ();printf ("\t\t\t----------------------------------------------------\n"); printf ("\t\t\t| 欢迎使用通信工程专业学生信息管理系统|\n");printf ("\t\t\t----------------------------------------------------\n"); printf ("\t\t\t本程序需要在当前目录下建立student.txt才可正常运行\n");do{printf ("\n\n\n");printf ("\t\t\t--------------------------------------------\n");printf ("\t\t\t通信工程专业学生信息管理系统|\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[6]----排序|\n");printf ("\t\t\t[0]----退出系统|\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 ();break;case 4:del ();break;case 5:change ();break;case 6:sort ();break;default:printf ("\n无效选项!");break;}}while (choice != 0);}//录入学生信息void record (){struct student *p0;p0 = (struct student *)malloc(LEN);printf ("\t\t\t请输入学生的姓名:");scanf ("%s",p0->name);printf ("\t\t\t请输入学生的学号:");scanf ("%ld",&p0->num);printf ("\t\t\t请输入学生的性别:");scanf ("%s",p0->sex);printf ("\t\t\t请输入学生的年龄:");scanf ("%d",&p0->age);printf ("\t\t\t请输入学生的地址:");scanf ("%s",p0->address);printf ("\t\t\t请输入学生的成绩:");scanf ("%f",&p0->score);insert (p0);printf ("\t\t\t该学生的信息为:\n");printf ("\t\t\t-------------------------------------------------------------------------------\n");printf ("\t\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;elsep2->next = p0;p0->next = p1;}else{p1->next = p0;p0->next = NULL;}}TOTAL_NUM++;}void display (struct student *p){printf ("\t\t\t%s\t%ld\t\t%d\t%s\t%s\t\t%f\n", p->name, p->num, p->age, p->sex,p->address, p->score);}//浏览学生信息void displayAll(){struct student *p;printf("\t\t\t学生总数:%d\n", TOTAL_NUM);p = head;if (head != NULL){printf("\t\t\t姓名\t学号\t\t年龄\t性别\t地址\t\t成绩\n");printf("\t\t\t-------------------------------------------------------------------------------\n");do{display(p);p = p->next;}while(p != NULL);}printf ("\n");}void query(){int choice;choice = -1;do{printf("\n");printf("--------------------\n");printf("| 按学号查询请按1 |\n");printf("| 按姓名查询请按2 |\n");printf("| 取消请按0 |\n");printf("+--------------------+\n");printf("请输入您的选择");scanf("%d", &choice);switch(choice){case 0:return;case 1:query_by_num();break;case 2:query_by_name();break;default:printf("\n无效选项!");break;}}while(choice != 0);}//按姓名查询学生信息void query_by_name(){char name[20];struct student *p1;printf("请输入学生的姓名");scanf("%s", name);if(head==NULL){printf("无学生记录\n");return;}p1=head;while(strcmp(name, p1->name) && p1->next!=NULL)p1=p1->next;if(!strcmp(name, p1->name)){printf("\t\t\t姓名\t学号\t\t年龄\t性别\t地址\t\t成绩\n");printf("\t\t\t-------------------------------------------------------------------------------\n");display(p1);}elseprintf("没有该学生记录请核对");}//按学号查询学生信息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\t成绩\n");printf ("\t\t\t-------------------------------------------------------------------------------\n");display (p1);}elseprintf ("\t\t\t没有该学生记录请核对");}//写入文件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%f\n", p->name, p->num, p->sex, p->age, p->address, p->score);}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("student.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%f\n", p1->name, &p1->num, p1->sex,&p1->age, p1->address, &p1->score);while(!feof(fp)){p1 = (struct student *)malloc(LEN);fscanf(fp,"%s\t%ld\t%s\t%d\t%s\t%f\n", p1->name, &p1->num, p1->sex, &p1->age, p1->address, &p1->score);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;elsep2->next = p1->next;free(p1);TOTAL_NUM--;}elseprintf("没有该学生记录请核对\n");}void sort() //排序模块。