最新学生信息管理系统C语言编程

合集下载

(完整word版)学生信息管理系统c语言版源代码

(完整word版)学生信息管理系统c语言版源代码

#include <stdio.h>#include <string.h> #include <stdlib.h> #include <conio.h> #define N 1000 typedef struct student {int number;char name[20];int grade;int gaoshu;int yingyu;int jisuanji;int sum;}STUDENT; STUDENT student[N]; int shuliang=0;void menu();void fhzjm(){char biaozhi[20]; printf("\n");printf("还需要操作么?如果需要操作请输入:yes,否则请输入:no\n");scanf("%s",biaozhi);if(strcmp(biaozhi,"yes")==0){menu();}else if(strcmp(biaozhi,"no")==0)exit(0);else{printf("请输入正确的字符,谢谢!\n");fhzjm();}}void DengJi(){int rs;int i,k=1;system("CLS");printf("请输入需要输入几个学生信息:"); scanf("%d",&rs);for(i=shuliang;i<shuliang+rs;i++,k++){printf("请输入第%d个学生的学号:",k); scanf("%d",&student[i].number); printf("请输入学生的姓名:");scanf("%s",student[i].name);printf("请输入学生3门课的成绩:"); printf("请输入第1门课的成绩:"); scanf("%d",&student[i].gaoshu); printf("请输入第2门课的成绩:"); scanf("%d",&student[i].yingyu); printf("请输入第3门课的成绩:");scanf("%d",&student[i].jisuanji);}shuliang=shuliang+rs;fhzjm();}void ShanChu(){char shanchuinfo[10];system("CLS");printf("删除全部学生信息请输入\"all\",删除指定学号的学生信息请输入\"one\"\n");scanf("%s",shanchuinfo);if(strcmp(shanchuinfo,"all")==0){int j;printf("你删除的学生信息如下:\n");printf("-----------学号-------------姓名-------------高数--------------英语--------------计算机\t\n");for(j=0;j<shuliang;j++)printf("----%d-------%s-------%d-------%d-------%d\t\n",student[j].number,student[j].name,student[j].gaos hu,student[j].jisuanji);shuliang=0;printf("删除成功\n\n");}else if(strcmp(shanchuinfo,"one")==0) {struct student *p=NULL;int choice;int i,j,k=0;printf("请输入你要删除的人的学号:"); scanf("%d",&choice);for(i=0;i<shuliang;i++){if(choice==student[i].number){k=1;j=i;break; }}if(k){if(shuliang==1) {p=&student[0]; free(p); shuliang=0;}else{for(i=j;i<shuliang;i++) {student[i]=student[i+1]; }shuliang=shuliang-1; }printf("删除成功\n\n"); }else{printf("输入数据错误!\n"); }}fhzjm();}void LiuLan(){int i;system("CLS");if(shuliang==0){printf("系统里面没有任何学生的信息!\n");}else{for(i=0;i<shuliang;i++){printf("第%d个学生的学号为:%d\n",i+1,student[i].number); printf("第%d个学生的姓名为:%s\n",i+1,student[i].name); printf("第%d个学生的第一门课的成绩为:%d\n",i+1,student[i].gaoshu);printf("第%d个学生的第二门课的成绩为:%d\n",i+1,student[i].yingyu);printf("第%d个学生的第三门课的成绩为:%d\n",i+1,student[i].jisuanji);student[i].sum=student[i].gaoshu+student[i].yingyu+stude nt[i].jisuanji;printf("第%d个学生的总成绩为:%d\n",i+1,student[i].sum);}}fhzjm();}void ChaZhao(){int xx;char choice,yy[20];int i,j,k=0;system("CLS");if(shuliang==0){printf("系统里面没有任何学生的信息!\n"); fhzjm();}printf("三种查找方式:学号,姓名,成绩\n");printf("如果按学号查找请输1,如果按姓名查找请输2,如果按成绩查找请输3\n");printf("请输入您查找的方式:");scanf("%s",&choice);if(choice=='1'){printf("请输入需要查找学生的学号:");scanf("%d",&xx);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数成绩----英语成绩----计算机成绩----\t\n");for(i=0;i<shuliang;i++){if(xx==student[i].number){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,st udent[j].yingyu,student[i].jisuanji);}}if(k==0)printf("输入信息有误:\n");}else if(choice=='2'){printf("请输入需要查找学生的姓名:\n");scanf("%s",yy);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数成绩----英语成绩----计算机成绩----\t\n");for(i=0;i<shuliang;i++){if(strcmp(yy,student[i].name)==0){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,st udent[j].yingyu,student[j].jisuanji);}}if(k==0)printf("输入信息有误:\n");}else if(choice=='3'){printf("请输入需要查找学生的成绩:\n");scanf("%d",&xx);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数----英语----计算机----\t\n");for(i=0;i<shuliang;i++){if(xx==student[i].grade){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,st udent[j].yingyu,student[i].jisuanji);}}if(k==0)printf("输入信息有误:\n");}fhzjm();}void PaiXu(){struct student *p1[N],**p2,*temp; int i,j;system("CLS");p2=p1;for( i=0;i<shuliang;i++){p1[i]=student+i;}for( i=0;i<shuliang;i++){for( j=i+1;j<shuliang;j++){if((*(p2+i))->sum<(*(p2+j))->sum){temp=*(p2+i);*(p2+i)=*(p2+j);*(p2+j)=temp;}}printf("按照总成绩排序之后的信息为:\n");printf("----学号----姓名----总成绩----\t\n");for( i=0;i<shuliang;i++){student[i].sum=student[i].gaoshu+student[i].yingyu+stude nt[i].jisuanji;printf("----%d-----%s----%d-----\n",(*(p2+i))->number,(*(p2+i))->name,(*(p2+i))->sum);}fhzjm();void CunChu(){int i;FILE *rs;if((rs=fopen("student.txt","w"))==NULL) {printf("not open");exit(0);}for(i=0;i<shuliang;i++)fwrite(&student[i], sizeof(student[i]), 1, rs); }if(ferror(rs)){fclose(rs);perror("写文件失败!\n");return;}printf("存储文件成功!\n");fclose(rs);}void DaoChu(){struct student t;int i=0;FILE* fp = fopen("student.txt", "r"); shuliang=0;if(NULL==fp){perror("读取文件打开失败!\n");}memset(student,0x0,sizeof(student)); while(1){fread(&t,sizeof(t),1,fp);if(ferror(fp)){fclose(fp);perror("读文件过程失败!\n"); return;}if(feof(fp)){break;}student[i]=t;i++;}fclose(fp);shuliang=i;printf("导出文件成功!\n");fhzjm();}void menu(){int n=0;system("CLS");printf(" 学生信息管理系统\n");printf(" 作者:陈椿\n");printf("-------------------MENU-----------------\n"); printf(" 1.登记学生信息\n");printf(" 2.删除学生信息\n");printf(" 3.浏览所有已经登记的学生\n"); printf(" 4.查找\n");printf(" 4.1按学号查找\n");printf(" 4.2按姓名查找\n");printf(" 4.3按成绩查找\n");printf(" 5.根据总成绩排序\n");printf(" 6.存储到文件\n");printf(" 7.从文件导出\n");printf(" 8.退出系统\n");a: printf(" 请选择:");scanf("%d",&n);switch (n){case 1:DengJi();break; case 2: ShanChu();break; case 3:LiuLan();break; case 4: ChaZhao();break; case 5:PaiXu();break;case 6:CunChu();break;case 7:DaoChu();break;case 8:exit(0);break;default:{printf("请输入1-8之间的数字,谢谢!\n"); goto a;}}}main() { menu(); }。

学生管理系统c语言简单版

学生管理系统c语言简单版

学生管理系统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. 查询学生信息查询学生信息可以按照姓名或电话号码进行查询。

学生信息管理系统C语言程序代码

学生信息管理系统C语言程序代码

#include <iostream.h> #include <iomanip.h>#include <fstream>#include <vector>#include <malloc.h>#include <stdlib.h>#include <string>#include <process.h>#include <stdio.h>#define LEN sizeof(struct student)using namespace std;int n=0; //定义一个全局变量统计学生人数struct student//定义一个学生信息的构造体char name[20]; //用来存放姓名的char sex[20]; //用来存放性别的char yuanxi[20];//用来存放院系的long int id; //用来存放学号的int score[4]; //用来存放分数的int total; //用来存放总分数的struct student *next;vector <student> stu;class Informationpublic:Information() ; //构造函数.~Information() ; //析构函数.student *creat();//建立链表函数。

void output(student *head);int count(student *head);//定义函数count()统计考生总数student *insert(student*head);//指针函数*insert()用来添加考生信息.student *cancel(student *head,long int num);//指针函数*cancel()用来删除考生信息.student *find(student *head,long int num); //指针函数*find()用来查找考生信息.void inorder(student *head);//定义inorder()函数将考生的总分从大到小排列并输出void average( student *head);//求学生成绩的平均分的函数void save(student *head);//保存函数student *Read();//读取函数private:student *p1,*p2,*p3,*head,st;Information::Information() //构造函数cout<<"******************************************************************************\n";cout<<" ------------------------<<欢送您使用学生信息管理系统>>------------------------\n";cout<<"******************************************************************* ***********\n\n";Information::~Information() //构造函数cout<<"******************************************************************* ***********\n";cout<<" ------------------------<<谢谢您使用学生信息管理系统>>------------------------\n";cout<<"******************************************************************* ***********\n";student *Information::creat(void) //定义一个指向struct student的构造体指针函数*creat()用来增加学生信息.char ch[20];n=0; //用来存放姓名的p1=p2=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元cout<<" -------------<<请建立学生考试信息表,在姓名处输入! 完毕输入。

学生信息管理系统(C语言)

学生信息管理系统(C语言)

#include<stdio.h>#include<string.h>int stu_sum = 0;struct Student{int rollno;char name[10];char address[30];char username[10];char password[10];float EnglishMarks;float MathsMarks;float ScienceMarks;float total;float average;char grade;}studlist[10];void main_menu(){printf(" Student Information Management System\n");printf("***********************************************************\n");printf("1.Login as Administrator\n");printf("2.Login as Student\n");printf("3.Exit\n");printf("***********************************************************\n");printf("Enter Y our Choice:");}void admin_menu(){printf(" Welcome Admin\n");printf("***********************************************************\n");printf("Admin Menu\n");printf("1. Register Student\n");printf("2. Exit\n");printf("***********************************************************\n");printf("Enter Y our Choice:");}void student_menu(){printf(" Welcome Student\n");printf("***********************************************************\n");printf("Student Menu\n");printf("1. V iew Marks\n");printf("2. Exit\n");printf("***********************************************************\n");printf("Enter Y our Choice:");}void registe(int id){printf("Enter Details of Student\n");printf("Rollno:");scanf("%d",&studlist[id].rollno);printf("Name:");scanf("%s",&studlist[id].name);printf("Address:");scanf("%s",&studlist[id].address);printf("Usename:");scanf("%s",&studlist[id].username);printf("Password:");scanf("%s",&studlist[id].password);printf("EnglishMarks:");scanf("%f",&studlist[id].EnglishMarks);printf("MathsMarks:");scanf("%f",&studlist[id].MathsMarks);printf("ScienceMarks:");scanf("%f",&studlist[id].ScienceMarks);printf("Student Registered Successfully !!!\n");}void mark_view(int i){studlist[i].total = studlist[i].EnglishMarks + studlist[i].MathsMarks + studlist[i].ScienceMarks;studlist[i].average = studlist[i].total / stu_sum;if(studlist[i].average >= 90){studlist[i].grade = 'A';}else if(studlist[i].average>=75 && studlist[i].average<90){studlist[i].grade = 'B';}else if(studlist[i].average>=50 && studlist[i].average<75){studlist[i].grade = 'C';}else{studlist[i].grade = 'F';}//print tabulationprintf("English\tMath\tScience\tTotal\tA verage\tGrade\t\n");printf("%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%c\t\n",studlist[i].EnglishMarks,studlist[i].MathsMark s,studlist[i].ScienceMarks,studlist[i].total,studlist[i].average,studlist[i].grade);}void main(){int i=0;int main_flag=1, admin_flag=1, student_flag=1;int main_choice,admin_choice,student_choice;char admin_name[10],admin_password[10],stu_name[10],stu_password[10];char admin[10] = "admin";while(main_flag){main_menu();//mainmenuscanf("%d",&main_choice);switch(main_choice){case 1:printf("Enter Username:");scanf("%s",admin_name);printf("Enter Password:");scanf("%s",admin_password);if(strcmp(admin_name,admin) != 0 || strcmp(admin_password,admin) != 0){printf("Name or Password error!\n");break;}while(admin_flag){admin_menu();//adminmenuscanf("%d",&admin_choice);switch(admin_choice){case 1:registe(stu_sum);stu_sum++;break;case 2:admin_flag = 0;break;}}break;case 2:printf("Enter Username:");scanf("%s",stu_name);printf("Enter Password:");scanf("%s",stu_password);while(i<stu_sum){if(strcmp(studlist[i].name,stu_name) == 0)break;i++;}if(strcmp(studlist[i].username,stu_name) != 0 || strcmp(studlist[i].password,stu_password) != 0){printf("Name or Password error!\n");break;}while(student_flag){student_menu();scanf("%d",&student_choice);switch(student_choice){case 1:mark_view(i);stu_sum++;break;case 2:student_flag = 0;break;}}break;case 3:main_flag = 0;break;}} }。

c语言--学生信息管理系统代码

c语言--学生信息管理系统代码

#include <stdio.h>#include <stdlib.h>#include <string.h>#define FUNC_NEW 1 /* 建立新的班级学生数据*/#define FUNC_SA VE 2 /*把数据写入文件并保存*/#define FUNC_OPEN 3 /*打开文件并从里读入数据*/#define FUNC_INSERT 4 /*插入一个学生的信息*/#define FUNC_SEARCH 5 /*查找学生的信息*/#define FUNC_CHANGE 6 /*修改学生的信息*/#define FUNC_DELETE 7 /*删除学生的信息*/#define FUNC_DISPLAY 8 /*展示学生的信息*/#define FUNC_CENSUS 9 /*分段统计学生总分人数并打印*/ #define FUNG_EXIT 10/*结束程序*/#define FUNC_CLOSE 10#define MAX_NUM 45#define MAX_NAME_STRLEN 30void DoSave();void DoOpen();void DoNew();void DoInsert();void DoDisplay();void DoDelete();void DoSearch();void DoChange();void Docensus();void DoExit();//用户定义的类型声明struct _student{int id;char name[MAX_NAME_STRLEN];int Math;int English;int Chinese;int Physics;int Chemistry;float averScore;int sum;};typedef struct _student STUD;struct _studTb{STUD stud[MAX_NUM];int length;};//全局变量的定义struct _studTb si;char strClassId[15];int main(){int iUserSelect;int MainMenu();system("color 20");for(;;){iUserSelect = MainMenu();if(FUNC_CLOSE == iUserSelect)break;switch(iUserSelect){case FUNC_NEW:DoNew();break;case FUNC_OPEN:DoSave();break;case FUNC_SA VE:DoOpen();break;case FUNC_INSERT:DoInsert();break;case FUNC_SEARCH:DoSearch();break;case FUNC_CHANGE:DoChange();break;case FUNC_DELETE:DoDelete();break;case FUNC_DISPLAY:DoDisplay();break;case FUNC_CENSUS:Docensus();break;case FUNC_CLOSE :DoExit();break;default:break;}}}int MainMenu(){int iUserSelect;system("cls");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(" | ****** 8> 展示学生信息的成绩排名****** | \n");printf(" | ****** 9> 分段统计学生信息****** | \n");printf(" | ****** 10> 退出学生系统****** | \n");printf(" | *****Please select a function id(1..9) to execute:***** | \n");printf(" --------------------------------------------------------------------- \n");scanf("%d",&iUserSelect);if(iUserSelect<1&&iUserSelect>9)printf("请正确输入指令\n");elsereturn iUserSelect;}void DoNew(){int number,i;system("cls");printf("\t\tFUNCION: 新建一个班级:\n");printf("\t\t请输入班级序号(string):");scanf("%s",strClassId);printf("\t\t请输入这个班有多少人:");scanf("%d",&number);for (i = 0; i < number; i++){printf("\t\t请输入学生学号:");scanf("%d",&si.stud[i].id);printf("\t\t请输入学生姓名:");scanf("%s",si.stud[i].name);printf("\t\t请输入学生成绩:\n");printf("\t\tMath English Chinese Physics Chemistry\n");scanf("%4d %4d %4d %4d %4d",\& si.stud[i].Math,& si.stud[i].English,& si.stud[i].Chinese,& si.stud[i].Physics,& si.stud[i].Chemistry);}si.length = number;}//保存学生信息void DoSave(){FILE *fp;int i;system("cls");if((fp=fopen("stu-list.txt","wb"))==NULL){printf("打开文件失败\n");return;}for(i=0;i<si.length;i++){if(fwrite(&si.stud[i],sizeof(si),1,fp)==1)printf("保存成功\n");}fclose(fp);}//开文件读取学生信息void DoOpen(){FILE *fp;int i=0;system("cls");if((fp=fopen("stu-list.txt","ab+"))==NULL){printf("打开文件失败\n");return;}while(!feof(fp)){if(fread(&si.stud[i],sizeof(si),1,fp)==1)i++;}fclose(fp);for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s 数学:%d 英语:%d 语文:%d 物理:%d 化学:%d\n",si.stud[i].id,si.stud[i].name,si.stud[i].Math,si.stud[i].English,si.stud[i].Chinese,si.stud[i].Physics,si.stud[i].Chemistry);}//插入学生信息void DoInsert(){FILE *fp;int j,INid,sid;int m=0,i=0,k=0;system("cls");if((fp=fopen("stu-list.txt","ab+"))==NULL){ printf("\t文件打开失败!");getchar();return;}while(!feof(fp)){if(fread(&si.stud[i],sizeof(si),1,fp)==1)m++;i++;}/*if(m==0){printf("没有学生记录!");fclose(fp);return;}*/printf("\t请输入要插入信息在那个学号之后:\n");scanf("%d",&INid);for(i=0;i<m;i++)if(INid==si.stud[i].id)break;for(j=m-1;j>i;j--)si.stud[j+1]=si.stud[j];stare1:printf("\t请输入要插入的学生的信息:\n");printf("\t请输入要插入的学号");scanf("%d",&sid);while(k<m){if(si.stud[k].id==sid){printf("\t 该学号已经存在,不允许重复插入!\n");goto stare1;}k++;}si.stud[i+1].id=sid;printf("\t请输入你想输入的姓名");scanf("%s",si.stud[i+1].name);printf(" Math English Chinese Physics Chemistry\n");scanf("%d %d %d %d %d",& si.stud[i+1].Math,& si.stud[i+1].English,& si.stud[i+1].Chinese,& si.stud[i+1].Physics,& si.stud[i+1].Chemistry);si.length=si.length+1;DoSave();}//在文件中查找学生信息,支持姓名学号查找void DoSearch(){int i=0,choice,Sid;char sname[MAX_NAME_STRLEN];int flag=0;system("cls");DoOpen();printf("\n1按姓名查找:\n2按学号查找:");scanf("%d",&choice);switch(choice){case 1: printf("请你输入要查找的姓名");scanf("%s",sname);while(i<si.length){if(strcmp(si.stud[i].name,sname)==0){flag=1;printf("学号:%d 姓名:%s 数学成绩:%d 英语成绩:%d 语文成绩:%d 物理成绩:%d 化学成绩:%d\n",si.stud[i].id,si.stud[i].name ,si.stud[i].Math,si.stud[i].English,si.stud[i].Chinese,si.stud[i].Physics,si.stud[i].Chemistry);}i++;}if(flag==0)printf("你输入的姓名不存在,请确认后再输入");break;case 2: printf("请你输入要查找的学号");scanf("%d",&Sid);while(i<si.length){if(Sid==si.stud[i].id){flag=1;printf("学号:%d 姓名:%s 数学成绩:%d 英语成绩:%d 语文成绩:%d 物理成绩:%d 化学成绩:%d\n",si.stud[i].id,si.stud[i].name ,si.stud[i].Math,si.stud[i].English,si.stud[i].Chinese,si.stud[i].Physics,si.stud[i].Chemistry);}i++;}if(flag==0)printf("你输入的学号不存在,请确认后再输入");break;}printf(" Please input a number to continue!");scanf("%d",&i);return;}//对学生信息进行修改void DoChange(){int choice1;int i=0;int onum;char choice2;system("cls");DoOpen();printf("你想对那个学生进行操作,请输入学号\n");scanf("%d",&onum);while(onum!=si.stud[i].id)i++;if(onum==si.stud[i].id){printf("\n你要修改哪一项");printf("1学号\n2姓名\n3数学成绩\n4英语成绩\n5语文成绩\n6物理成绩\n7化学成绩");printf("请选择");scanf("%d",&choice1);switch(choice1){case 1: printf("\n请输入修改后的学号");scanf("%d",&si.stud[i].id);break;case 2: printf("\n输入你要修改的姓名");scanf("%s",&si.stud[i].name);break;case 3: printf("\n请输入要修改的成绩");scanf("%d",&si.stud[i].Math);break;case 4: printf("\n请输入要修改的成绩");scanf("%d",&si.stud[i].English);break;case 5: printf("\n请输入要修改的成绩");scanf("%d",&si.stud[i].Chinese);break;case 6: printf("\n请输入要修改的成绩");scanf("%d",&si.stud[i].Physics);break;case 7: printf("\n请输入要修改的成绩");scanf("%d",&si.stud[i].Chemistry);break; }}elseprintf("没有该同学信息");printf(" Please input a number(0..9) to continue!");scanf("%d",&i);}//删除学生信息void DoDelete(){int i,id;char fname[MAX_NAME_STRLEN];system("cls");DoOpen();printf("请输入学生学号");scanf("%d",&id);i=0;while(si.stud[i].id!=id)i++;if(si.stud[i].id==id){while(i<si.length-1){si.stud[i]=si.stud[i+1];i++;}si.length=si.length-1;for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s 数学:%d 英语:%d 语文:%d 物理:%d 化学:%d \n",si.stud[i].id,si.stud[i].name,si.stud[i].Math,si.stud[i].English,si.stud[i].Chinese,si.stud[i].Physics,si.stud[i].Chemistry);}elseprintf("没有该同学信息");printf(" Please input a number(0..9) to continue!");scanf("%d",&i);}//展示学生信息void DoDisplay(){struct _studTb m;int i,j,n;system("cls");DoOpen();printf("请选择\n1.数学排名2.英语排名3.语文排名 4.物理排名 5.化学排名 6.学生总分并排序7.学生平均分并排序\n");scanf("%d",&n);if(n==1){for(j=0;j<si.length-1;j++){for(i=0;i<si.length-j-1;i++)if(si.stud[i].Math<si.stud[i+1].Math){m.stud[1]=si.stud[i];si.stud[i]=si.stud[i+1];si.stud[i+1]=m.stud[1];}}for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s 数学成绩排名:%d\n", si.stud[i].id, si.stud[i].name ,si.stud[i].Math);}else if(n==2){for(j=0;j<si.length-1;j++){for(i=0;i<si.length-j;i++)if(si.stud[i].English<si.stud[i+1].English){m.stud[1]=si.stud[i];si.stud[i]=si.stud[i+1];si.stud[i+1]=m.stud[1];}}for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s 英语成绩排名:%d\n", si.stud[i].id, si.stud[i].name ,si.stud[i].English);}else if(n==3){for(j=0;j<si.length-1;j++){for(i=0;i<si.length-j;i++)if(si.stud[i].Chinese<si.stud[i+1].Chinese){m.stud[1]=si.stud[i];si.stud[i]=si.stud[i+1];si.stud[i+1]=m.stud[1];}}for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s 语文成绩排名:%d\n", si.stud[i].id, si.stud[i].name, si.stud[i].Chinese);}else if(n==4){for(j=0;j<si.length-1;j++){for(i=0;i<si.length-j;i++)if(si.stud[i].Physics<si.stud[i+1].Physics){m.stud[1]=si.stud[i];si.stud[i]=si.stud[i+1];si.stud[i+1]=m.stud[1];}}for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s OS成绩排名:%d\n", si.stud[i].id, si.stud[i].name, si.stud[i].Physics);}else if(n==5){for(j=0;j<si.length-1;j++){for(i=0;i<si.length-j;i++)if(si.stud[i].Chemistry<si.stud[i+1].Chemistry){m.stud[1]=si.stud[i];si.stud[i]=si.stud[i+1];si.stud[i+1]=m.stud[1];}}for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s C语言成绩排名:%d\n", si.stud[i].id, si.stud[i].name,si.stud[i].Chemistry);}else if(n==6){for(i=0;i<si.length;i++)si.stud[i].sum=si.stud[i].Math+si.stud[i].English+si.stud[i].Chinese+si.stud[i].Physics+si.stud [i].Chemistry;for(j=0;j<si.length-1;j++){for(i=0;i<si.length-j;i++)if(si.stud[i].sum<si.stud[i+1].sum){m.stud[1]=si.stud[i];si.stud[i]=si.stud[i+1];si.stud[i+1]=m.stud[1];}}for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s 总分成绩排名:%f\n", si.stud[i].id, si.stud[i].name, si.stud[i].sum);}else if(n==7){for(i=0;i<si.length;i++){si.stud[i].sum=si.stud[i].Math+si.stud[i].English+si.stud[i].Chinese+si.stud[i].Physics+si.stud [i].Chemistry;si.stud[i].averScore=(float)si.stud[i].sum/si.length;}for(j=0;j<si.length-1;j++){for(i=0;i<si.length-j;i++)if(si.stud[i].averScore<si.stud[i+1].averScore){m.stud[1]=si.stud[i];si.stud[i]=si.stud[i+1];si.stud[i+1]=m.stud[1];}}for(i=0;i<si.length;i++)printf("学号:%d 姓名:%s 平均成绩排名:%f\n", si.stud[i].id, si.stud[i].name, si.stud[i].averScore);}printf(" Please input a number(0..9) to continue!");scanf("%d",&i);}//统计学生信息void Docensus(){struct _studTb sen;int mark;int sum=0;int i=0;system("cls");DoOpen();printf("请输入要统计多少分以上的学生信息");scanf("%d",&mark);while(i<si.length){ if(si.stud[i].Math>mark){sen.stud[sum]=si.stud[i];sum++;}i++;}printf("一共有:%d人\n",sum);for(i=0;i<sum;i++)printf("他的学号%4d姓名%s数学成绩%4d英语成绩%4d 语文成绩%4d 物理成绩%4d 化学成绩%4d\n ",sen.stud[i].id,sen.stud[i].name,sen.stud[i].Math,sen.stud[i].English,sen.stud[i].Chinese,sen.stud[i].Physics,sen.stud[i].Chemistry);printf(" Please input a number(0..9) to continue:");scanf("%d",&i);}void DoExit(){printf("\t\t 谢谢使用!\n");printf("\t\t");system("pause");exit(0);}。

C实现简单的学生信息管理系统控制台程序

C实现简单的学生信息管理系统控制台程序

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语言源代码

学生信息管理系统C语言源代码

#include<stdio.h>#include<malloc.h>#include<string.h>#include<stdlib.h>#define len sizeof(struct student)FILE *fp;struct student{long num;char name[15];int age;char sex[3];char chushen[10];char dizhi[20];char phone[11];char email[20];struct student *next;};void menu(){printf("===========学生信息管理系统==========\n\n");printf(" 1、录入学生信息\n");printf(" 2、浏览学生信息\n");printf(" 3、查询学生信息\n");printf(" 4、删除学生信息\n");printf(" 5、插入学生信息\n");printf(" 6、修改学生信息\n");printf(" 7、排序学生信息\n");printf(" 8、退出管理系统\n");printf("=====================================\n");}struct student *creat() //录入学生信息{int n;struct student *head;struct student *p1,*p2;n=0;p1=p2=(struct student *) malloc(len);scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p1->num,&p1->age,p1->name,p1->sex,p1->chushen ,p1->dizhi,p1->phone,p1->email);head=NULL;while(p1->num!=0){n=n+1;if(n==1) head=p1;else p2->next=p1;p2=p1;p1=(struct student *)malloc(len);scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p1->num,&p1->age,p1->name,p1->sex,p1->chu shen,p1->dizhi,p1->phone,p1->email);}p2->next=NULL;return(head);}void insert(struct student *head) //插入学生信息{int search_num;struct student *p,*q,*s;p=head;printf("在哪个学生前插入请输入学号:\n");scanf("%d",&search_num);while((p!=NULL)&&(p->num!=search_num)){q=p;p=p->next;}s=(struct student *)malloc(len);q->next=s;system("cls");printf("请输入学生信息:\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&s->num,&s->age,s->name,s->sex,s->chushen,s->diz hi,s->phone,s->email);s->next=p;}void printList(struct student *head) //浏览全部学生信息{struct student *p;p=head;if(head==NULL)printf("没有学生信息!!\n");else{do{fread(p,len,1,fp);printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->diz hi,p->phone,p->email);p=p->next;}while(p!=NULL);}}void findList_num(struct student *head,long search_num) //按学号查找{struct student *p;p=head;while((p!=NULL)&&(p->num!=search_num))p=p->next;if(p!=NULL)printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->diz hi,p->phone,p->email);elseprintf("没有该学生信息!!\n");}void findList_name(struct student *head,char *search_name) //按姓名查找{struct student *p;int cmp1=0,cmp=0;p=head;while(p!=NULL)if(strcmp(p->name,search_name)!=0){p=p->next;cmp++;}else{printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->dizhi,p->phone,p->email);p=p->next;cmp1=1;}if(cmp!=0&&cmp1==0)printf("没有该学生信息!!\n");}void xiugai(struct student *p1,long xiu_num) //修改学生信息{struct student *p2;p2=p1;while((p2!=NULL)&&(p2->num!=xiu_num))p2=p2->next;if(p2!=NULL){scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p2->num,&p2->age,p2->name,p2->sex,p2->chu shen,p2->dizhi,p2->phone,p2->email);}elseprintf("没有该学生信息!!\n");}struct student *delList(struct student *head,long del_num) // 删除学生信息{struct student *p,*q;p=head;q=head;while(p &&(p->num != del_num)){q=p;p=p->next;}if(p==NULL)printf("无此学号!\n");else{if(p == head){head = p->next;free(p);}else{q->next = p->next;free(p);}}return head;}void paixu(struct student *head) //按学号排序{struct student *p,*f,*t;char ch[100];int i;t=f=p=head;for(p=head;p->next!=NULL;p=p->next){for(t=head,f=t->next;t->next!=NULL;t=t->next,f=f->next){if(t->num>f->num>0){i=t->num;t->num=f->num;f->num=i;i=t->age;t->age=f->age;f->age=i;strcpy(ch,t->name);strcpy(t->name,f->name);strcpy(f->name,ch);strcpy(ch,t->sex);strcpy(t->sex,f->sex);strcpy(f->sex,ch);strcpy(ch,t->chushen);strcpy(t->chushen,f->chushen);strcpy(f->chushen,ch);strcpy(ch,t->dizhi);strcpy(t->dizhi,f->dizhi);strcpy(f->dizhi,ch);strcpy(ch,t->phone);strcpy(t->phone,f->phone);strcpy(f->phone,ch);strcpy(ch,t->email);strcpy(t->email,f->email);strcpy(f->email,ch);}}}// return head;}void save(struct student *head) //保存为磁盘文件{struct student *p;if((fp=fopen("keshe","w"))==NULL){printf("cannot open this file\n");exit(0);}p=head;while(p!=NULL){fprintf(fp,"%d\n",p->num);fprintf(fp,"%d\n",p->age);fprintf(fp,"%s\n",p->name);fprintf(fp,"%s\n",p->sex);fprintf(fp,"%s\n",p->chushen);fprintf(fp,"%s\n",p->dizhi);fprintf(fp,"%s\n",p->phone);fprintf(fp,"%s\n",p->email);p=p->next;}fclose(fp);}struct student *read() //从磁盘读取文件{struct student *head=NULL;struct student *p=NULL;struct student *t=NULL;int a;// fp=fopen("keshe","r");if((fp=fopen("keshe","r"))==NULL){printf("cannot open this file\n");exit(0);}while(1){t=(struct student *)malloc(len);a=fscanf(fp,"%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&t->num,&t->age,t->name,t->sex,t->chush en,t->dizhi,t->phone,t->email);if(a==0||a==-1)return head;t->next=NULL;if(p==NULL){p=t;head=t;}else{p->next=t;p=p->next;p->next=NULL;}}fclose(fp);}void main(){int code=0;struct student *pt = NULL;while(code!=8){menu();printf("请输入上述序号进行操作:\n");scanf("%d",&code);system("cls");switch(code){case 1:{system("cls");printf("每个学生的信息之间用Tab键分隔\n");printf("===========================录入学生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");pt=creat();save(pt);system("cls");printf("===========================录入学生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("************录入学生信息成功***********!!\n");printf("按回车键返回主菜单\n");getchar();getchar();system("cls");};break;case 2:{system("cls");printf("===========================学生信息表================================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");pt=read();printList(pt);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("\n按回车键返回主菜单\n");getchar();getchar();system("cls");};break;case 3:{int search=0;system("cls");printf("===========================查询学生信息==============================\n");printf("---------------------------------------------------------------------\n");while(search!=3){printf("1、按学号查询\n2、按姓名查询\n3、退出查询\n");scanf("%d",&search);switch(search){case 1:{long search_num;system("cls");printf("请输入学生学号\n");scanf("%d",&search_num);system("cls");printf("===========================查询结果==================================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");findList_num(read(),search_num);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("\n按回车键返回查询菜单\n");getchar();getchar();system("cls");};break;case 2:{char search_name[15];system("cls");printf("请输入学生姓名\n");scanf("%s",search_name);system("cls");printf("===========================查询结果==================================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");findList_name(read(),search_name);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("\n按回车键返回查询菜单\n");getchar();getchar();system("cls");};}}system("cls");};break;case 4:{long del_num;system("cls");printf("===========================删除学生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("请输入要删除学生信息的学号:\n");scanf("%d",&del_num);system("cls");pt=delList(read(),del_num);save(pt);printf("===========================删除结果================================\n");printf("-------------------------------------------------------------------\n");printf("学号为%d的学生信息成功删除\n",del_num);printf("\n按回车键返回主菜单\n");getchar();getchar();system("cls");};break;case 5:{system("cls");printf("每个学生的信息之间用Tab键分隔\n");printf("===========================插入学生信息==============================\n");printf("---------------------------------------------------------------------\n");insert(pt);save(pt);system("cls");printf("===========================插入学生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("****插入学生信息成功***!!\n\n");printf("按回车键返回主菜单\n");getchar();getchar();system("cls");}break;case 6:{long search_num;system("cls");printf("请输入要修改的学生学号:\n");scanf("%d",&search_num);system("cls");printf("每个学生的信息之间用Tab键分隔\n");printf("===========================修改学生信息==================================\n");printf("-------------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");findList_num(read(),search_num);printf("\n");printf("请输入修改信息:\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");pt=read();xiugai(pt,search_num);save(pt);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("****修改学生信息成功***!!\n\n");printf("\n按回车键返回查询菜单\n");getchar();getchar();system("cls");};break;case 7:{system("cls");printf(" 按学号从小到大排序\n\n");printf("===========================学生信息表================================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");pt=read();paixu(pt);printList(pt);save(pt);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("\n按回车键返回主菜单\n");getchar();getchar();system("cls");};break;case 8:read();break;}}}。

学生信息管理系统(C语言版)源代码

学生信息管理系统(C语言版)源代码

#include "stdio.h"#include "stdlib.h"#include "string.h"int shoudsave=0; /* */ struct student{char num[10];/* 学号*/ char name[20];char sex[4];int age;int cgrade;int mgrade;int egrade;int totle;int ave;char xueyuan[30];char banji[20];char ID[30];char phone[20];char address[50];char neartime[10];/* 最近更新时间*/};typedef struct node{struct student data;struct node *next;}Node,*Link;void login()/*登录函数*/{char logname[30];printf("请输入用户名和密码:\n用户名:");scanf("%c",logname);}void menu(){printf("***********************请按照提示操作,否则可能出现错误*************************"); printf("********************************************************************************");printf("\t1登记学生资料\t\t2删除学生资料\t\t7统计学生资料\n");printf("\t3查询学生资料\t\t4修改学生资料\t\t8排序\n");printf("\t5保存学生资料\t\t6输出学生资料\t\t0结束\n");printf("********************************************************************************\n");}void printstart(){printf("-----------------------------------------------------------------------\n");}void Wrong(){printf("\n=====>提示:输入错误!\n");}void Nofind(){printf("\n=====>提示:没有找到该学生!\n");}void printc() /* 本函数用于输出中文*/{printf(" 学号\t 姓名性别年龄英语成绩数学成绩C语言成绩总分平均分学院班级身份证电话住址\n");}void printe(Node *p)/* 本函数用于输出英文*/{printf("%-12s%-8s%-6s%-6d%-6d%-6d%-6d%-6d%-8d%-20s%-15s%-20 s%-15s%-20s\n",p->data.num,p->,p->data.sex,p->data.age,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave,p ->data.xueyuan,p->data.banji,p->data.ID,p->data.phone,p->data.address);}Node* Locate(Link l,char findmess[],char nameornum[]) /* 该函数用于定位链表中符合要求的接点,幵返回该指针*/{Node *r;if(strcmp(nameornum,"num")==0) /* 按学号查询*/{r=l->next;while(r!=NULL){if(strcmp(r->data.num,findmess)==0)return r;r=r->next;}}else if(strcmp(nameornum,"name")==0) /* 按姓名查询*/ {r=l->next;while(r!=NULL){if(strcmp(r->,findmess)==0)return r;r=r->next;}}return 0;}void Add(Link l) /* 增加学生*/{Node *p,*r,*s;char num[10];r=l;s=l->next;while(r->next!=NULL)r=r->next; /* 将指针置于最末尾*/while(1){printf("请你输入学号(以'0'返回上一级菜单:)");scanf("%s",num);if(strcmp(num,"0")==0)break;while(s){if(strcmp(s->data.num,num)==0){printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num);printstart();printc();printe(s);printstart();printf("\n");return;}s=s->next;}p=(Node *)malloc(sizeof(Node)); strcpy(p->data.num,num); printf("请你输入姓名:");scanf("%s",p->); getchar();printf("请你输入性别:");scanf("%s",p->data.sex); getchar();printf("请你输入年龄:");scanf("%d",&p->data.age); getchar();printf("请你输入c语言成绩:");scanf("%d",&p->data.cgrade); getchar();printf("请你输入数学成绩:"); scanf("%d",&p->data.mgrade); getchar();printf("请你输入英语成绩:"); scanf("%d",&p->data.egrade); getchar();printf("请你输入学院名:");scanf("%s",&p->data.xueyuan); getchar();printf("请你输入班级:");scanf("%s",&p->data.banji); getchar();printf("请你输入身份证:");scanf("%s",&p->data.ID); getchar();printf("请你输入电话:");scanf("%s",&p->data.phone); getchar();printf("请你输入家庭住址:");scanf("%s",&p->data.address);getchar();p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade; p->data.ave=p->data.totle / 3;/* 信息输入已经完成*/p->next=NULL;r->next=p;r=p;shoudsave=1;}}void Qur(Link l) /* 查询学生*/{int sel;char findmess[20];Node *p;if(!l->next)printf("\n=====>提示:没有资料可以查询!\n");return;}printf("\n=====>1按学号查找\n=====>2按姓名查找\n"); scanf("%d",&sel);if(sel==1)/* 学号*/{printf("请你输入要查找的学号:");scanf("%s",findmess);p=Locate(l,findmess,"num");if(p){printf("\t\t\t\t查找结果\n");printstart();printc();printe(p);printstart();}elseNofind();}else if(sel==2) /* 姓名*/{printf("请你输入要查找的姓名:"); scanf("%s",findmess);p=Locate(l,findmess,"name");if(p){printf("\t\t\t\t查找结果\n"); printstart();printc();printe(p);printstart();}elseNofind();}elseWrong();}void Del(Link l) /* 删除*/{int sel;Node *p,*r;char findmess[20];if(!l->next){printf("\n=====>提示:没有资料可以删除!\n");return;}printf("\n=====>1按学号删除\n=====>2按姓名删除\n"); scanf("%d",&sel);if(sel==1){printf("请你输入要删除的学号:");scanf("%s",findmess);p=Locate(l,findmess,"num");if(p){r=l;while(r->next!=p)r=r->next;r->next=p->next;free(p);printf("\n=====>提示:该学生已经成功删除!\n"); shoudsave=1;}elseNofind();}else if(sel==2){printf("请你输入要删除的姓名:");scanf("%s",findmess);p=Locate(l,findmess,"name");if(p)r=l;while(r->next!=p)r=r->next;r->next=p->next;free(p);printf("\n=====>提示:该学生已经成功删除!\n"); shoudsave=1;}elseNofind();}elseWrong();}void Modify(Link l){Node *p;char findmess[20];if(!l->next){printf("\n=====>提示:没有资料可以修改!\n"); return;}printf("请你输入要修改的学生学号:");scanf("%s",findmess);p=Locate(l,findmess,"num");if(p){printf("请你输入新学号(原来是%s):",p->data.num); scanf("%s",p->data.num);getchar();printf("请你输入新姓名(原来是%s):",p->); scanf("%s",p->);getchar();printf("请你输入新性别(原来是%s):",p->data.sex); scanf("%s",p->data.sex);printf("请你输入新年龄(原来是%d):",p->data.age);scanf("%d",&p->data.age);getchar();printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade); scanf("%d",&p->data.cgrade);getchar();printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade); scanf("%d",&p->data.mgrade);getchar();printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade); scanf("%d",&p->data.egrade);getchar();printf("请你输入新学院名(原来是%s):",p->data.xueyuan);scanf("%s",p->data.xueyuan);getchar();printf("请你输入新班级(原来是%s):",p->data.banji);scanf("%s",p->data.banji);getchar();printf("请你输入新身份证(原来是%s):",p->data.ID);scanf("%s",p->data.ID);getchar();printf("请你输入新电话(原来是%s):",p->data.phone);scanf("%s",p->data.phone);getchar();printf("请你输入新家庭住址(原来是%s):",p->data.address);scanf("%s",p->data.address);getchar();p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade; p->data.ave=p->data.totle/3;printf("\n=====>提示:资料修改成功,注意保存!\n");shoudsave=1;}elseNofind();}void Disp(Link l){int count=0;Node *p;p=l->next;if(!p){printf("\n=====>提示:没有资料可以显示!\n"); return;}printf("\t\t\t\t显示结果\n");printstart();printc();printf("\n");while(p){printe(p);p=p->next;}printstart();printf("\n");}void Tongji(Link l){Node *pm,*pe,*pc,*pt,*pa; /* 用于指向分数最高的接点*/ Node *r=l->next;if(!r){printf("\n=====>提示:没有资料可以统计!\n");return ;}pm=pe=pc=pt=pa=r;while(r!=NULL){if(r->data.cgrade>=pc->data.cgrade)pc=r;if(r->data.mgrade>=pm->data.mgrade)pm=r;if(r->data.egrade>=pe->data.egrade)pe=r;if(r->data.totle>=pt->data.totle)pt=r;if(r->data.ave>=pa->data.ave)pa=r;r=r->next;}printf("------------------------------统计结果--------------------------------\n");printf("总分最高者:\t%s %d分\n",pt->,pt->data.totle);printf("平均分最高者:\t%s %d分\n",pa->,pa->data.ave);printf("英语最高者:\t%s %d分\n",pe->,pe->data.egrade);printf("数学最高者:\t%s %d分\n",pm->,pm->data.mgrade);printf("c语言最高者:\t%s %d分\n",pc->,pc->data.cgrade); printstart();}void Sort(Link l){Link ll;Node *p,*rr,*s;int sortoption;ll=(Link)malloc(sizeof(Node)); /* 用于做新的连表*/ll->next=NULL;if(l->next==NULL){printf("\n=====>提示:没有资料可以排序!\n");return ;}p=l->next;printstart();printf ("\t0按学号排序\t\t1按成绩排序");printstart();scanf("%d",&sortoption);if(sortoption==1)while(p){ s=(Node*)malloc(sizeof(Node)); /* 新建接点用于保存信息*/ s->data=p->data;s->next=NULL;rr=ll;while(rr->next!=NULL && rr->next->data.totle>=p->data.totle)rr=rr->next;if(rr->next==NULL)rr->next=s;else{s->next=rr->next;rr->next=s;}p=p->next;}else while(p){ s=(Node*)malloc(sizeof(Node)); /* 新建接点用于保存信息*/s->data=p->data;s->next=NULL;rr=ll;while(rr->next!=NULL && (strcmp(rr->next->data.num,p->data.num))<=0) rr=rr->next;if(rr->next==NULL)rr->next=s;else{s->next=rr->next;rr->next=s;}p=p->next;}free(l);l->next=ll->next;printf("\n=====>提示:排序已经完成!\n"); }void Save(Link l){FILE* fp;Node *p;int flag=1,count=0;fp=fopen("e:\\student","wb");if(fp==NULL){printf("\n=====>提示:重新打开文件时发生错误!\n"); exit(1);}p=l->next;while(p){if(fwrite(p,sizeof(Node),1,fp)==1){p=p->next;count++;}else{flag=0;break;}}if(flag){printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count);shoudsave=0;}fclose(fp);}void main(){Link l;/* 连表*/FILE *fp; /* 文件指针*/int sel;char ch;char jian;int count=0;Node *p,*r;printf("\t\t\t\t学生成绩管理系统\n\t\t\t青岛理工大学计算机工程学院计算091\n\t\t\t 梁德智200907030\n");l=(Node*)malloc(sizeof(Node));l->next=NULL;r=l;fp=fopen("e:\\student","rb");if(fp==NULL){printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n");scanf("%c",&jian);if(jian=='y'||jian=='Y')fp=fopen("e:\\student","wb");elseexit(0);}printf("\n=====>提示:文件已经打开,正在导入记录,关闭后打开可执行文件\n");while(!feof(fp)){p=(Node*)malloc(sizeof(Node));if(fread(p,sizeof(Node),1,fp)) /* 将文件的内容放入接点中*/{p->next=NULL;r->next=p;r=p; /* 将该接点挂入连中*/count++;}}fclose(fp); /* 关闭文件*/printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count);while(1){menu();printf("请你选择操作:");scanf("%d",&sel);if(sel==0){if(shoudsave==1){ getchar();printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n"); scanf("%c",&ch);if(ch=='y'||ch=='Y')Save(l);}printf("\n=====>提示:你已经退出系统,再见!\n"); break;}switch(sel){case 1:Add(l);break; /* 增加学生*/case 2:Del(l);break;/* 删除学生*/case 3:Qur(l);break;/* 查询学生*/case 4:Modify(l);break;/* 修改学生*/case 5:Save(l);break;/* 保存学生*/case 6:Disp(l);break;case 7:Tongji(l);break;case 8:Sort(l);break;default: Wrong();getchar();break;}}}。

c语言-学生信息管理系统(完整版)

c语言-学生信息管理系统(完整版)
return 1;
}
count=fwrite(stu,sizeof(Student),current,fs);
fclose(fs);
if(count!=current)
{
printf("保存失败\n");
return 1;
case'4':delete();break;
case'5':list();break;
case'6':save();break;
case'7':load();break;
case'0':if(stu!=NULL)
#include<string.h>
#include<malloc.h>
#include"Student.h"
#include"function.h"
Student*stu=NULL;
int current=0;
int total=0;
int main()
{
char choice;
printf("地址:%s\n",stu[i].address);
return 0;
}
}
printf("该学生不存在\n");
return 1;
}
int update()
{
char name[40];
printf(" 7.加载学生信息\n");
printf(" 0.退出程序\n");

学生管理系统 C语言代码

学生管理系统 C语言代码

#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语言代码

学生信息管理系统c语言代码

学生信息管理系统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语言)

学生信息管理系统(C语言)

学⽣信息管理系统(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;}。

C语言版-学生信息管理系统

C语言版-学生信息管理系统
if(head==NULL){printf("当前为空");goto end;}/*没有列表*/
p1=head;
while(num!=p1->num&&p1->next!=NULL)/*p1不是要找的结点,并且后面还有结点*/
{p2=p1;p1=p1->next;}/*p1后移一个结点,p2的next指向了原来的P1*/
scanf("%d",&q);
return q;
}
struct stu *cr(struct stu *head,struct stu *stud) /*插入函数*/
{
struct stu *p0,*p1,*p2;
p1=head;/*让P1指向第一个结点*/
p0=stud;/*P0指向要插入的结点*/
p2=p1;/*P2成为了P1,现在的P2也就相当于刚才的首结点的next*/
p1=(struct stu *)malloc(sizeof(struct stu));/*给P1继续开辟新的内存单元*/
scanf("%ld,%s,%c,%f",&p1->num,&p1->name,&p1->sex,&p1->cj);/*继续输入剩余的学生信息,直到p1->num=0结束*/
while(p1->num!=0)
{
n=n+1; /*结点个数加1*/
if(n==1)head=p1;/*如果只有一个结点,那么首结点就是p1*/
else
p2->next=p1;/*否则P2成了首结点P2的next就成了p1*/

C语言学生信息管理系统(完整版)

C语言学生信息管理系统(完整版)

#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 <stdlib.h>#include <math.h>#include <string.h>#include<windows.h>struct student //存储学生信息的结构体{char name[10];int num;char sex[5];char subject[10];int score;}stud[10];int a[10],b[10],c[10],d[10],m,stustuSIZE,searchscore; //a[],b[]为辅助数组struct student HS[60],HS1[60]; //HS1[60]为溢出表struct tree //树的结构体{struct tree *left;int data;struct tree *right;};typedef struct tree treenode;typedef treenode *btree;struct s_node //栈的结构体{btree date;struct s_node *next;};typedef struct s_node s_list;typedef s_list *link;btree f,root,q;link S;link creat(link stack) //创建空栈的函数{stack=(link)malloc(sizeof(s_list));if (!stack){printf("\nERROR");return NULL;}return stack;}link push(link stack,btree value) //添加新的元素value为stack的栈顶元素{link newnode;newnode=(link)malloc(sizeof(s_list));if (!newnode){printf("\nERROR");return NULL;}newnode->date=value;newnode->next=stack;stack=newnode;return stack;}link pop(link stack) //栈顶出栈的函数,c表示出栈的栈顶元素{link top;if (stack!=NULL){top=stack;stack=stack->next;f=top->date;free(top);q=stack->date;return stack;}elsef=NULL;}btree insert(btree root,int node) //插入树中间的节点{btree newnode;btree curnode;btree parnode;newnode=(btree)malloc(sizeof(struct tree));newnode->data=node;newnode->left=NULL;newnode->right=NULL;if (root==NULL) //根节点,直接返回return newnode;else{curnode=root;while (curnode!=NULL){parnode=curnode;if (curnode->data>node)curnode=curnode->left;elsecurnode=curnode->right;}if (parnode->data>node)parnode->left=newnode;elseparnode->right=newnode;}return root;}btree treecreat(int len) //创建树的函数{btree root=NULL;int i;for (i=0;i<len;i++)root=insert(root,d[i]);return root;}void trav(btree p) //遍历树的函数{int i;int j=0;S=push(S,p);q=S->date;do{while (S->date!=0){S=push(S,q->left);q=q->left;}S=pop(S);if (1){S=pop(S);if (f->data==searchscore){for (i=0;i<=stustuSIZE;i++){if (stud[i].score==searchscore){printf("姓名:%s 学号:%d 性别:%s 科目:%s 成绩:%d\n",stud[i].name,stud[i].num,stud[i].sex,stud[i].subject,stud[i].score);return;}}}printf("%d",f->data);j++;S=push(S,f->right);q=S->date;}}while (j<stustuSIZE-1);}void sort() //采用冒泡排序的方法对学号进行排序{int i,j,t,m;for (i=0;i<=stustuSIZE;i++){if (stud[i].num!=0)a[i]=stud[i].num;}m=i-1;for (j=0;j<m;j++)for (i=0;i<m-j;i++)if (a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;} //a[0]到a[m]排序完毕}int Bsearch(int searchnum) //通过折半查找,查找学生学号{int low,high,mid;int i,j;for (i=0,j=1;i<=stustuSIZE;i++,j++)c[j]=a[i];low=1;high=j-1;while (low<=high){mid=floor((low+high)/2);if (c[mid]==searchnum)return mid;else if (searchnum<c[mid])high=mid-1;elselow=mid+1;}return 0;}void Hash() //建立HS表的函数{int k,i;for (i=0;i<=stustuSIZE;i++){if (stud[i].num!=0) //学号为0表示已经删除{k=(stud[i].name[0]-96)+(stud[i].name[1]-96); //HS函数if (HS[k].name==0){strcpy(HS[k].name,stud[i].name);HS[k].num=stud[i].num;strcpy(HS[k].sex,stud[i].sex);strcpy(HS[k].subject,stud[i].subject);HS[k].score=stud[i].score;}else{strcpy(HS[k].name,stud[i].name); //用HS1[]当作溢出表,处理冲突HS[k].num=stud[i].num;strcpy(HS[k].sex,stud[i].sex);strcpy(HS[k].subject,stud[i].subject);HS[k].score=stud[i].score;}}}}int maxscore() //搜索分数最高的学生,返回值为其在结构体数组中的序号{int i=0,n,j;n=b[i]; //m记录当前的最高分数j=i; //j记录最高分数项的序号for (i=1; i<=stustuSIZE; i++){if (n<b[i]){n=b[i];j=i;}}b[j]=0; //找到分数最高项后,将最高分数项的分数置0,以便不影响下次的寻找return j;}int main(){int serve,i,u,v,w,t=0,n,r;int flag=0; //flag记录学生信息是否已经输入过int flag1=0;int search,searchnum,j;char namesearch[10];while (flag!=2){printf("-----------------------------学生信息管理系统--------------------------------\n\n\n");printf(" 表单排序选项\n\n");printf(" 【1】学生信息输入\n");printf(" 【2】学生信息浏览\n");printf(" 【3】学生信息查询\n");printf(" 【4】学生成绩区间段查询和统计\n");printf(" 【5】学生成绩排序\n");printf(" 【6】学生信息修改\n");printf(" 【7】学生信息增加\n");printf(" 【8】学生信息删除\n");printf(" 【9】结束\n");printf("-------------------------------------------------------------------------\n\n");printf(" 请选择您要进入的功能: ");scanf("%d",&serve);switch (serve){case 1:{system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");printf(" 请输入学生的个数:");scanf("%d",&i);stustuSIZE=i-1;printf("请按姓名,学号,性别(m||w),选课科目,成绩的顺序输入信息,以空格隔开\n");for (i=0;i<=stustuSIZE;i++){scanf("%s%d%s%s%d",stud[i].name,&stud[i].num,stud[i].sex,stud[i].subject,&stud[i].score);if(stud[i].score<0||stud[i].score>100||stud[i].sex[0]!='m'&&stud[i].sex[0]!='w'){printf("输入数据不合法!请重新输入.\n");scanf("%s%d%s%s%d",stud[i].name,&stud[i].num,stud[i].sex,stud[i].subject,&stud[i].score);}};flag=1;system("cls");break;}case 2:{if (flag==0){printf("还没有输入信息,无法浏览\n");break;}system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");for (i=0;i<=stustuSIZE;i++){if (stud[i].num!=0) //学号为0表示该生信息已经被删除printf(" 姓名:%s 学号:%d 性别:%s 科目:%s 成绩:%d\n",stud[i].name,stud[i].num,stud[i].sex,stud[i].subject,stud[i].score);}system("pause");system("cls");break;}case 3:{while (flag==0){printf("还没有输入信息,无法浏览\n");break;}system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");printf("请输入查询信息的方式:\n");printf(" 【1】按学号查询\n");printf(" 【2】按姓名查询\n");printf(" 【3】按成绩查询\n");printf(" ");scanf("%d",&search);if (search==1){printf(" 请输入学生的学号:");scanf("%d",&searchnum);sort();j=Bsearch(searchnum);for (i=0;i<=stustuSIZE;i++){if (stud[i].num==c[j])break;}printf("该生信息如下:\n");printf("姓名:%s 学号:%d 性别:%s 科目:%s 成绩:%d\n",stud[i].name,stud[i].num,stud[i].sex,stud[i].subject,stud[i].score);system("pause");system("cls");break;}else if (search==2){Hash();printf(" 请输入学生的姓名:\n");scanf("%s",namesearch);r=(namesearch[0]-96)+(namesearch[1]-96);if (strcmp(namesearch,HS[r].name)==0){printf(" 该生信息如下:\n");printf(" 姓名:%s 学号:%d 性别:%s 科目:%s 成绩:%d\n",HS[r].name,HS[r].num,HS[r].sex,HS[r].subject,HS[r].score);system("pause");system("cls");break;}else if (strcmp(namesearch,HS1[r].name)==0){printf("该生信息如下:\n");printf("姓名:%s 学号:%d 性别:%s 科目:%s 成绩:%d\n",HS1[r].name,HS1[r].num,HS1[r].sex,HS1[r].subject,HS1[r].score);system("pause");system("cls");break;}else{printf("找不到该生信息!\n");system("pause");system("cls");break;}}else{for (i=0;i<=stustuSIZE;i++){if (stud[i].num!=0)d[i]=stud[i].score;}printf("请输入要查询的成绩:\n");scanf("%d",&searchscore);S=creat(S);S->date=NULL;root=treecreat(i);trav(root);system("pause");system("cls");break;}}case 4:{while (flag==0){printf("还没有输入信息,无法浏览\n");break;}system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");printf(" 请输入要统计区间的下限:");scanf("%d",&m);printf(" 请输入要统计区间的上限:");scanf("%d",&n);for (i=0;i<=stustuSIZE;i++){if ((stud[i].score>=m)&&(stud[i].score<=n)){printf(" 姓名:%s 学号:%d 性别:%s 科目:%s 成绩:%d\n",stud[i].name,stud[i].num,stud[i].sex,stud[i].subject,stud[i].score);t++;}}printf("该区间段学生的个数为%d\n",t);system("pause");system("cls");break;}case 5:{while (flag==0){printf("还没有输入信息,无法浏览\n");break;}system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");for (i=0;i<=stustuSIZE;i++){if (stud[i].num!=0)b[i]=stud[i].score;}for (i=0; i<=stustuSIZE; i++){u=maxscore();printf("姓名:%s 分数:%d\n",stud[u].name,stud[u].score);}system("pause");system("cls");break;}case 6:{while (flag==0){printf("还没有输入信息,无法浏览\n");break;}system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");printf(" 请输入要修改信息的学生的学号:");scanf("%d",&v);for (i=0;i<=stustuSIZE;i++){if (flag1==2)break;while (stud[i].num==v){printf(" 该生当前信息如下:\n");printf(" 姓名:%s 学号:%d 性别:%s 科目:%s 成绩:%d\n",stud[i].name,stud[i].num,stud[i].sex,stud[i].subject,stud[i].score);printf("请按姓名,学号,性别(m||w),选课科目,成绩的顺序输入新的信息:\n");scanf("%s%d%s%s%d",stud[i].name,&stud[i].num,stud[i].sex,stud[i].subject,&stud[i].score);flag1=2;break;}}system("pause");system("cls");break;}case 7:{while (flag==0){printf("还没有输入信息,无法浏览\n");break;}system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");i=stustuSIZE+1;printf(" 请输入该生的信息:\n");scanf("%s%d%s%s%d",stud[i].name,&stud[i].num,stud[i].sex,stud[i].subject,&stud[i].score);stustuSIZE++;system("pause");system("cls");break;}case 8:{while (flag==0){printf("还没有输入信息,无法浏览\n");break;}system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");printf(" 请输入要删除信息的学生的学号:");scanf("%d",&w);for (i=0; i<=stustuSIZE; i++){if (stud[i].num==w)stud[i].num=0; //学号置0表示该项被删除}system("pause");system("cls");break;}case 9:{flag=2;break;}default:{printf("输入数字错误!\n");system("pause");system("cls");break;}}}system("cls");printf("-----------------------------学生信息管理系统-------------------------------\n\n\n");printf("\n\n\n\n 谢谢使用!\n\n\n\n\n"); }。

学生信息管理系统 C语言

学生信息管理系统 C语言

/*********************************************************************** *************************学生信息管理系统(2)************************** *修复了在没有学生记录的情况下查看、排序和查询部分仍然显示出子菜单的问题* ************************************************************************/ #include <stdio.h>#include <string.h>#include <stdlib.h>#define N 50 //学生记录最大数量struct student //学生记录结构体定义{int ID;//学号char name[20];//姓名char sex[2];//性别int score[3];//三门课的成绩(高数,英语,专业课)int sum;//三门课的成绩和float average;//三门课的平均成绩};/*********************************************************************** ****************************进行函数声明******************************** ************************************************************************/ void Menu_select(); //显示主菜单void Inputstu(struct student stu[], int * stu_number); //录入学生信息void Browsestu(struct student stu[], int * stu_number); //查看学生信息void Sortstu(struct student stu[], int * stu_number); //排序学生信息void Searchstu(struct student stu[], int * stu_number); //查找学生信息void Deletestu(struct student stu[], int * stu_number); //删除学生信息void Modifystu(struct student stu[], int * stu_number); //修改学生信息void Countscore(struct student stu[], int * stu_number); //统计学生信息/*********************************************************************** ******************开始定义各个功能模块的函数**************************** ************************************************************************/ void Menu_seclect()//菜单选择函数部分{system("cls");system("title 主菜单");printf("\n\n");printf("\t\t|-----------------------------------|\n");printf("\t\t| 学生信息管理系统|\n");printf("\t\t|-----------------------------------|\n");printf("\t\t| 1---录入学生记录|\n");printf("\t\t| 2---查看学生记录|\n");printf("\t\t| 3---查询学生记录|\n");printf("\t\t| 4---排序学生记录|\n");printf("\t\t| 5---删除学生记录|\n");printf("\t\t| 6---修改学生记录|\n");printf("\t\t| 7---统计学生记录|\n");printf("\t\t| 0---【退出系统】|\n");printf("\t\t|-----------------------------------|\n");}void Inputstu(struct student stu[], int * stu_number)//1.增加学生记录函数部分{char ch = 'y';int i, count = 0;system("title 增加学生记录");while ((ch == 'y') || (ch == 'Y')){system("cls");printf("\n\t\t--------------------增加学生记录------------------\n");printf("\n\n\t\t 请输入学生信息\n");printf("\n\t\t 学号:");scanf("%d", &stu[count].ID);for (i = 0; i < *stu_number; i++)if (stu[count].ID == stu[i].ID){printf("\n\t\t 该学号已使用,请重输:\n");printf("\n\t\t 学号:");scanf("%d", &stu[count].ID);}printf("\n\t\t 姓名:");scanf("%s", &stu[count].name);printf("\n\t\t 性别:");scanf("\n%s", &stu[count].sex);printf("\n\t\t 数学成绩:");scanf("%3d", &stu[count].score[0]);printf("\n\t\t 英语成绩:");scanf("%3d", &stu[count].score[1]);printf("\n\t\t 专业成绩:");scanf("%3d", &stu[count].score[2]);stu[count].sum = stu[count].score[0] + stu[count].score[1] + stu[count].score[2];stu[count].average = (float)stu[count].sum / 3.0;printf("\n\n\t\t 是否输入下一个学生信息?(y/n)");scanf("\n%c", &ch);count++;}*stu_number = *stu_number + count;return;}void Browsestu(struct student stu[], int * stu_number)//2.浏览学生记录函数部分{int i, j, choose;struct student temp_stu[N], st;system("title 浏览学生记录");while (1){system("cls");printf("\n");printf("\t|---------------------------------------------------------------|\n");printf("\t| 浏览学生记录子菜单|\n");printf("\t|---------------------------------------------------------------|\n");printf("\t| 1---按学号顺序浏览|\n");printf("\t| 2---按名次顺序浏览|\n");printf("\t| 0---返回主菜单|\n");printf("\t|---------------------------------------------------------------|\n");printf("\t 请选择浏览方式:");scanf("%d", &choose);switch (choose){case 1:if(* stu_number==0){ printf("\t\t对不起,无可用的学生纪录!\n");getch();return;}else{system("cls");printf("\n\n\t 按学号升序浏览如下:\n");printf("\n\t 学号\t 姓名\t 性别\t数学\t英语\t专业\t总分\t平均分\n\n");for (i = 0; i < *stu_number; i++){printf("\t %d\t %s\t %s\t %d\t %d\t %d\t %d\t %.2f\n\n", stu[i].ID, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].sum, stu[i].average);}printf("\n\t\t 浏览完毕,按任意键返回子菜单!");getch();break;}case 2:if(* stu_number==0){ printf("\t\t对不起,无可用的学生纪录!\n");getch();return;}else{for (i = 0; i < *stu_number; i++){temp_stu[i] = stu[i];}for (i = 1; i < *stu_number; i++)for (j = 1; j <= *stu_number - i; j++)if (temp_stu[j - 1].sum < temp_stu[j].sum){st = temp_stu[j - 1];temp_stu[j - 1] = temp_stu[j];temp_stu[j] = st;}system("cls");printf("\n\n\t 按名次升序浏览如下:\n");printf("\n\t名次\t学号\t姓名\t性别\t数学\t英语\t专业\t总分\t平均分\n");for (i = 0; i < *stu_number; i++){printf("\t %d\t%d\t%s\t %s\t %d\t %d\t %d\t %d\t %.2f\n\n", i + 1, temp_stu[i].ID, temp_stu[i].name, temp_stu[i].sex, temp_stu[i].score[0], temp_stu[i].score[1], temp_stu[i].score[2], temp_stu[i].sum, temp_stu[i].average);}printf("\n\t\t 浏览完毕,按任意键返回子菜单!");getch();break;}case 0:return;}}return;}void Sortstu(struct student stu[], int * stu_number)//3.排序学生成绩记录函数部分{int i, j;struct student st;system("title 排序学生记录");if(* stu_number==0){ printf("\t\t对不起,无可用的学生纪录!\n");getch();return;}else{for (i = 1; i < *stu_number; i++)for (j = 1; j <= *stu_number - i; j++)if (stu[j - 1].ID > stu[j].ID){st = stu[j - 1];stu[j - 1] = stu[j];stu[j] = st;}system("cls");printf("\n\n\t\t********************排序学生记录********************\n");printf("\n\n\t 按学号升序排序后的学生记录如下:\n");printf("\n\t 学号\t姓名\t性别\t数学\t英语\t专业\t总分\t平均分\n\n");for (i = 0; i < *stu_number; i++){printf("\t %d\t%s\t %s\t %d\t %d\t %d\t %d\t %.2f\n\n", stu[i].ID, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].sum, stu[i].average);}printf("\n\t\t 排序完毕,按任意键返回主菜单!");getch();return;}}void Searchstu(struct student stu[], int * stu_number)//4.查询学生记录函数部分{int xh,i, num, choose, find;char xm[20];system("title 查询学生记录");while (1){system("cls");printf("\n");printf("\t|---------------------------------------------------------------|\n");printf("\t| 查询学生记录子菜单|\n");printf("\t|---------------------------------------------------------------|\n");printf("\t| 1---按学号查询|\n");printf("\t| 2---按姓名查询|\n");printf("\t| 0---返回主菜单|\n");printf("\t|---------------------------------------------------------------|\n");printf("\t 请选择查询方式:");scanf("%d", &choose);switch (choose){case 1:if(* stu_number==0){printf("\t\t对不起,无可用的学生纪录!\n");getch();return;}else{printf("\n\t 请输入要查询的学生学号:");scanf("%d", &xh);for (i = 0; i < *stu_number; i++)if (stu[i].ID == xh){printf("\n\t 要查询的学生信息如下:\n");printf("\n\t 学号\t 姓名\t 性别\t数学\t英语\t专业\t总分\t平均分\n\n");printf("\t %d\t %s\t %s\t %d\t %d\t %d\t %d\t %.2f\n\n", stu[i].ID, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].sum, stu[i].average);printf("\n\t 显示完毕,按任意键返回子菜单!");getch();break;}if (i == *stu_number){printf("\n\t 要查询的学生不存在!按任意键返回子菜单!");getch();}break;}case 2:if(* stu_number==0){printf("\t\t对不起,无可用的学生纪录!\n");getch();return;}else{printf("\n\t 请输入要查询的学生姓名:");scanf("%s", xm);find = 0;num = 0;for (i = 0; i < *stu_number; i++){if (strcmp(stu[i].name, xm) == 0){find = 1;num++;if (num == 1){printf("\n\t 要查询的学生信息如下:\n");printf("\n\t 学号\t 姓名\t 性别\t数学\t英语\t专业\t总分\t 平均分\n\n");}printf("\t %d\t %s\t %s\t %d\t %d\t %d\t %d\t %.2f\n\n", stu[i].ID, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].sum, stu[i].average);}}if (find){printf("\n\t 显示完毕,按任意键返回子菜单!");getch();}else{printf("\n\t 要查询的学生不存在!按任意键返回子菜单!");getch();}break;}case 0:return;}}return;}void Deletestu(struct student stu[], int * stu_number)//删除学生记录函数部分{int i, j,xh;char ch = 'y';system("title 删除学生记录");while ((ch == 'y') || (ch == 'Y')){system("cls");printf("\n\t\t------------------------删除学生记录------------------------\n\n");printf("\t\t 请输入要删除的学生学号:");scanf("%d", &xh);for (i = 0; i < *stu_number; i++){if (stu[i].ID == xh){printf("\n\t 要删除的学生信息如下:\n");printf("\n\t 学号\t 姓名\t 性别\t数学\t英语\t专业\t总分\t平均分\n\n");printf("\t %d\t %s\t %s\t %d\t %d\t %d\t %d\t %.2f\n\n", stu[i].ID, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].sum, stu[i].average);break;}}if (i == *stu_number){printf("\n\t\t要删除的学生不存在!\n");}else{printf("\n\t 确定删除吗(y/n)?:");scanf("\n%c", &ch);if (ch == 'y' || ch == 'Y'){for (j = i + 1; j < *stu_number; j++){stu[j - 1] = stu[j];}printf("\n\t 该学生已被删除!\n");(*stu_number)--;}}printf("\n\t 是否继续删除其他学生(y/n)?:");scanf("\n%c", &ch);}return;}void Modifystu(struct student stu[], int * stu_number)//修改学生记录函数部分{int i, j, choose,xh;char ch = 'y';system("title 修改学生记录");while (ch == 'y' || ch == 'Y'){system("cls");printf("\n\t --------------------------修改学生记录--------------------------\n\n");printf("\t 请输入要修改的学生学号:");scanf("%d", &xh);for (i = 0; i < *stu_number; i++){if (stu[i].ID == xh){printf("\n\t 要修改的学生信息如下:\n");printf("\n\t 学号\t 姓名\t 性别\t数学\t英语\t专业\t总分\t平均分\n\n");printf("\t %d\t %s\t %s\t %d\t %d\t %d\t %d\t %.2f\n\n", stu[i].ID, stu[i].name, stu[i].sex, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].sum, stu[i].average);break;}}if (i == *stu_number){printf("\n\t\t要修改的学生不存在!\n");}else{printf("\n\t 确定修改吗(y/n)?:");scanf("\n%c", &ch);while (ch == 'y' || ch == 'Y'){printf("\n\t 1.基本信息修改 2.学生成绩修改\n");printf("\n\t 请选择修改内容:");scanf("%d", &choose);switch (choose){case 1:system("cls");printf("\n\t\t-------------请重新输入该生的基本信息-----------\n");printf("\n\t\t 学号:");scanf("%d", &stu[i].ID);for (j = 0; j < *stu_number; j++)if (stu[i].ID != xh && stu[i].ID == stu[j].ID){printf("\n\t\t 该学号已存在,请重新输入!\n");printf("\n\t\t 学号:");scanf("%d", &stu[i].ID);}printf("\n\t\t 姓名:");scanf("%s", &stu[i].name);printf("\n\t\t 性别:");scanf("\n%s", &stu[i].sex);break;case 2:system("cls");printf("\n\t\t-------------请重新输入该生的成绩信息-----------\n");printf("\n\t\t 数学成绩:");scanf("%3d", &stu[i].score[0]);printf("\n\t\t 英语成绩:");scanf("%3d", &stu[i].score[1]);printf("\n\t\t 专业成绩:");scanf("%3d", &stu[i].score[2]);stu[i].sum = stu[i].score[0] + stu[i].score[1] + stu[i].score[2];stu[i].average = (float)stu[i].sum / 3.0;}printf("\n\t\t 修改成功!是否继续修改该生的其他信息(y/n)?:");scanf("\n%c", &ch);}}printf("\n\t\t 是否继续修改其他学生的信息(y/n)?:");scanf("\n%c", &ch);}return;}void Countscore(struct student stu[],int * stu_number)//统计学生成绩函数部分{int i, j, choose, sum[3], grade[3][5], min_score[3], max_score[3];float avg[3];system("title 统计学生成绩");while (1){system("cls");printf("\n");printf("\t|---------------------------------------------------------------|\n");printf("\t| 统计学生成绩子菜单|\n");printf("\t|---------------------------------------------------------------|\n");printf("\t| 1---统计每门课程的总分和平均分|\n");printf("\t| 2---统计每门课程的最高分和最低分|\n");printf("\t| 3---统计每门课程各分数段人数|\n");printf("\t| 0---返回主菜单|\n");printf("\t|---------------------------------------------------------------|\n");printf("\t 请选择统计方式:");scanf("%d", &choose);if (choose == 1){for (j = 0; j < 3; j++){sum[j] = 0;avg[j] = 0.0;}for (j = 0; j < 3; j++)for (i = 0; i < *stu_number; i++){sum[j] = sum[j] + stu[i].score[j];}for (j = 0; j < 3; j++){avg[j] = (float)sum[j] / *stu_number;}printf("\n\t 数学课程总分为:%d,平均分为:%.2f\n", sum[0], avg[0]);printf("\n\t 英语课程总分为:%d,平均分为:%.2f\n", sum[1], avg[1]);printf("\n\t 专业课程总分为:%d,平均分为:%.2f\n", sum[2], avg[2]);printf("\n\n\t 统计完毕,按任意键返回子菜单!\n");getch();}elseif (choose == 2){for (j = 0; j < 3; j++) //min_score[3]和max_score[3]数组初始化{min_score[j] = 0;max_score[j] = 0;}for (j = 0; j < 3; j++){if (*stu_number > 0){min_score[j] = max_score[j] = stu[0].score[j]; //最高分最低分置初值}else{min_score[j] = max_score[j] = 0;}for (i = 1; i < *stu_number; i++){if (stu[i].score[j] < min_score[j]){min_score[j] = stu[i].score[j];}if (stu[i].score[j] > max_score[j]){max_score[j] = stu[i].score[j];}}}printf("\n\t 数学课程的最低分:%d,最高分:%d\n", min_score[0], max_score[0]);printf("\n\t 英语课程的最低分:%d,最高分:%d\n", min_score[1], max_score[1]);printf("\n\t 专业课程的最低分:%d,最高分:%d\n", min_score[2], max_score[2]);printf("\n\n\t 统计完毕,按任意键返回子菜单!\n");getch();}elseif (choose == 3){for (i = 0; i < 3; i++)for (j = 0; j < 5; j++){grade[i][j] = 0;}for (j = 0; j < 3; j++)for (i = 0; i < *stu_number; i++){switch (stu[i].score[j] / 10){case 10:case 9:grade[j][0]++;break;case 8:grade[j][1]++;break;case 7:grade[j][2]++;break;case 6:grade[j][3]++;break;default:grade[j][4]++;break;}}printf("\n\n");printf("\t 数学课程各分数段的人数如下:\n");printf("\t 90-100: %d | 80-90: %d | 70-80: %d | 60-70: %d | 60分以下: %d\n\n", grade[0][0], grade[0][1], grade[0][2], grade[0][3], grade[0][4]);printf("\t 英语课程各分数段的人数如下:\n");printf("\t 90-100: %d | 80-90: %d | 70-80: %d | 60-70: %d | 60分以下: %d\n\n", grade[1][0], grade[1][1], grade[1][2], grade[1][3], grade[1][4]);printf("\t 专业课程各分数段的人数如下:\n");printf("\t 90-100: %d | 80-90: %d | 70-80: %d | 60-70: %d | 60分以下: %d\n\n", grade[2][0], grade[2][1], grade[2][2], grade[2][3], grade[2][4]);printf("\n\n\t 统计完毕,按任意键返回子菜单!\n");getch();}elseif (choose == 0){break; //结束循环}}return;}/*********************************************************************** *********************程序的主函数从这里开始运行************************* ************************************************************************/ int main(void){struct student stu[N];int stu_number=0;int choose,flag=1;system("color 1F");system("title 学生信息管理系统");while (flag){system("cls");Menu_seclect();printf("\t\t 请选择主菜单序号(0-7):");scanf("%d", &choose);switch (choose){case 1:Inputstu(stu, &stu_number);break;case 2:Browsestu(stu, &stu_number);break;case 3:Searchstu(stu, &stu_number);break;case 4:Sortstu(stu, &stu_number);break;case 5:Deletestu(stu, &stu_number);break;case 6:Modifystu(stu, &stu_number);break;case 7:Countscore(stu, &stu_number);break;case 0:system("cls");system("color 2F");printf("\n\n\n\n\n");printf("\t*****************************************************************\n") ;printf("\t*****************************************************************\n") ;printf("\t* * * *\n");printf("\t* * 感谢您的使用,再见! * *\n");printf("\t* * * *\n");printf("\t*****************************************************************\n") ;printf("\t*****************************************************************\n") ;flag = 0;}}}。

C语言学生信息管理系统(源代码)

C语言学生信息管理系统(源代码)

#include <stdio.h>#include <string.h>/* 谭法建立单链表和输出单链表*/#include <malloc.h>#include <stdlib.h>typedef struct node{ int num;char name[20];struct node *next;}STD;#define LEN sizeof(STD)int menu_select();void handle_menu1();void game4();void game2();STD *insert(STD *head,STD *stud);STD *insert2(STD *head,STD *stud); void game3();void game5();STD *delete(STD*head,long num);void game1();void game6();STD *search(STD*head,long num);STD *head1,*head2;int n=0;/*追加法建表*/void creat1(void){ STD *p1,*p2;system("CLS");head1=NULL;p1=(STD *)malloc(LEN);p2=p1;printf("建表方法1追加法建表!\n");printf("输入学号姓名,若输入学号为0则退出建表!\n");scanf("%d%s",&p1->num,p1->name);while(p1->num!=0){ n++;if(n==1)head1=p1;elsep2->next=p1;p2=p1;p1=(STD *)malloc(LEN);scanf("%d%s",&p1->num,p1->name);}free(p1); p2->next=NULL;scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");return ;}/* 插入法建表*/void creat2(void){ STD *p1;head2=NULL;system("CLS");p1=(STD *)malloc(LEN);printf("建表方法2插入法建表!\n");printf("输入学号姓名(输入学号以0结束)!\n");scanf("%d%s",&p1->num,p1->name);while(p1->num!=0){ p1->next=head2;head2=p1;p1=(STD *)malloc(LEN);scanf("%d%s",&p1->num,p1->name);}scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");free(p1);return ;}/* 链表输出*/void print(STD *head){ STD *p;p=head;while (p!=NULL){ printf("学号%3d 姓名%s\n",p->num,p->name); p=p->next;} printf("链表为空!\n");scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");}/*-------------------------------------------------*//*--------------表1插入结点函数-------*//*-------------------------------------------------*/void game4(){char ch;STD *stud,*head=head1;system("CLS");printf("\t仅限在表1中插入!\n");printf("\t输入要插入结点的学号和姓名(以空格隔开):");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);if(stud->num<0){ printf("\t输入的学号不能为负数,请重新选择插入!\n");return;}while(stud->num>=0){head1=insert(head,stud);printf("\t继续插入新结点吗?(y/n):");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入新结点学号姓名:(输入n结束插入)");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2插入结点函数-------*//*-------------------------------------------------*/void game2(){char ch;STD *stud,*head=head2;system("CLS");printf("\t仅限在表2中插入!\n");printf("\t输入要插入结点的学号和姓名(以空格隔开):");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);if(stud->num<0){ printf("\t输入的学号不能为负数,请重新选择插入!\n");return;}while(stud->num>=0){head2=insert2(head,stud);printf("\t继续插入新结点吗?(y/n):");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入新结点学号姓名:(输入n结束插入)");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 插入模块*//**************************************/STD *insert(STD *head,STD *stud){STD *p0,*p1,*p2;p1=head;p0=stud;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;}}n=n+1;printf("按回车键继续!\n");getchar();system("CLS");return (head);}/**************************************//* 插入模块2 *//**************************************/STD *insert2(STD *head,STD *stud){STD *p0,*p1,*p2;p1=head;p0=stud;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;}}n=n+1;printf("按回车键继续!\n");getchar();system("CLS");return (head);}/*-------------------------------------------------*//*--------------表1删除学生信息-------*//*-------------------------------------------------*/void game3(){ int num;char ch;STD *head=head1;printf("\t仅限在表1中删除!\n");printf("\t输入要删除的学号:");scanf("%*c");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新选择删除!\n");return;}while(num>=0){head=head1;head1=delete(head,num);printf("\t继续删除吗?(y/n):");scanf("%*c");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要删除的学号:(输入n结束删除!)");scanf("%*c");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2删除学生信息-------*//*-------------------------------------------------*/void game5(){ int num;char ch;STD *head=head2;printf("\t仅限在表2中删除!\n");printf("\t输入要删除的学号:");scanf("%*c");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新选择删除!\n");return;}while(num>=0){head=head2;head2=delete(head,num);printf("\t继续删除吗?(y/n):");scanf("%*c");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要删除的学号:(输入n结束删除!)");scanf("%*c");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 删除模块*//**************************************/STD *delete(STD*head,long num){STD *p1,*p2;if (head==NULL) {printf("\n没有找到该学号!\n");return head;} 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;printf("\n删除:%ld\n",num);n=n-1;}elseprintf("\n 没有发现此项! \n",num);system("CLS");return(head);}/*-------------------------------------------------*//*--------------表1查找学生信息-------*//*-------------------------------------------------*/void game1(){ int num;char ch;STD *head=head1;printf("\t仅限在表1中查找!\n");printf("\t输入要查找的学号:");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新查找!\n");return;}while(num>=0){head=head1;head1=search(head,num);printf("\t继续查找吗?(y/n):");scanf("%d",&num);ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要查找的学号:(输入n结束查找)");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2查找学生信息-------*//*-------------------------------------------------*/void game6(){ int num;char ch;STD *head=head2;printf("\t仅限在表2中查找!\n");printf("\t输入要查找的学号:");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新查找!\n");return;}while(num>=0){head=head2;head2=search(head,num);printf("\t继续查找吗?(y/n):");scanf("%d",&num);ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要查找的学号:(输入n结束查找)");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 查找模块*//**************************************/STD *search(STD*head,long num){STD *p1,*p2;if (head==NULL) {printf("\n没有找到该学号!\n");return head;} p1=head;while(num!=p1->num&&p1->next!=NULL){p2=p1;p1=p1->next;}if(num==p1->num)printf("\n%d %s\n",p1->num,p1->name);elseprintf("\n 没有发现此项! \n",num);return(head);}/* void main(){printf(" *** 运行结果***\n");printf("输入学号姓名(输入学号以0结束)!\n");creat1();print(head1);creat2();print(head2);} *///******************************//* select.cpp:主程序文件*//******************************void main(){handle_menu1();}//*****************************//* 菜单处理函数*//*****************************void handle_menu1(){int h;for(;;){h=menu_select();switch(h){ case 1:/* printf("\t进入追加法建表\n"); */creat1();break; /* 调用功能模块*/case 2:/* printf("\t进入插入法建表\n"); */creat2();break;case 3:/* printf("\t输出追加法链表的结果\n"); */print(head1);break;case 4:/* printf("\t输出插入法链表的结果\n"); */print(head2);break;case 5:/* printf("\t链表1插入\n"); */game4();break;case 6:/* printf("\t链表2插入\n"); */game2();break;case 7:/* printf("\t链表1删除\n"); */game3();break;case 8:/* printf("\t链表2删除\n"); */game5();break;case 9:/* printf("\t链表1查找\n"); */game1();break;case 10:/* printf("\t链表2查找\n"); */game6();break;case 11:printf("\t再见,欢迎再次使用本系统!谢谢!\n");return;}}}//**********************************//* 菜单选择函数: int menu_select()*//**********************************int menu_select(){int cn;for(;;){printf("\ \n");printf("\t1.追加法建表\n");printf("\ \n");printf("\t2.插入法建表\n");printf("\ \n");printf("\t3.输出链表1\n");printf("\ \n");printf("\t4.输出链表2\n");printf("\ \n");printf("\t5.插入链表1 \n");printf("\ \n");printf("\t6.插入链表2 \n");printf("\ \n");printf("\t7.删除链表1 \n");printf("\ \n");printf("\t8.删除链表2 \n");printf("\ \n");printf("\t9.查找链表1 \n");printf("\ \n");printf("\t10.查找链表2 \n");printf("\ \n");printf("\t11.退出系统\n");printf("\ \n");printf("\t请您选择1-11:");scanf("%d",&cn);//gets(s);//cn=atoi(s);if(cn<1||cn>11)printf("\n\t输入错误,重选1-11:");elsebreak;}return cn;}。

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

学生信息管理系统C语言编程【问题描述】学生信息的管理是每个学校必须具有的管理功能,主要是对学生的基本情况及学习成绩等方面的管理。

该系统模拟一个简单的学生管理系统,要求对文件中所存储的学生数据进行各种常规操作,如:排序、查找、计算、显示等功能。

通过此课题,熟练掌握文件、数组、结构体的各种操作,在程序设计中体现一定的算法思想,实现一个简单的学生信息管理系统。

【基本要求】(1)学生信息包括:学生基本信息文件(student.txt)(注:该文件不需要编程录入数据,可用文本编辑工具直接生成)的内容如下:(2)学生成绩基本信息文件(score.dat)及其内容如下:((注:该文件内容需要编程录入数据,具体做法见下面的要求)学号课程编号课程名称学分平时成绩实验成绩卷面成绩综合成绩实得学分(3)需要实现的功能1)数据录入和计算功能:对score.dat进行数据录入,只录入每个学生的学号、课程编号、课程名称、学分、平时成绩、实验成绩、卷面成绩共7个数据,综合成绩、实得学分由程序根据条件自动运算。

综合成绩的计算:如果本课程的实验成绩为-1,则表示无实验,综合成绩=平时成绩*30%+卷面成绩*70%;如果实验成绩不为-1,表示本课程有实验,综合成绩=平时成绩*15%+实验成绩*15%+卷面成绩*70% 。

实得学分的计算:采用等级学分制,综合成绩在90-100之间,应得学分=学分*100%;综合成绩在80-90之间,应得学分=学分*80%;综合成绩在70-80之间 ,应得学分=学分*75%;综合成绩在60-70之间,应得学分=学分*60%;综合成绩在60以下 ,应得学分=学分*0%。

2)查询功能:分为学生基本情况查询和成绩查询两种(1)学生基本情况查询:①、输入一个学号或姓名(可实现选择),查出此生的基本信息并显示输出,格式如下:②、输入一个宿舍号码,可查询出本室所有的学生的基本信息并显示输出。

(格式如上所示)(2)成绩查询:①、输入一个学号时,查询出此生的所有课程情况,格式如下:学号:xx 姓名:xxxxx课程编号:xxx 课程名称:xxxxx 综合成绩:xxxx 实得学分: xx课程编号:xxx 课程名称:xxxxx 综合成绩:xxxx 实得学分: xx课程编号:xxx 课程名称:xxxxx 综合成绩:xxxx 实得学分: xx ……………………共修:xx科,实得总学分为: xxx(3)删除功能:提供待删除学生的学号,则在student.txt和score.dat中删除所有与该学生有关的信息。

(4)排序功能:能实现选择按综合成绩或实得学分升序或降序排序并显示数据。

【程序设计的具体说明】(1)将与两个文件对应的信息分别定义两种结构体类型来表示,也可以用类来定义;(2)对score.dat文件的写入,从键盘上输入的是前七项,后两项数据项根据计算方法算出后,得到完整的结构体信息,作为一个整体写入(可调用write函数)。

(3)删除功能中可以将删除相关信息后得到的文件生成新文件存储,也可以在原文件的基础上作删除(4)可以用面向过程方法或是面向对象的方法实现。

(5)主界面提供菜单选择的方法选择实现某一功能,一次运行程序能进行多次选择执行不同的功能。

#include"stdio.h"#include"stdlib.h"#include"string.h"#define N 3typedef struct z1{char no[11];char name[15];int score[N];float sum;float average;int order;struct z1 *next;}STUDENT;STUDENT *init();STUDENT *create();STUDENT *del(STUDENT *h);void print(STUDENT *h);void search1(STUDENT *h);void search2(STUDENT *h);STUDENT *insert(STUDENT *h);void sort(STUDENT *h);void save(STUDENT *h);void tongji(STUDENT *h);int menu_select();STUDENT *load();void inputs(char *prompt,char *s,int count);STUDENT *load();main(){int i;STUDENT *head;head=init();for(;;){switch(menu_select()){case 0:head=init();break;case 1:head=create();break;case 2:head=insert(head);break;case 3:save(head);break;case 4:print(head);break;case 5:search1(head);break;case 6:head=del(head);break;case 7:sort(head);break;case 8:tongji(head);break;case 9:search2(head);break;case 10:exit(0);}}}int menu_select(){char *menu[]={"************菜单************", "0. 初始化链表","1. 输入学生成绩","2. 插入学生成绩","3. 保存学生记录","4. 显示学生记录","5. 按学号查找学生信息","6. 删除指定学号的学生信息","7. 按某一门课对学生成绩排序","8. 统计某门课程的学生成绩","9. 按姓名查找学生信息","10. 退出系统"};char s[3];int c,i;for(i=0;i<=11;i++)printf(" %s\n",menu[i]);do{printf("\n请选择0~10中的某一个选项\n"); scanf("%s",s);c=atoi(s);}while(c<0||c>10);return c;}STUDENT *init(){return NULL;}STUDENT *create(){int i;int s;STUDENT *h=NULL,*info;for(;;){info=(STUDENT *)malloc(sizeof(STUDENT));if(!info){printf("\n内存不足");return NULL;}inputs("输入学号:",info->no,11);if(info->no[0]=='@')break;inputs("输入姓名:",info->name,15);printf("开始输入%d门课的成绩\n",N);s=0;for(i=0;i<N;i++){do{printf("第%d门分数:",i+1);scanf("%d",&info->score[i]);if(info->score[i]>100||info->score[i]<0) printf("输入成绩错误,请重新输入:\n");}while(info->score[i]>100||info->score[i]<0); s=s+info->score[i];}info->sum=s;info->average=(float)s/N;info->order=0;info->next=h;h=info;}return h;}void inputs(char *prompt,char *s,int count){char p[255];do{printf(prompt);scanf("%s",p);if(strlen(p)>count)printf("\n太长了!\n");}while(strlen(p)>count);strcpy(s,p);}void print(STUDENT *h){int i=0;STUDENT *p;p=h;printf("\n\n\n***********************学生***********************\n");printf("|序号|学号 | 姓名 | 语文 | 英语 |数学 | 总分 |平均分 |名次|\n");printf("|---|-------|--------|----|----|----|------|------|---|\n");while(p!=NULL){i++;printf("|%3d|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",i,p->no,p->name,p->score[0],p->score [1],p->score[2],p->sum,p->average,p->order);p=p->next;}printf("***********************end***********************\n");}STUDENT *del(STUDENT *h){STUDENT *p,*q;char s[11];printf("请输入要删除的学生的学号\n");scanf("%s",s);q=p=h;while(strcmp(p->no,s)&&p!=NULL){q=p;p=p->next;}if(p==NULL)printf("\n链表中没有学号为%s的学生\n",s);else{printf("\n\n\n***********************找到了***********************\n"); printf("|学号 | 姓名 | 语文 | 英语 | 数学 | 总分 | 平均分 | 名次|\n");printf("|----------|----------|----|----|----|------|------|---|\n");printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);printf("***********************end***********************\n");printf("请按任意键删除\n");getchar();if(p==h)h=p->next;else q->next=p->next;free(p);printf("\n已经删除学号为%s的学生\n",s);printf("不要忘了保存数据\n");}return h;}void search1(STUDENT *h){STUDENT *p;char s[11];printf("请输入你要查找的同学的学号\n");scanf("%s",s);p=h;while(strcmp(p->no,s)&&p!=NULL)p=p->next;if(p==NULL)printf("'n没有学号为%s的学生\n",s);else{printf("\n\n\n***********************找到了***********************\n"); printf("|学号 | 姓名 | 语文 | 英语 | 数学 | 总分 | 平均分| 名次 |\n");printf("|----------|-----------|----|----|----|------|------|---|\n");printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);printf("***********************end***********************\n");}}void search2(STUDENT *h){STUDENT *p;char s[11];printf("请输入你要查找的同学的姓名\n");scanf("%s",s);p=h;while(strcmp(p->name,s)&&p!=NULL)p=p->next;if(p==NULL)printf("\n没有姓名为%s的学生\n",s);else{printf("\n\n\n***********************找到了***********************\n"); printf("|学号 | 姓名 | 语文 | 英语 | 数学 | 总分 | 平均分 | 名次 |\n");printf("|----------|-----------|----|----|----|------|------|---|\n");printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);printf("***********************end***********************\n");}}STUDENT *insert(STUDENT *h){STUDENT *p,*q,*info;char s[11];int s1,i;printf("请输入插入点的学生学号\n");scanf("%s",s);printf("\n请输入新的学生信息\n");info=(STUDENT *)malloc(sizeof(STUDENT));if(!info){printf("\n内存不足!");return NULL;}inputs("输入学号:",info->no,11);inputs("输入姓名:",info->name,15);printf("请输入%d门课的分数\n",N);s1=0;for(i=0;i<N;i++){do{printf("分数%d",i+1);scanf("%d",&info->score[i]);if(info->score[i]>100||info->score[i]<0)printf("输入数据有误,请重新输入\n");}while(info->score[i]>100||info->score[i]<0);s1=s1+info->score[i];}info->sum=s1;info->average=(float)s1/N;info->order=0;info->next=NULL;p=h;q=h;while(strcmp(p->no,s)&&p!=NULL){q=p;p=p->next;}if(p==NULL)if(p==h)h=info;else q->next=info;elseif(p==h){info->next=p;h=info;}else{info->next=p;q->next=info;}printf("\n已经插入了%s这个学生\n",info->name);printf("----不要忘了存盘啊--\n");return(h);}void save(STUDENT *h){FILE *fp;STUDENT *p;char outfile[10];printf("请输入保存文件的文件名,例如 c:\\f1\\te.txt:\n"); scanf("%s",outfile);if((fp=fopen(outfile,"wb"))==NULL){printf("不能打开文件\n");exit(1);}printf("\n正在保存......\n");p=h;while(p!=NULL){fwrite(p,sizeof(STUDENT),1,fp);p=p->next;}fclose(fp);printf("------保存成功!!!------\n");}void sort(STUDENT *h){int i=0,j;STUDENT *p,*q,*t,*h1;printf("请输入要按哪门课程的编号来排序:(0.语文 1.数学 2.英语)\n"); scanf("%d",&j);h1=h->next;h->next=NULL;while(h1!=NULL){t=h1;h1=h1->next;p=h;q=h;while(t->score[j]<p->score[j]&&p!=NULL){q=p;p=p->next;}if(p==q){t->next=p;h=t;}else{t->next=p;q->next=t;}}p=h;while(p!=NULL){i++;p->order=i;p=p->next;}print(h);printf("排序成功!!!\n");}void tongji(STUDENT *h){STUDENT *p;int a,b,i;printf("请输入课程编号\n");scanf("%d",&i);printf("请输入分数段:\n");scanf("%d,%d",&a,&b);p=h;while(p!=NULL){printf("\n\n\n***********************找到了***********************\n");if(p->score[i]>=a&&p->score[i]<=b){printf("|学号 | 姓名 | 语文 | 英语 | 数学 | 总分 | 平均分 | 名次 |\n");printf("|--------|---------|----|----|----|------|------|---|\n");printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);}p=p->next;}printf("***********************end***********************\n");}。

相关文档
最新文档