学生宿舍管理软件C语言源代码完整版
宿舍管理系统c语言
#include"stdio.h"int main_menu_select() /*主菜单选择*/ {char s;printf("\n1 Administrator in charge of the students and books' information\n");printf("\n2 Administrator in charge of lend books\n");printf("\n3 Administrator in charge of receive books\n");printf("\n4 Student\n");printf("\n5 Guest\n");printf("\n6 exit\n\n");printf("\n input 1-6 to choice the function\n");do{s=getche();printf("\n");}while(s<49||s>54);return s;}int administrator_menu_select() /*管理员菜单选择*/ {int s;printf("input 1-6 to choice the function\n");printf("1 input the information of books\n");printf("2 recompose the information of the books\n");printf("3 cancel the information of books \n");printf("4 input the information of students\n");printf("5 recompose information of the students\n");printf("6 cancel the information of students\n");printf("7 return main menu\n");printf("8 exit\n\n" );do{s=getche();printf("\n");}while(s<49||s>56);return s;}hello_main() /*返回主菜单*/ {for(; ;){switch(main_menu_select()){case 49:adm_information();break;case 51:printf("hellooo");break;case 52:printf("helloooo");break;case 53:printf("hellooooo");break;case 54:printf("Goodbye!");exit(0);}}}hello_adm_menu() /*返回管理员功能选择菜单*/ {for(; ;){switch(administrator_menu_select()){case 49:books_information_input();break;case 50:printf("Student\n");break;case 51:printf("Guest\n");break;case 52:students_information_input();break;case 53:printf("Guest of gentleman\n");break;case 54:printf("hahha");break;case 55:hello_main();break;case 56:printf("Goodbye!");exit(0);}}}struct /*图书结构体*/ {int number;char name[20];char press[20];char writer[20];int price;}books[200];struct /*学生结构体*/ {int number;char name[20];char sex[6];int grade;}students[200];adm_information() /*管理员菜单*/ {for(; ;){switch(administrator_menu_select()){case 49:books_information_input();break;case 51:printf("Guest\n");break;case 52:students_information_input();break;case 53:printf("Guest of gentleman\n");break;case 54:printf("hahha");break;case 55:hello_main();break;case 56:printf("Goodbye!");exit(0);}}}int books_information_input() /*图书信息输入函数*/ {int m,i,s;char h;printf("input the number of the books you want to operate:");scanf("%d",&m);for(i=1;i<m+1;i++){printf("please input the %dth book's number:",i);scanf("%d",&books[i].number);printf("\n please input the %dth book's name:",i);scanf("%s",books[i].name);printf("\n please input the %dth book's press:",i);scanf("%s",books[i].press);printf("\n please input the %dth book's writer:",i);scanf("%s",books[i].writer);printf("\n please input the %dth book's price:",i);scanf("%d",&books[i].price);printf("\n\n");}printf("\ninformation of the students has been inputed\n");printf("1 to return higher menu\n"); /*返回上一级菜单,即管理员选择功能菜单*/h=getche();if(h==1)hello_adm_menu();}students_information_input() /*学生信息输入函数*/ {int m,i,s;printf("input the number of the students you want to operate:");scanf("%d",&m);for(i=1;i<m+1;i++){printf("\nplease input the %dth student's number:",i);scanf("%d",&students[i].number);printf("\n please input the %dth student's name:",i);scanf("%s",students[i].name);printf("\n please input the %dth student's sex:",i);scanf("%s",students[i].sex);printf("\n please input the %dth student's grade:",i);scanf("%d",&students[i].grade);}printf("\ninformation of the books has been inputed\n\n"); }main(){for(; ;){switch(main_menu_select()){case 49:adm_information();break;case 50:printf("helloo");break;case 51:printf("hellooo");break;case 52:printf("helloooo");break;case 53:printf("hellooooo");break;case 54:printf("Goodbye!");exit(0);}}}。
C语言实现学生宿舍信息管理系统
C语⾔实现学⽣宿舍信息管理系统本⽂实例为⼤家分享了C语⾔实现学⽣宿舍信息管理系统的具体代码,供⼤家参考,具体内容如下功能描述该学⽣宿舍信息管理系统主要实现的功能有:创建学⽣宿舍信息,显⽰学⽣宿舍信息,查询学⽣宿舍信息,修改学⽣宿舍信息,删除学⽣宿舍信息,保存学⽣宿舍信息,读取学⽣宿舍信息。
其系统功能模块图如下:完整代码如下:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>#include<windows.h>#define MAX 1000int k=0;//结构体类型typedef struct{char name[20]; //姓名char sex[5]; //性别char classs[20]; //班级int number; //学号int age; //年龄int dorm; //宿舍号int year; //年份int month; //⽉份}students;//创建学⽣宿舍信息int establish(students stu[]){ int i,x;for(i=0;i<1000;i++){system("cls");printf("\n\n 录⼊学⽣信息 (最多%d个)\n",MAX);printf(" ----------------------------\n");printf("\n 第%d个学⽣",k+1);printf("\n 请输⼊学⽣的学号:");scanf("%d",&stu[k].number);printf("\n 请输⼊学⽣的姓名:");scanf("%s",stu[k].name);printf("\n 请输⼊学⽣的性别:");scanf("%s",stu[k].sex);printf("\n 请输⼊学⽣的年龄:");scanf("%d",&stu[k].age);printf("\n 请输⼊学⽣的班级:");scanf("%s",stu[k].classs);printf("\n 请输⼊学⽣⼊住时间(如:2017 9):");while((scanf("%d %d",&stu[k].year,&stu[k].month))!=EOF){if(stu[k].year<1000||stu[k].year>9999||stu[k].month>12||stu[k].month<1)//限定输⼊范围{printf("对不起,输⼊错误,请重新输⼊:");}elsebreak;}printf("\n 请输⼊学⽣的宿舍号:");scanf("%d",&stu[k++].dorm);printf("\n 请按 1 键返回主菜单或按 0 键继续创建:");scanf("%d",&x);if(x!=0) break;}return k;}//显⽰学⽣宿舍信息void display(students stu[]){int i;for(i=0;i<k;i++){printf("学号:%d 姓名:%s 性别:%s 年龄:%d 班级:%s 宿舍号: %d ⼊住时间:%d/%d\n",stu[i].number,stu[i].name,stu[i].sex,stu[i].age,stu[i].classs,stu[i].dorm,stu[i].year,stu[i].month);}printf("按任意键返回主菜单!");getch();system("cls");return ;}//查询学⽣宿舍信息void query(students stu[]){int i,m=0;Sleep(1000);for(i=0;i<k;i++){if(number==stu[i].number){printf("\n\n学号:%d 姓名:%s 性别:%s 年龄:%d 班级:%s 宿舍号: %d ⼊住时间:%d/%d\n",stu[i].number,stu[i].name,stu[i].sex,stu[i].age,stu[i].classs,stu[i].dorm,stu[i].year,stu[i].month);m=1;}}if(m==0){printf("对不起,此学⽣信息不存在!\n");}printf("按任意键返回主菜单!");getch();system("cls");return ;}//修改学⽣信息void modify(students stu[]){int number,i,choose,m=0;system("cls");printf("\n\n\n 请输⼊您要修改的学⽣的学号:");scanf("%d",&number);printf(" 正在查询,请稍后.....\n");Sleep(1000);for(i=0;i<k;i++){if(number==stu[i].number){printf("\n\n学号:%d 姓名:%s 性别:%s 年龄:%d 班级:%s 宿舍号: %d ⼊住时间:%d/%d\n",stu[i].number,stu[i].name,stu[i].sex,stu[i].age,stu[i].classs,stu[i].dorm,stu[i].year,stu[i].month);printf("\n\n ********请输⼊您想要修改的数据********\n\n");printf(" 1. 学号\n");printf(" 2. 姓名\n");printf(" 3. 性别\n");printf(" 4. 年龄\n");printf(" 5. 班级\n");printf(" 6. 宿舍号\n");printf(" 7. ⼊住时间\n\n");printf(" 请选择(1-7):");while((scanf("%d",&choose))!=EOF){if(choose<1||choose>7){printf("对不起,输⼊错误,请重新输⼊:");}else{switch(choose){case 1:{printf("\n 请输⼊你改的新学号:");scanf("%d",&stu[i].number);break;}case 2:{printf("\n 请输⼊你改的新姓名:");scanf("%s",stu[i].name);break;}case 3:{printf("\n 请输⼊你改的新性别:");scanf("%s",stu[i].sex);break;}case 4:{printf("\n 请输⼊你改的新年龄:");scanf("%d",&stu[i].age);break;}case 5:{printf("\n 请输⼊你改的新班级:");scanf("%s",stu[i].classs);break;}case 6:{printf("\n 请输⼊你改的新宿舍:");scanf("%d",&stu[i].dorm);break;}case 7:{printf("\n 请输⼊你改的新⼊住时间:");scanf("%d %d",&stu[i].year,&stu[i].month);break;}}printf("修改成功!");Sleep(500);printf("\n\n学号:%d 姓名:%s 性别:%s 年龄:%d 班级:%s 宿舍号: %d ⼊住时间:%d/%d\n",stu[i].number,stu[i].name,stu[i].sex,stu[i].age,stu[i].classs,stu[i].dorm,stu[i].year,stu[i].month);}}if(m==0){printf("对不起,此学⽣信息不存在!\n");}printf("按任意键返回主菜单!");getch();return ;}//删除学⽣信息void deletee(students stu[]){char name1[20];int i,j,m=0;printf("请输⼊学⽣姓名:");scanf("%s",name1);printf("\n");printf("正在查找是否存在此学⽣信息.....\n");Sleep(1000);for(i=0;i<k;i++){if(strcmp(stu[i].name,name1)==0){m=1;printf("已找到此学⽣信息!\n删除中....\n");Sleep(2000);for(j=i;j<k;j++){strcpy(stu[j].name,stu[j+1].name);strcpy(stu[j].sex,stu[j+1].sex);strcpy(stu[j].classs,stu[j+1].classs);stu[j].age=stu[j+1].age;stu[j].dorm=stu[j+1].dorm;stu[j].number=stu[j+1].number;stu[j].year=stu[j+1].year;stu[j].month=stu[j+1].month;}k--;printf("删除成功!\n");}}if(m==0){printf("此学⽣信息不存在!\n");}printf("按任意键返回主菜单!");getch();system("cls");return ;}//保存学⽣住宿信息void preservation(students stu[]){int i;FILE *fp;if((fp=fopen("学⽣宿舍信息.txt","w"))==NULL){printf("未发现学⽣宿舍信息!\n");printf("按任意键返回...\n");getch();system("cls");return ;}else{for(i=0;i<k;i++){fprintf(fp,"\n\n学号:%d 姓名:%s 性别:%s 年龄:%d 班级:%s 宿舍号: %d ⼊住时间:%d/%d\n",stu[i].number,stu[i].name,stu[i].sex,stu[i].age,stu[i].classs,stu[i].dorm,stu[i].year,stu[i].month); }fclose(fp);printf("正在保存⽂件....\n");Sleep(1000);printf("⽂件保存成功!\n");printf("按任意键返回...\n");getch();system("cls");return ;}}//读取学⽣住宿信息void read(students stu[]){FILE *fp;char ch;if((fp=fopen("学⽣宿舍信息.txt","r"))==NULL){printf("⽂件⽆法打开!\n");exit(0);}printf("正在读⼊⽂件...\n");putchar(ch);ch=fgetc(fp);}printf("\n");fclose(fp);printf("按任意键返回...\n");getch();system("cls");return ;}void title(){printf(" \n\n\n **********************************\n");printf(" * *\n");printf(" * *\n");printf(" * *\n");printf(" * 欢迎进⼊学⽣宿舍信息管理系统 *\n");printf(" * *\n");printf(" * *\n");printf(" * *\n");printf(" **********************************\n");printf("\n 按任意键进⼊系统!\n");getch();}void start(){students stu[20];int choose,k;while(choose!=0){system("cls");printf("\n\n\n ********学⽣宿舍信息管理系统********\n\n");printf(" 1. 创建学⽣宿舍信息\n\n");printf(" 2. 显⽰学⽣宿舍信息\n\n");printf(" 3. 查询学⽣宿舍信息\n\n");printf(" 4. 修改学⽣宿舍信息\n\n");printf(" 5. 删除学⽣宿舍信息\n\n");printf(" 6. 保存学⽣宿舍信息\n\n");printf(" 7. 读取学⽣宿舍信息\n\n");printf(" 0. 退出系统\n\n");printf(" 请选择(0-7):");while((scanf("%d",&choose))!=EOF){if(choose<0||choose>7){printf("对不起,输⼊错误,请重新输⼊:");}else{switch(choose){case 1: k=establish(stu); break;//创建学⽣宿舍信息case 2: display( stu) ; break;//显⽰学⽣宿舍信息case 3: query(stu); break;//查询学⽣宿舍信息case 4: modify(stu); break;//修改学⽣宿舍信息case 5: deletee(stu); break;//删除学⽣宿舍信息case 6: preservation(stu); break;//保存学⽣宿舍信息case 7: read(stu);break;//读取学⽣宿舍信息case 0: break;}break;}}}}int main(){title();start();return 0;}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
宿舍管理系统_C语言源代码
#include<stdio.h>struct dorm{int num;int members_num;int Health_score;char member1[10];char member2[10];char member3[10];char member4[10];};struct student{int num;char name[10];int dorm_num;char gender[10];char major[10];char class_name[10];char instructor[10];};static struct dorm dm[100];static struct student st[400];static int d_i=2;static int s_i=2;void pri_dorm(struct dorm d){printf("\n宿舍号:%d\n",d.num);printf("现住人数:%d\n",d.members_num);printf("卫生分数:%d\n",d.Health_score);printf("宿舍成员:\n");if(d.member1[0]!=NULL) printf("%s\n",d.member1);if(d.member2[0]!=NULL) printf("%s\n",d.member2);if(d.member3[0]!=NULL) printf("%s\n",d.member3);if(d.member4[0]!=NULL) printf("%s\n",d.member4);printf("\n");}void pri_student(struct student s){printf("\n学号:%d\n",s.num);printf("姓名:%s\n",);printf("宿舍号:%d\n",s.dorm_num);printf("性别:%s\n",s.gender);printf("班级:%s\n",s.class_name);printf("专业:%s\n",s.major);printf("辅导员:%s\n",s.instructor);printf("\n");}int panduansusherenshu(struct dorm d)//通过此函数,判断宿舍共多少人(宿舍人数最多住四个人){int i=0;if(d.member1[0]!=NULL){i++;}if(d.member2[0]!=NULL){i++;}if(d.member3[0]!=NULL){i++;}if(d.member4[0]!=NULL){i++;}return i;}int panduanxueshengxinxi(struct student s)//判断学生信息是否合法{int i=1;int j=0;int k=0;if(((s.num/100000000)>0)){if(!strcmp(s.gender,"男")||!strcmp(s.gender,"女")){if((s.dorm_num/100)>0){i=0;}}}for(j=0;j<sizeof(dm)/52;j++){if(dm[j].num==s.dorm_num){k=1;break;}}if(k==0) {i=1;}for(j=0;j<sizeof(st)/60;j++){if(st[j].num==s.num) i=1;}for(j=0;j<sizeof(dm)/52;j++){if(dm[j].members_num==4) {i=1;printf("\n宿舍人数已满!\n");}}return i;}void main_interface()//主界面{int i=0;void interface1();void interface2();void interface3();void interface4();void interface5();void interface6();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("********************************\n");printf("请输入操作项:");scanf("%d",&i);switch(i){case 1:system("cls");interface1();break;case 2:system("cls");interface2();break;case 3:system("cls");interface3();break;case 4:system("cls");interface4();break;case 5:system("cls");interface5();break;case 6:system("cls");interface6();break;case 7:system("cls");exit(0);default:system("cls");printf("操作项命令错误,请重新输入!");main_interface();break;}}void interface1()//查找宿舍信息{int i=0;//选项选择int j=0;//记录需要查询的学生学号int k=0;int q=0;printf("\n");printf("进入宿舍信息查询界面:\n");printf("********************************\n");printf("****** 宿舍信息查询******\n");printf("*** 1.进入宿舍查询***\n");printf("*** 2.返回主界面***\n");printf("********************************\n");printf("请输入操作项:");scanf("%d",&i);switch(i){case 1:printf("请输入需要查询宿舍的宿舍号:");scanf("%d",&j);for(k=0;k<sizeof(dm)/52;k++){if(dm[k].num==j){q=1; break;}}if(q==1){system("cls");pri_dorm(dm[k]);printf("\n返回上一界面\n");interface1();}else{system("cls");printf("\n不存在您所查询的宿舍号!");printf("\n返回上一界面\n");interface1();}break;case 2:system("cls");printf("\n");printf("进入主界面:\n");main_interface();break;default :system("cls");printf("\n选项输入错误!\n");printf("\n返回上一界面\n");interface1();break;}}void interface2()//查找学生信息{int i=0;//选项选择int j=0;//记录学生学号int q=0;int k=0;printf("\n");printf("进入学生信息查询界面:\n");printf("********************************\n");printf("****** 学生信息查询******\n");printf("*** 1.进入学生查询***\n");printf("*** 2.返回主界面***\n");printf("********************************\n");printf("请输入操作项:");scanf("%d",&i);switch(i){case 1:printf("请输入需要查询学生的学号:");scanf("%d",&j);for(k=0;k<sizeof(dm)/52;k++){if(st[k].num==j){q=1; break;}}if(q==1){system("cls");pri_student(st[k]);printf("\n返回上一界面\n");interface2();}else{system("cls");printf("\n你查找的学生不存在!");printf("\n返回上一界面\n");interface2();}break;case 2:system("cls");printf("\n");printf("进入主界面:\n");main_interface();break;default:system("cls");printf("\n选项输入错误!\n");printf("\n返回上一界面\n");interface2();break;}}void interface3()//添加入住学生{struct student ss;int j=0;printf("请输入学生的信息:\n");printf("学号:");scanf("%d",&ss.num);printf("姓名:");scanf("%s",&);printf("宿舍号:");scanf("%d",&ss.dorm_num);printf("性别:");scanf("%s",&ss.gender);printf("班级:");scanf("%s",&ss.class_name);printf("专业:");scanf("%s",&ss.major);printf("辅导员:");scanf("%s",&ss.instructor);if(panduanxueshengxinxi(ss)==0){s_i++;st[s_i].num=ss.num;st[s_i].dorm_num=ss.dorm_num;strcat(st[s_i].name,);strcat(st[s_i].gender,ss.gender);strcat(st[s_i].class_name,ss.class_name);strcat(st[s_i].instructor,ss.instructor);strcat(st[s_i].major,ss.major);pri_student(st[s_i]);}else{system("cls");printf("\n\n输入的学生信息有错误,请重新输入!\n\n");interface3();}for(j=0;j<=sizeof(dm)/52;j++){if(dm[j].num==ss.dorm_num) break;}if(dm[j].member1[0]==NULL) strcat(dm[j].member1,);else if(dm[j].member2[0]==NULL) strcat(dm[j].member2,);else if(dm[j].member3[0]==NULL) strcat(dm[j].member3,);else strcat(dm[j].member4,);dm[j].members_num++;system("cls");printf("添加学生成功!\n");printf("\n返回主界面!\n");main_interface();}void interface4()//删除入住学生{int i=0;//存储需要删除学生的学号int j=0;int k=0;int q=0;printf("请输入需要删除的学生学号:\n");scanf("%d",&i);for(j=0;j<sizeof(st)/60;j++){if(st[j].num==i){k=1;break;}}if(k==0){system("cls");printf("不存在需要删除学生!\n");printf("返回上一界面,请重新输入!\n");interface4();}if(k==1){for(q=0;q<sizeof(dm)/52;q++){if(dm[q].num=st[j].dorm_num){dm[q].members_num--;if(!strcmp(dm[q].member1,st[j].name)){dm[q].member1[0]=NULL;strcmp(dm[q].member1," ");}if(!strcmp(dm[q].member2,st[j].name)){dm[q].member2[0]=NULL;strcmp(dm[q].member2," ");}if(!strcmp(dm[q].member3,st[j].name)){dm[q].member3[0]=NULL;strcmp(dm[q].member3," ");}if(!strcmp(dm[q].member4,st[j].name)){dm[q].member4[0]=NULL;strcmp(dm[q].member4," ");}}}st[j].num=0;st[j].name[0]=NULL;strcmp(st[j].name," ");st[j].class_name[0]=NULL;strcmp(st[j].class_name," ");st[j].dorm_num=0;st[j].gender[0]=NULL;strcmp(st[j].gender," ");st[j].instructor[0]=NULL;strcmp(st[j].instructor," ");st[j].major[0]=NULL;strcmp(st[j].major," ");}system("cls");printf("删除学生成功,返回主界面!\n");main_interface();}void interface5()//更改宿舍信息{int i=0;//存储宿舍号int j=0;//储存更改后的分数int k=0;int q=0;printf("请输入需要更改信息的宿舍号:\n");scanf("%d",&i);for(k=0;k<sizeof(dm)/52;k++){if(dm[k].num==i){q=1;break;}}if(q==1){printf("********************************\n");printf("****** 宿舍信息更改******\n");printf("*** 更改卫生分数***\n");printf("********************************\n");while(1){printf("\n%d宿舍卫生分数更改为:\n",i);scanf("%d",&j);if(j>=0&&j<=10) break;else {printf("输入的分数有错误,请重新输入!\n");}}dm[k].Health_score=j;system("cls");printf("更改宿舍信息成功!\n");printf("\n返回主界面:\n");main_interface();}if(q==0){system("cls");printf("输入的宿舍号不存在,请确认后重新输入!\n\n");interface5();}}void interface6()//更改学生信息{int i=0;//存储学生学号int k=0;//判断该学号是否存在int j=0;int q=0;//存储选项struct student ss;printf("请输入需要被更改的学生的学号:\n");scanf("%d",&i);for(j=0;j<sizeof(st)/60;j++){if(st[j].num==i){k=1;break;}}if(k==0){printf("该学号不存在,请确认后重新输入!\n");interface6();} if(k==1){printf("********************************\n");printf("****** 学生信息更改******\n");printf("*** 1.更改姓名***\n");printf("*** 2.更改班级***\n");printf("*** 3.更改专业***\n");printf("*** 4.更改辅导员***\n");printf("********************************\n");printf("\n请输入选项:\n");scanf("%d",&q);switch(q){case 1:printf("请输入改变后的姓名:\n");scanf("%s",);strcpy(st[j].name,);system("cls");printf("\n更改信息成功,返回主界面!\n");main_interface();break;case 2:printf("请输入改变后的班级:\n");scanf("%s",ss.class_name);strcpy(st[j].class_name,ss.class_name);system("cls");printf("\n更改信息成功,返回主界面!\n");main_interface();break;case 3:printf("请输入改变后的专业:\n");scanf("%s",ss.major);strcpy(st[j].major,ss.major);system("cls");printf("\n更改信息成功,返回主界面!\n");main_interface();break;case 4:printf("请输入改变后的辅导员:\n");scanf("%s",ss.instructor);strcpy(st[j].instructor,ss.instructor);system("cls");printf("\n更改信息成功,返回主界面!\n");main_interface();break;default :system("cls");printf("选项输入错误! 返回上一界面!\n");interface6();break;}}}void start(){int j=103;int i=0;dm[0].num=101;dm[0].Health_score=10;dm[0].member1[0]=NULL;strcat(dm[0].member1,"赵钱");dm[0].member2[0]=NULL;dm[0].member3[0]=NULL;dm[0].member4[0]=NULL;dm[0].members_num=panduansusherenshu(dm[0]);dm[1].num=102;dm[1].Health_score=9;dm[1].member1[0]=NULL;strcat(dm[1].member1,"周吴");dm[1].member2[0]=NULL;dm[1].member3[0]=NULL;dm[1].member4[0]=NULL;dm[1].members_num=panduansusherenshu(dm[1]);for(i=2;i<100;i++){dm[i].num=j++;dm[i].members_num=0;dm[i].Health_score=0;dm[i].member1[0]=NULL;dm[i].member2[0]=NULL;dm[i].member3[0]=NULL;dm[i].member4[0]=NULL;}st[0].num=201011011;st[0].name[0]=NULL;strcat(st[0].name,"赵钱");st[0].dorm_num=101;st[0].class_name[0]=NULL;strcat(st[0].class_name,"工商1001");st[0].gender[0]=NULL;strcat(st[0].gender,"女");st[0].major[0]=NULL;strcat(st[0].major,"工商管理");st[0].instructor[0]=NULL;strcat(st[0].instructor,"巴菲特");st[1].num=201011012;st[1].name[0]=NULL;strcat(st[1].name,"周吴");st[1].dorm_num=102;st[1].class_name[0]=NULL;strcat(st[1].class_name,"软件1001");st[1].gender[0]=NULL;strcat(st[1].gender,"女");st[1].major[0]=NULL;strcat(st[1].major,"软件工程");st[1].instructor[0]=NULL;strcat(st[1].instructor,"李开复");for(i=2;i<400;i++){st[i].num=0;st[i].name[0]=NULL;st[i].class_name[0]=NULL;st[i].dorm_num=0;st[i].gender[0]=NULL;st[i].instructor[0]=NULL;st[i].major[0]=NULL;}}int main(){start();printf("************************************************************************\ n");printf(" 宿舍管理系统说明: \n\n");printf(" 该程序现有两人(201011011赵钱、201011012周吴)分别入住在寝室101、102\n\n");printf(" 宿舍号必须为三位数字,如101;学生学号必须为9位数字,如201093046;\n\n");printf(" 添加入住学生时,学生性别只能输入'男'或'女',其他输入视为无效输入!\n\n");printf(" 寝室最多入住人数为4人,添加学生到一宿舍时,该宿舍人数为4人,则提醒错误!\n\n");printf("********************************************************************* ***\n\n");main_interface();return 0;}。
学生宿舍管理软件C语言源代码
一、需求分析该程序是由C语言编写的一个宿舍管理查询软件,其主要功能是实现对学生信息的增加、删除、修改、查询、排序、存储、加载。
其中查询可以分别以姓名、学号、寝室号为关键字查询学生信息。
排序可以分别以学号和寝室号为关键字进行从小到大的排序。
①输入的形式:根据用户所选择的功能,然后再依据程序相应的提示进行输入:选择功能1(添加学生信息):按照从先到后的顺序输入学生姓名(30个字符以内),学生学号(15个字符以内),宿舍号码(整数,范围在0~32767)。
选择功能2(修改学生信息):按照从先到后的顺序输入要修改的学生姓名(30个字符以内),修改后学生的姓名(30个字符以内),修改后学生的学号(15个字符以内),修改后学生的宿舍号(整数,范围在0~32767)。
选择功能3(删除学生信息):输入要删除的学生姓名(30个字符以内)。
选择功能4(以姓名查询学生信息):输入要查找的学生的姓名(30个字符以内)。
选择功能5(以学号查询学生信息):输入要查找的学生的学号(15个字符以内)。
选择功能6(以寝室号查询学生信息):输入寝室号(整数,范围在0~32767)。
②输出的形式:根据用户所选择的功能不同,会有不同的输出:选择功能1(添加学生信息):根据程序的判断会输出添加成功或者添加失败。
选择功能2(修改学生信息):根据程序的判断会输出修改成功或者修改失败。
选择功能3(删除学生信息):根据程序的判断会输出删除成功或者删除失败。
选择功能4(以姓名查询学生信息):根据程序的判断,如果查找成功,则会输出相应的学生信息,反之,则会输出查找失败。
选择功能5(以学号查询学生信息):根据程序的判断,如果查找成功,则会输出相应的学生信息,反之,则会输出查找失败。
选择功能6(以寝室号查询学生信息):根据程序的判断,如果查找成功,则会输出相应的学生信息,反之,则会输出查找失败。
选择功能7,8(以寝室号和学号为关键字进行从小到大的排序):程序会输出排序成功。
学生宿舍管理源代码
printf("\a\a警告:您输入错误,是否重输!(y/n)");
fflush(stdin);
ch1=getchar();
system("cls");
break;
}
} //end switch
}while(ch=='n'|| ch1=='y'); //控制是否要退出系统
printf("****************************** 学生信息插入 **********************************\n");
charu(stu,count); //调用插入函数
count++;
printf("是否继续插入?(y/n)");
printf("请输入第%d个学生的信息\n");
stu[count]=shuru(); //调用输入函数
printf("是否继续(y/n)");
fflush(stdin); // 刷新标准输入缓冲区,把输入缓冲区里的东西丢弃
ch=getchar();
count++;
c=='g')
return "女";
else
return "男";
}
}stu;
/****************************主函数开始**************************/
if(choice3==1) //控制按照学号查找
{
chazhao_number(stu,count); //调用按照学号查找的函数
c语言宿舍管理
c语言宿舍管理以下是一个简单的 C 语言宿舍管理程序示例,用于管理宿舍的入住和退房记录:```c#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_HOSTS 100// 宿舍结构体struct Dorm {char name[50];int capacity;int occupied;int* roomNumbers;};// 初始化宿舍结构体void initDorm(struct Dorm* dorm) {strcpy(dorm->name, "");dorm->capacity = 0;dorm->occupied = 0;dorm->roomNumbers = NULL;}// 释放宿舍内存void freeDorm(struct Dorm* dorm) {if (dorm->roomNumbers != NULL) {free(dorm->roomNumbers);}}// 添加宿舍void addDorm(struct Dorm** head, struct Dorm* dorm) {if (*head == NULL) {*head = dorm;} else {struct Dorm* current = *head;while (current->next != NULL) {current = current->next;}current->next = dorm;}}// 打印宿舍信息void printDormInfo(struct Dorm* dorm) {printf("宿舍名称: %s\n", dorm->name);printf("容量: %d\n", dorm->capacity);printf("已入住: %d\n", dorm->occupied);}// 分配宿舍房间号void assignRoomNumbers(struct Dorm* dorm) {if (dorm->roomNumbers == NULL) {dorm->roomNumbers = (int*)malloc(dorm->capacity * sizeof(int)); }for (int i = 0; i < dorm->capacity; i++) {dorm->roomNumbers[i] = i + 1;}}int main() {struct Dorm* head = NULL;// 添加宿舍struct Dorm dorm1;initDorm(&dorm1);strcpy(, "宿舍 1"); dorm1.capacity = 10;addDorm(&head, &dorm1);struct Dorm dorm2;initDorm(&dorm2);strcpy(, "宿舍 2"); dorm2.capacity = 15;addDorm(&head, &dorm2);// 分配宿舍房间号struct Dorm* current = head;while (current != NULL) {assignRoomNumbers(current); current = current->next;}// 打印宿舍信息current = head;while (current != NULL) {printDormInfo(current);current = current->next;}// 释放内存current = head;while (current != NULL) {freeDorm(current);current = current->next;}return 0;}```这个程序创建了一个宿舍管理系统,包括添加宿舍、为宿舍分配房间号以及打印宿舍信息的功能。
C语言宿舍管理系统课设(附源码)
C语言宿舍管理系统课设项目说明本系统基于C语言开发,适用于刚入门的C语言新手项目课设,开发软件采用VC++6.0开发,VS,DEV C++等均可运行。
(书生)项目运行截图代码运行界面截图完整源码#include<stdio.h>#include<stdlib.h>#include<string.h>#define HEAD printf("\t|%-10s%-8s%-9s%-5s%-10s%-5s%-5s%-5s%-5s%-12s%-5s|\n","学号","姓名","专业","班级","公寓名","宿舍","床位","性别","年纪","手机号","级别")/*密码登录管理登录信息*/typedef struct EN{//存用户和密码char userName1[10];char passWorld1[10];}EN;void enter();void encryption(char passWorld[])//加密{int i;for(i=0;i<strlen(passWorld);i++){passWorld[i]+=20;}}void sign_in(char userName[],char passWorld[])//注册{FILE *fp;int flag=0;char userName1[10];char passWorld1[10];printf("\t注册(用户名密码最多9位)\n");printf("\t用户名:");fflush(stdin);gets(userName);printf("\t密码:");gets(passWorld);if((fp=fopen("enter.txt","rt"))==NULL){exit(0);}while(!feof(fp)){fscanf(fp,"%s %s",userName1,passWorld1);if(!strcmp(userName,userName1)){printf("用户名重复\n");flag=1;break;}}fclose(fp);if(flag==1)enter();else{if((fp=fopen("enter.txt","at"))==NULL)exit(0);encryption(passWorld);//加密fprintf(fp,"%s %s\n",userName,passWorld);}fclose(fp);enter();}void alter()//删除不合法用户{FILE *fp;int n=0;EN en[1000];。
宿舍管理系统c语言源代码
宿舍管理系统c语言源代码很荣幸能为大家提供一份宿舍管理系统的c语言源代码。
这个宿舍管理系统基于c语言编写,适用于大学宿舍管理,并比较易于使用。
下面会详细解释其代码实现以及相关功能。
首先,我们来看看该程序的主要功能。
它可以实现以下功能:添加学生信息、删除学生信息、查找学生信息、修改学生信息、查看所有学生信息、保存学生信息。
同时,它还具有输入密码、退出等功能。
来看下面的代码实现说明:首先,我们需要定义一个结构体来存储学生信息。
结构体包括以下属性:学号、姓名、性别、年龄、所在学院、所在宿舍楼、所在房间号。
typedef struct student{char num[10]; // 学号char name[10]; // 姓名char sex[10]; // 性别int age; // 年龄char department[20];// 所在学院char dormitory[20]; // 所在宿舍楼char roomnum[10]; // 所在房间号}StuInfo;接下来,我们需要定义一些函数来实现各种功能。
首先,我们需要一个函数来输入学生信息。
void InputInfo(StuInfo *p)该函数的作用是输入学生信息,参数为指向结构体StuInfo的指针。
在函数中,我们可以使用scanf函数来从控制台输入学生的各项信息。
接下来,我们需要一个函数来添加学生信息。
void AddInfo(StuInfo *p, int *n)该函数的作用是添加学生信息,参数包括指向结构体StuInfo的指针以及学生数量的指针。
在函数中,我们可以通过遍历数组来找到空位置,然后调用输入信息的函数来输入学生信息。
接下来,我们需要一个函数来删除学生信息。
void DelInfo(StuInfo *p, int *n)该函数的作用是删除学生信息,参数包括指向结构体StuInfo的指针以及学生数量的指针。
在函数中,我们可以先输入学生的学号,然后通过遍历数组来找到该学生,最后将该位置清空。
C语言宿舍管理系统课设(附源码)
C语言宿舍管理系统课设项目说明本系统基于C语言开发,适用于刚入门的C语言新手项目课设,开发软件采用VC++6.0开发,VS,DEV C++等均可运行。
(书生)项目运行截图代码运行界面截图完整源码#include<stdio.h>#include<stdlib.h>#include<string.h>#define HEAD printf("\t|%-10s%-8s%-9s%-5s%-10s%-5s%-5s%-5s%-5s%-12s%-5s|\n","学号","姓名","专业","班级","公寓名","宿舍","床位","性别","年纪","手机号","级别")/*密码登录管理登录信息*/typedef struct EN{//存用户和密码char userName1[10];char passWorld1[10];}EN;void enter();void encryption(char passWorld[])//加密{int i;for(i=0;i<strlen(passWorld);i++){passWorld[i]+=20;}}void sign_in(char userName[],char passWorld[])//注册{FILE *fp;int flag=0;char userName1[10];char passWorld1[10];printf("\t注册(用户名密码最多9位)\n");printf("\t用户名:");fflush(stdin);gets(userName);printf("\t密码:");gets(passWorld);if((fp=fopen("enter.txt","rt"))==NULL){exit(0);}while(!feof(fp)){fscanf(fp,"%s %s",userName1,passWorld1);if(!strcmp(userName,userName1)){printf("用户名重复\n");flag=1;break;}}fclose(fp);if(flag==1)enter();else{if((fp=fopen("enter.txt","at"))==NULL)exit(0);encryption(passWorld);//加密fprintf(fp,"%s %s\n",userName,passWorld);}fclose(fp);enter();}void alter()//删除不合法用户{FILE *fp;int n=0;EN en[1000];fp=fopen("enter.txt","rt");if(fp==NULL){printf("\t打开文件失败\n");exit(0);}while(!feof(fp)){fscanf(fp,"%s %s",en[n].userName1,en[n].passWorld1);n++;}//printf("大小%d\n",--n);printf("\t%-8s\t%-8s\n","用户名","密码");int i;for(i=0;i<n;i++){printf("\t%-8s\t%-8s\n",en[i].userName1,en[i].passWorld1);}fclose(fp);printf("\t输入你要删除的用户名\n");printf("\t用户名:");char ch[10];printf("\t");scanf("%s",ch);for(i=0;strcmp(ch,en[i].userName1);i++){}int k=i;for(i=k;i<n-1;i++){en[i]=en[i+1];}n--;// for(i=0;i<n;i++)// {// printf("%-8s\t%-8s\n",en[i].userName1,en[i].passWorld1); // }fp=fopen("enter.txt","wt");if(fp==NULL){printf("\t打开文件失败\n");exit(0);}for(i=0;i<n;i++){fprintf(fp,"%s %s\n",en[i].userName1,en[i].passWorld1);}fclose(fp);}void enter() //登录入口{printf("\t=================================\n");printf("\t|\t登录:\t\t\t|\n");printf("\t=================================\n");FILE *fp;int i;printf("\t1.管理员\t2.登录\n");char userName[10];char passWorld[10];char userName1[10];char passWorld1[10];int choice;printf("\t");scanf("%d",&choice);int flag=0;switch(choice){case 1:{ //管理员,注册用户和删除char adm[10];printf("\t输入权限码\n");printf("\t");scanf("%s",adm);if(strcmp(adm,"12")){printf("\t权限码错误\n");enter();}printf("\t");printf("1.注册\t2.修改\n");int j;printf("\t");scanf("%d",&j);switch(j){case 1:{sign_in(userName,passWorld);break;}case 2:{int flag1=0;do{alter();flag1=0;printf("\t是否继续删除:1.是 2.否\n");printf("\t");scanf("%d",&flag1);}while(flag1==1);enter();break;}default:{break;}}break;}case 2:{ //用户登录printf("\t登录\n");printf("\t用户名:");fflush(stdin);printf("\t");gets(userName);printf("\t密码:");printf("\t");gets(passWorld);if((fp=fopen("enter.txt","rt"))==NULL){exit(0);}while(!feof(fp)){fscanf(fp,"%s %s",userName1,passWorld1);encryption(passWorld);//加密if(!strcmp(userName,userName1)&&!strcmp(passWorld,passWorld1)) {flag=1;break;}}if(flag==0){printf("\t输入用户名密码不匹配或者错误\n");enter();}printf("\t成功\n");break;}default:{printf("输入选择不符合格式\n");break;}}}/*存储数据操作数据*/typedef struct stu{ //宿舍信息char dorm[50];int dorm_num;int dorm_num_id;char id[10];char name[10];int banji;char major[20];int age;int enUniversity;char number[12];char sex[3];struct stu *next;}stu;void print(stu *head);void interface()//主界面{printf("\n\n");printf("\t---------------------------------------------------------\n");printf("\t|\t\t欢迎使用宿舍信息管理系统\t\t|\n");printf("\t---------------------------------------------------------\n");/*数据录入*/printf("\t|\t\t\t1-录入数据\t\t\t|\n");/*数据增删改查*/printf("\t|\t\t\t2-数据增加\t\t\t|\n");printf("\t|\t\t\t3-数据删除\t\t\t|\n");printf("\t|\t\t\t4-数据修改\t\t\t|\n");printf("\t|\t\t\t5-数据查询\t\t\t|\n");/*数据统计*/printf("\t|\t\t\t6-数据统计\t\t\t|\n");/*报表*/printf("\t|\t\t\t7-数据报表\t\t\t|\n");printf("\t---------------------------------------------------------\n");}int find_id(char id[],stu *head)//学号查重,重复返回0,否则1{stu *i;for(i=head->next;i!=NULL;i=i->next){if(strcmp(id,i->id)==0){printf("\t学号重复\n");return 0;}}return 1;}int find_check(stu *head,stu *p) //检查宿舍是否满员,符合返回1,不符合返回0 {//print(head); //测试//printf("进入\n");stu *i;for(i=head->next;i!=NULL;i=i->next){if(!strcmp(p->dorm,i->dorm)&&(p->dorm_num_id==i->dorm_num_id)&&(p->do rm_num==i->dorm_num)){printf("\t宿舍信息重复\n");return 0;}}return 1;}stu *creat()//创建链表{stu *head,*end,*p;char id[10];head=NULL;head=(stu*)malloc(sizeof(stu));head->next=NULL;end=head;printf("\t输入学号:");fflush(stdin);gets(id);while(strlen(id)>0){if(find_id(id,head))//学号查重,重复返回0,否则1{p=(stu*)malloc(sizeof(stu));strcpy(p->id,id);printf("\t输入姓名:");gets(p->name);printf("\t输入公寓名称:");scanf("%s",p->dorm);printf("\t输入宿舍名称:");scanf("%d",&p->dorm_num);printf("\t输入床位号:");scanf("%d",&p->dorm_num_id);if(find_check(head,p)) //检查宿舍是否满员,符合返回1,不符合返回0{printf("\t手机号:");fflush(stdin);gets(p->number);printf("\t年龄:");scanf("%d",&p->age);printf("\t性别:");scanf("%s",p->sex);printf("\t专业班级:");scanf("%s %d",p->major,&p->banji);printf("\t输入入学年份:");scanf("%d",&p->enUniversity);end->next=p;end=p;p->next=NULL;}}printf("\t输入学号:");fflush(stdin);gets(id);}return head;}void print(stu *head)//链表打印输出{stu *i;for(i=head->next;i!=NULL;i=i->next){printf("\t|%-10s%-8s%-9s%-5d%-10s%-5d%-5d%-5s%-5d%-12s%-5d|\n",i->id,i-> name,i->major,i->banji,i->dorm,i->dorm_num,i->dorm_num_id,i->sex,i->age,i->numb er,i->enUniversity);}}stu *write_linked() //文件生成链表{FILE *fp;fp=fopen("student.txt","rt");stu *i;stu *head;head=NULL;head=(stu*)malloc(sizeof(stu));stu *end,*p;end=head;while(!feof(fp)){p=(stu*)malloc(sizeof(stu));fread(p,sizeof(stu),1,fp);fgetc(fp);end->next=p;end=p;p->next=NULL;}fclose(fp);return head;}void write_file(stu *head) //用链表,生成文件{FILE *fp;fp=fopen("student.txt","wt");stu *i;for(i=head->next;i!=NULL;i=i->next){fwrite(i,sizeof(stu),1,fp);if(i->next!=NULL)fputc('\n',fp);}fclose(fp);}void header()//数据表头{printf("\t---------------------------------------------------------------------------------\n");HEAD;printf("\t---------------------------------------------------------------------------------\n"); }void exchange_num(int *x,int *y)//交换int{int t=*x;*x=*y;*y=t;}void exchange_string(char a[],char b[])//交换字符串{char t[20];strcpy(t,a);strcpy(a,b);strcpy(b,t);}void exchange(stu *ec1,stu *ec2) //交换stu结构体类型{exchange_num(&ec1->age,&ec2->age);exchange_num(&ec1->banji,&ec2->banji);exchange_string(ec1->dorm,ec2->dorm);exchange_num(&ec1->dorm_num,&ec2->dorm_num);exchange_num(&ec1->dorm_num_id,&ec2->dorm_num_id);exchange_string(ec1->id,ec2->id);exchange_num(&ec1->enUniversity,&ec2->enUniversity);exchange_string(ec1->major,ec2->major);exchange_string(ec1->name,ec2->name);exchange_string(ec1->number,ec2->number);exchange_string(ec1->sex,ec2->sex);}void sort(stu *head) //根据公寓宿舍床位排序{stu *i,*j;for(i=head->next;i!=NULL;i=i->next){for(j=i->next;j!=NULL;j=j->next){if(strcmp(i->dorm,j->dorm)>0){exchange(i,j);}}}for(i=head->next;i!=NULL;i=i->next){for(j=i->next;j!=NULL;j=j->next){if(!strcmp(i->dorm,j->dorm)&&i->dorm_num>j->dorm_num){exchange(i,j);}}}for(i=head->next;i!=NULL;i=i->next){for(j=i->next;j!=NULL;j=j->next){if(strcmp(i->dorm,j->dorm)==0&&i->dorm_num==j->dorm_num&&i->dorm_nu m_id>j->dorm_num_id){exchange(i,j);}}}}void add(stu *head)//添加数据{stu *end;for(end=head->next;end->next!=NULL;end=end->next){}stu *p;char id[20];printf("\t输入学号:");fflush(stdin);gets(id);while(strlen(id)>0){if(find_id(id,head))//学号查重,重复返回0,否则1{p=(stu*)malloc(sizeof(stu));p->next=NULL;strcpy(p->id,id);printf("\t输入姓名:");gets(p->name);printf("\t输入公寓名称:");scanf("%s",p->dorm);printf("\t输入宿舍名称:");scanf("%d",&p->dorm_num);printf("\t输入床位号:");scanf("%d",&p->dorm_num_id);if(find_check(head,p)) //检查宿舍是否满员,符合返回1,不符合返回0{printf("\t手机号:");fflush(stdin);gets(p->number);printf("\t年龄:");scanf("%d",&p->age);printf("\t性别:");scanf("%s",p->sex);printf("\t专业班级:");scanf("%s %d",p->major,&p->banji);printf("\t输入入学年份:");scanf("%d",&p->enUniversity);end->next=p;end=p;}}printf("\t输入学号:");fflush(stdin);gets(id);}printf("\t结束\n");}void dele(stu *head)//按学号删除数据{printf("\t输入你要删除的学号:");char id[20];fflush(stdin);gets(id);stu *end1;//倒数第二个stu *i;while(strlen(id)>0){for(end1=head->next;end1->next->next!=NULL;end1=end1->next){}i=head;while((i=i->next)!=NULL){if(strcmp(id,i->id)==0){exchange(i,end1->next);free(end1->next);end1->next=NULL;sort(head);printf("\t成功\n");break;}else if(i->next==NULL){printf("\t->未找到相匹配的学号<-\n");}}printf("\t输入你要删除的学号:");gets(id);}}void modify(stu *head)//按学号修改数据{char flag[5];printf("\t输入你要修改的学号:");char id[20];char new_id[20];fflush(stdin);gets(id);stu *i;stu *k;k=(stu*)malloc(sizeof(stu));k->next=NULL;while(strlen(id)>0){i=head;while((i=i->next)!=NULL){if(strcmp(id,i->id)==0){printf("\t是否修改学号(yes/no):") ;gets(flag);if(strcmp(flag,"yes")==0){printf("\t输入修改的学号:");gets(new_id);if(find_id(new_id,head)||strcmp(id,new_id)==0){strcpy(k->id,new_id);}else{printf("\t新学号重复");break;}}else{strcpy(k->id,i->id);}printf("\t输入姓名:");gets(k->name);printf("\t输入公寓名称:");scanf("%s",k->dorm);printf("\t输入宿舍名称:");scanf("%d",&k->dorm_num);printf("\t输入床位号:");scanf("%d",&k->dorm_num_id);if(find_check(head,k)||(!strcmp(k->dorm,i->dorm)&&i->dorm_num==k->dorm_n um&&i->dorm_num_id==k->dorm_num_id)) //检查宿舍是否满员,符合返回1,不符合返回0{printf("\t手机号:");fflush(stdin);gets(k->number);printf("\t年龄:");scanf("%d",&k->age);printf("\t性别:");scanf("%s",k->sex);printf("\t专业班级:");scanf("%s %d",k->major,&k->banji);printf("\t输入入学年份:");scanf("%d",&k->enUniversity);exchange(i,k);}}else if(i->next==NULL){printf("\t->未找到相匹配的学号<-\n");}}printf("\t输入你要修改的学号:");fflush(stdin);gets(id);}free(k);}void interface1()//数据查询子界面{printf("\t\t------------------\n");printf("\t\t|1.按学号查询|\n");printf("\t\t|2.按姓名查询|\n");printf("\t\t|3.按公寓宿舍查询|\n");printf("\t\t------------------\n");}void lookup_id(stu *head)//按学号查找{char id[20];printf("\t输入学号:");fflush(stdin);gets(id);stu *i;while(strlen(id)>0){i=head;while((i=i->next)!=NULL){if(strcmp(id,i->id)==0){header();printf("\t|%-10s%-8s%-9s%-5d%-10s%-5d%-5d%-5s%-5d%-12s%-5d|\n",i->id,i-> name,i->major,i->banji,i->dorm,i->dorm_num,i->dorm_num_id,i->sex,i->age,i->numb er,i->enUniversity);printf("\t---------------------------------------------------------------------------------\n");break;}else if(i->next==NULL){printf("\t未找到相应学号\n");}}printf("\t输入学号:");fflush(stdin);gets(id);}}void lookup_name(stu *head)//按姓名查找{char name[20];printf("\t输入姓名:");fflush(stdin);gets(name);stu *i;int flag;//判断是否找到数据,1找到,0枚找到int flag1;//判断是否输出表头,1输出,0不输出flag1=1;while(strlen(name)>0){ flag=0;i=head;while((i=i->next)!=NULL){if(strcmp(name,i->name)==0){if(flag1==1){header();flag1=0;}printf("\t|%-10s%-8s%-9s%-5d%-10s%-5d%-5d%-5s%-5d%-12s%-5d|\n",i->id,i-> name,i->major,i->banji,i->dorm,i->dorm_num,i->dorm_num_id,i->sex,i->age,i->numb er,i->enUniversity);flag=1;}else if(i->next==NULL&&flag==0){printf("\t未找到相应姓名\n");}}printf("\t---------------------------------------------------------------------------------\n");printf("\n");printf("\t输入姓名:");fflush(stdin);gets(name);}}void lookup_dorm_num(stu *head)//按公寓宿舍查找{int num=0;char dorm[20];printf("\t输入公寓和宿舍号:");scanf("%s %d",dorm,&num);stu *i;int flag;//判断是否找到数据,1找到,0枚找到int flag1;//判断是否输出表头,1输出,0不输出flag1=1;while(strlen(dorm)>0&&num!=0){ flag=0;i=head;while((i=i->next)!=NULL){if(num==i->dorm_num&&strcmp(dorm,i->dorm)==0){if(flag1==1){header();flag1=0;}printf("\t|%-10s%-8s%-9s%-5d%-10s%-5d%-5d%-5s%-5d%-12s%-5d|\n",i->id,i->name,i->major,i->banji,i->dorm,i->dorm_num,i->dorm_num_id,i->sex,i->age,i->numb er,i->enUniversity);flag=1;}else if(i->next==NULL&&flag==0){printf("\t未找到相应宿舍号\n");}}printf("\t---------------------------------------------------------------------------------\n");printf("\n");num=0;printf("\t输入公寓和宿舍号:");scanf("%s %d",dorm,&num);}}void son_operation(stu *head)//查询操作选项表{printf("\t输入选项(0退出):");int choice;scanf("%d",&choice);if(choice==0){return;}switch(choice){case 1:{lookup_id(head);//按id查询break;}case 2:{lookup_name(head);//按姓名查询break;}case 3:{lookup_dorm_num(head);//按公寓宿舍查询break;}default :{printf("\t->输入格式有误<-\n");break;}}}void son_statistical()//统计操作表子目录{printf("\t\t----------------\n");printf("\t\t|1.统计总人数|\n");printf("\t\t|2.统计单个公寓|\n");printf("\t\t|3.统计公寓宿舍|\n");printf("\t\t----------------\n");}void statistical_total(stu *head)//统计总人数{stu *i;int n=0;for(i=head->next;i!=NULL;i=i->next){n++;}printf("\t->共%d人<-\n",n);}void statistical_dorm(stu *head)//统计单个公寓{int n=0;char dorm[20];printf("\t输入公寓:");fflush(stdin);gets(dorm);stu *i;while(strlen(dorm)>0){i=head;n=0;while((i=i->next)!=NULL){if(strcmp(dorm,i->dorm)==0){n++;}}printf("\t->该公寓共%d人<-\n",n);printf("\t输入公寓:");fflush(stdin);gets(dorm);}}void statistical_dorm_num(stu *head)//统计公寓宿舍{int num=0;int n;char dorm[20];printf("\t输入公寓和宿舍号:");scanf("%s %d",dorm,&num);stu *i;while(strlen(dorm)>0&&num!=0){ n=0;i=head;while((i=i->next)!=NULL){if(num==i->dorm_num&&strcmp(dorm,i->dorm)==0){n++;}}printf("\t->该宿舍工%d人<-\n",n);num=0;printf("\t输入公寓和宿舍号:");scanf("%s %d",dorm,&num);}}void statistical_operation(stu *head) //统计操作选项表{printf("\t输入选项(0退出):");int choice;scanf("%d",&choice);if(choice==0){return;}switch(choice){case 1:{statistical_total(head);//统计总人数break;}case 2:{statistical_dorm(head);//统计单个公寓break;}case 3:{statistical_dorm_num(head);//统计公寓宿舍break;}default :{printf("\t->输入格式有误<-\n");break;}}}int main(){enter();//登录system("cls");printf("\t登陆成功\n");int choice;while(1){interface();stu *head;printf("\t输入1~7:");scanf("%d",&choice);switch(choice){case 1:{//录入信息head=creat();//创建链表//print(head);write_file(head);//写入文件break;}case 2:{//增加head=write_linked();add(head);sort(head);write_file(head);break;}case 3:{ //按学号删除head=write_linked();dele(head);write_file(head);break;}case 4:{//改按学号head=write_linked();modify(head);write_file(head);break;}case 5:{//查,按姓名,宿舍,学号interface1();//子目录head=write_linked();son_operation(head);break;}case 6:{ //统计,总人数,每个宿舍人数,一个楼人数head=write_linked();son_statistical();statistical_operation(head);//statistical_date();break;}case 7:{//报表head=write_linked();header();sort(head);print(head);printf("\t---------------------------------------------------------------------------------\n");break;}default :{//system("cls");printf("\t->输入有误,重新输入<-\n");break;}}printf("\t按任意键继续");fflush(stdin);getchar();system("cls");}}。
学生宿舍管理软件C语言源代码(完整版)
getchar();
printf(请输入学生班级(30个字符以内):”);
scanf("%s",S[flag].S_class);
getchar();
printf("请输入学生的学号(15个字符以内):");
scanf( "%s" ,S[flag].S_number);
printf(请输入学生电话号码:”;
scanf("%s",&S[flag]. S_phone);
getchar();
dirty=1;
printf("修改成功!\n");
}
putchar( '\n');
}
//删除学生信息
void Delete(Student S)
{
int i,j;
int flag=0; //用来判断表中是否存在所要删除的学生的信息
scanf( "%d",&S[S->Total].D_number);
getchar();
printf("请输入学生地址:");
scanf("%s",S[S->Total].S_address);
getchar();
printf(请输入学生电话号码:”;
scanf("%s",&S[S->Total]. S_phone);
char S_class[31];//学生班级
char S_number[16];//学生学号
int D_number;//学生所在寝室的宿舍号char S_address[500];//学生地址
宿舍管理系统(c语言版)
{ printf("\t\t输入的操作代码无效,请重新输入:");
fflush(stdin);
choice=getchar();
}*/
}
void display() /*显示所有学生的信息*/
{ printf("文件读取失败!\n");
return;
}
printf("\t%-10s\t%-10s\t%-5s\n","姓名","学号","宿舍号");
bound();
while(fread(sturecord,sizeof(STU),1,fp)!=0)
{
printf("\t%-10s",sturecord->stuname);
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
void menu(); /*主菜单*/
void searchmenu(); /*查询菜单*/
void search(); /*查询系统*/
{
STU *sturecord;
sturecord=(STU*)malloc(sizeof(STU));
if(check()==0)
return;
system("cls");
sort_stunum();
C语言——学生宿舍管理系统
int i=0;
char ch;
system("cls");
do{ if(i<num)
{
printf("输入第%(个学生的宿舍号:",i+1);
scanf("%d",&stu[i].dorNo) ;
printf("\n姓名:");
scanf("%s",&stu[i].stuName);
printf("\n学号:");scanf("%d",&stu[i].stuNo);
//增加学生信息
void add(struct Student *,int);
//全局变量来记录存储学生的人数int num=0;
//主函数
int main()
{ห้องสมุดไป่ตู้
char ch[10];
printf(" \t欢迎进入宿舍管理系统\n");
printf("请输入你想存储的学生人数:") ;
scanf("%d",&num); system("cls");
//按姓名查找
void naSeek(struct Student *,int);
//按系别查找
void deSeek(struct Student *,int);
//删除学生信息void del(struct Student *,int);
//修改学生信息
void modify(struct Student *,int);
printf(" \t1. printf("\t2.
C语言学生宿舍管理系统代码(可运行)
C语⾔学⽣宿舍管理系统代码(可运⾏)#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<string.h>#include<windows.h>#include <malloc.h>#include<dos.h>#define len sizeof(struct dorminfo)#define Max 100int a[Max]={0};int length;void showmenu();void processmenu();void create();void display();void disbed();void modify();void del();void save();void read();typedef struct{int dormno;int bedno;int isstay;}bedinfo;struct dorminfo{bedinfo bed;int stuno;char name[20];char stucla[20];int year;int month;struct dorminfo *next;};struct dorminfo *head=NULL,*p1,*p2,*p3;void showmenu(){printf("\n\n\n\t\t 欢迎进⼊学⽣宿舍管理系统\n");printf("\t\t*********************************\n");printf("\t\t1.输⼊床位信息\n");printf("\t\t2.根据学号,显⽰学⽣住宿信息\n");printf("\t\t3.根据宿舍号,显⽰住宿信息\n");printf("\t\t4.根据宿舍号、床位号,修改住宿信息\n");printf("\t\t5.根据宿舍号、床位号,删除住宿信息\n");printf("\t\t6.保存学⽣宿舍信息\n");printf("\t\t7.从⽂件读⼊学⽣信息\n");printf("\t\t8.退出 \n");printf("\t\t********************************\n") ;}void processmenu(){int caidan;printf("请输⼊您的选项<1~8>:");scanf("%d",&caidan);if(caidan>8||caidan<0){printf("对不起,您输⼊的选项有误,请重新输⼊!");scanf("%d",&caidan);}switch(caidan){case 2:display();break;case 3:disbed();break;case 4:modify();break;case 5:del();break;case 6:save();break;case 7:read();break;case 8:exit(0);}}void create(){int j;char ch;length=0;p1=(struct dorminfo *)malloc(len);if(head==NULL)head=p1;printf("开始输⼊床位信息....\n");Sleep(500);do{p2=(struct dorminfo *)malloc(len);printf("请输⼊宿舍号:");scanf("%d",&p2->bed.dormno);printf("请输⼊床号:");scanf("%d",&p2->bed.bedno);printf("是否有⼈居住(1/0):");scanf("%d",&p2->bed.isstay);printf("请输⼊学⽣学号:");scanf("%d",&p2->stuno);a[length]=p2->stuno;if(length>1){for(j=1;j<length;j++){if(a[length]==a[j]){printf("该床位号已存在,请重新输⼊:");scanf("%d",&p2->bed.bedno);}}}printf("请输⼊学⽣姓名:");scanf("%s",p2->name);printf("请输⼊学⽣班级:");scanf("%s",p2->stucla);printf("请输⼊学⽣⼊住时间(年⽉)<如2015 5>:");scanf("%d%d",&p2->year,&p2->month);if(p2->year<1000||p2->year>9999||p2->month>12||p2->month<1) {printf("对不起,输⼊错误,请重新输⼊!\n");scanf("%d%d\n",&p2->year,&p2->month);}length++;p1->next=p2;p2->next=NULL;p1=p1->next;printf("第%d个住宿信息创建成功!\n",length);Sleep(300);fflush(stdin);printf("是否继续添加住宿信息?<y/Y>");ch=getchar();} while(ch=='y'||ch=='Y');}void display(){int flag=0,No;p3=head->next;scanf("%d",&No);while(p3!=NULL){if(p3->stuno==No){printf("\n住宿信息如下:");printf("\n宿舍号:%d",p3->bed.dormno);printf("\n床位号:%d",p3->bed.bedno);printf("\n是否有⼈⼊住:%d",p3->bed.isstay);printf("\n学⽣学号:%d",p3->stuno);printf("\n学⽣姓名:%s",p3->name);printf("\n学⽣班级:%s",p3->stucla);printf("\n⼊住时间为:%d年%d⽉\n",p3->year,p3->month); flag=1;}p3=p3->next;}if(!flag)printf("没有找到该学⽣住宿信息!\n");}void disbed(){int flag=0,DormNo;p3=head->next;printf("请输⼊宿舍号:");scanf("%d",&DormNo);while(p3!=NULL){if(p3->bed.dormno==DormNo){printf("\n住宿信息如下:");printf("\n宿舍号:%d",p3->bed.dormno);printf("\n床位号:%d",p3->bed.bedno);printf("\n是否有⼈⼊住:%d",p3->bed.isstay);printf("\n学⽣学号:%d",p3->stuno);printf("\n学⽣姓名:%s",p3->name);printf("\n学⽣班级:%s",p3->stucla);printf("\n⼊住时间为:%d年%d⽉\n",p3->year,p3->month); flag=1;}p3=p3->next;}if(!flag)printf("没有找到该学⽣住宿信息!\n");}void modify(){struct dorminfo *p;int DormNo,BedNo,flag;int Dormno,Bedno,Isstay,Stuno,Year,Month;char Name[20],Stucla[20];if(head==NULL){printf("住宿信息为空,不能修改,按任意键返回...\n");getch();system("cls");return ;}p1=p3=head;printf("请输⼊宿舍号、床位号:");scanf("%d %d",&DormNo,&BedNo);while(p3!=NULL){if(p3->bed.dormno==DormNo&&p3->bed.bedno==BedNo) {printf("已找到要修改的宿舍号、床位号!\n");flag=1;p=p3;}p3=p3->next;}if(flag){printf("请输⼊修改后的宿舍号:");scanf("%d",&Dormno);printf("请输⼊修改后的床号:");scanf("%d",&Bedno);printf("是否有⼈居住(1/0):");scanf("%d",&Isstay);printf("请输⼊修改后的学⽣学号:");scanf("%d",&Stuno);while(p1!=NULL){if(p1->stuno==Stuno){printf("该床位号已存在,请重新输⼊:");scanf("%d",&Stuno);}p1=p1->next;}printf("请输⼊修改后的学⽣姓名:");scanf("%s",Name);printf("请输⼊修改后的学⽣班级:");scanf("%s",Stucla);printf("请输⼊修改后的学⽣⼊住时间(年⽉)<如2015 5>:");scanf("%d%d",&Year,&Month);if(Year<1000||Year>9999||Month>12||Month<1){printf("对不起,输⼊错误,请重新输⼊!\n");scanf("%d%d",&Year,&Month);}p->bed.dormno=Dormno;p->bed.bedno=Bedno;p->bed.isstay=Isstay;p->stuno=Stuno;strcpy(p->name,Name);strcpy(p->stucla,Stucla);p->year=Year;p->month=Month;printf("修改成功,信息如下:\n");printf("-宿舍号--床号--有⽆⼈⼊住--学号--姓名--班级--⼊住时间(年⽉)");printf("\n");printf("%6d%5d%8d%9d%7s%8s%9d%2d\n",p->bed.dormno,p->bed.bedno,p->bed.isstay,p->stuno,p->name,p->stucla,p->year,p->month); }else{printf("没有找到该宿舍号与床号信息,按任意键返回...\n");getch();system("cls");return ;}}void del(){int DormNo,BedNo;p1=head,p2=head->next;printf("请输⼊宿舍号、床位号:");scanf("%d %d",&DormNo,&BedNo);while(p2!=NULL){if(p2->bed.dormno==DormNo&&p2->bed.bedno==BedNo){p1->next=p2->next;free(p2);length--;printf("删除成功!\n");return ;}p2=p2->next;p1=p1->next;}if(p1==NULL)printf("找不到要删除的宿舍号、床位号!\n");}void save(){FILE *fp1;if(head==NULL){printf("\n,没有找到该宿舍号与床号信息,按任意键返回....");getch();system("cls");return ;}if((fp1=fopen("学⽣宿舍管理系统.txt","w"))==NULL){printf("\n信息⽆法保存,按任意键返回....");getch();system("cls");return ;}p1=head->next;printf("正在保存⽂件...\n");Sleep(800);fputs(" 宿舍号床号有⽆⼈⼊住学号姓名班级⼊住时间(年⽉) :\n",fp1);while(p1!=NULL){fprintf(fp1,"%6d%5d%8d%7d%6s%4s%7d%2d\n",p1->bed.dormno,p1->bed.bedno,p1->bed.isstay,p1->stuno,p1->name,p1->stucla,p1->year,p1->month);p1=p1->next;}fclose(fp1);printf("⽂件保存成功!\n");printf("按任意键返回...\n");getch();system("cls");return ;}void read(){FILE *fp2;char ch;if((fp2=fopen("学⽣宿舍管理系统.txt","r"))==NULL){printf("⽂件⽆法打开!\n");exit(0);}printf("正在读⼊⽂件...\n");Sleep(1000);ch=fgetc(fp2);while(!feof(fp2)){putchar(ch);ch=fgetc(fp2);}printf("\n");fclose(fp2);printf("⽂件读⼊成功!\n");}void main(){while(1){processmenu(); system("pause"); system("cls");}}。
宿舍管理系统源代码
#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct Student{char name[20];char sex[5];int age;char institute[20];char specialty[30]; }Student;typedef struct Room{int roomnum;int roomarea;int totalnum;int stunum;Student stu[10];Room *next; }Room;typedef struct Story{char storynum;Room *room;}Story;/* -------------------------------------------------------------- */Student *StudentCreat(int age,char name[],char institute[],char specialty[],char sex[]){Student *Stu;Stu=(Student *)malloc(sizeof(Student));Stu->age=age;strcpy(Stu->institute,institute); strcpy(Stu->name,name);strcpy(Stu->specialty,specialty); strcpy(Stu->sex,sex);return Stu;}Room *RoomCreat(int room_num,int room_area,int total_num,int stu_num) {Room *R;int i;R=(Room *)malloc(sizeof(Room));if(!R)return NULL;R->roomnum=room_num;R->roomarea=room_area;R->totalnum=total_num;R->stunum=stu_num;R->next=NULL;return R;}Story *StoryCreat(){Story *S;S=(Story *)malloc(sizeof(Story));S->room=RoomCreat(0,0,0,0);return S;}Story *DormCreat(){Story *S,*control;char i;control=(Story *)malloc(26*sizeof(Story)); if(!control)return NULL;for(i='A';i<='Z';i++){S=StoryCreat(); S->storynum=i; control[i-'A']=*S;}return control;}/* -------------------------------------------------------------- */Story *StorySearch(Story *control,char storynum){return control+(storynum-'A');}Room *RoomSearch(Room *R,int room_num){while(R->next!=NULL){ if(R->next->roomnum==room_num)break; else R=R->next;}return R;}Student *StudentSearch(Room *R,char name[]){Student *p;int i;R=R->next; p=R->stu;for(i=0;i<R->stunum;i++){ if(strcmp(p->name,name)==0)return p; else p++;}return NULL;}/* -------------------------------------------------------------- */void RoomInsert(Story *S,Room *R){R->next=S->room->next; S->room->next=R;}void StudentInsert(Room *R,Student *Stu){R=R->next;R->stu[R->stunum]=*Stu;R->stunum++;}void RoomDelete(Room *R){Room *p;R=R->next;p=R;R=R->next;free(p);}void StudentDelete(Room *R,Student *Stu){R=R->next;Student *p; for(p=R->stu;Stu<p+R->stunum-1;Stu++)*Stu=*(Stu+1);R->stunum--;}void RoomRevamp(Room *R){int i,k;R=R->next;printf("1 、房号 2 、面积 3 、可容纳人数 :\n");printf(" 要修改那一项 :\n");scanf("%d",&i); switch(i)case 1:{ printf(" 房号 :"); scanf("%d",&k); R->roomnum=k; break;}case 2:{ printf(" 面积 :"); scanf("%d",&k); R->roomarea=k; break;}case 3:{ printf(" 可容纳人数 :"); scanf("%d",&k); R->totalnum =k;break;}}}void StudentRevamp(Student *Stu){int i,k;char str[30];printf("1 、姓名 2 、性别 3 、学院 4 、专业 5 、年龄 :\n");printf(" 要修改那一项 :\n");scanf("%d",&i); switch(i){case 1:{printf(" 姓名 :");scanf("%s",str); strcpy(Stu->name,str); break;}case 2:{printf(" 性别 :");scanf("%s",str); strcpy(Stu->sex,str);break;}case 3:{printf(" 学院 :");scanf("%s",str); strcpy(Stu->institute,str); break;}case 4:{printf(" 专业 :");scanf("%s",str); strcpy(Stu->specialty,str); break;}case 5:{printf(" 年龄 :");scanf("%d",&k);Stu->age =k;break;}}/* ------------------------------------------- ------------------- */void RoomScan(Room *R){int i;Student*p;R=R->next;printf(" 房号:%d\n",R->room nu m);printf(" 面积:%d\n",R->roomarea);printf(" 可容纳人数 :%d\n",R->totalnum);printf(" 已住入人数 :%d\n",R->stunum);printf(" 成员:");for(i=0;i<R->stunum;i++){p=&(R->stu[i]);printf("%s ",p->name);}putchar('\n');}void StudentScan(Student *Stu){printf(" 姓名 :%s\n",Stu->name);printf(" 年龄 :%d\n",Stu->age);printf(" 性别 :%s\n",Stu->sex);printf("学院 :%s\n",Stu->institute);printf("专业 :%s\n",Stu->specialty);}int main(){int roomnum,roomarea,totalnum,stunum,age;int event;char name[20],institute[20],specialty[30],sex[5];char storynum,judge;Story *control;Story *S;Room *R;Student *Stu;control=DormCreat();do{printf(" **************************************************************\n");*\n");*\n");f*************************************************************宿舍管理系统\n\n\n");printf (" 功能选择菜单 :\n");printf ("1 、宿舍信息录入 2 、学生信息录入 3 、删除某个宿舍 4 、删 除某个学生 \n");printf("5 、宿舍信息浏览 6 、学生信息浏览 7 、宿舍信息修改 8 、学 生信息修改 \n");scanf("%d",&event);、,I • 、、printf("*先录入宿舍信息才能录入学生信息 printf("* 先录入信息才能删除浏览或修改信息 printf("*** **\n"); printf("\n\n\nswitch(event){case 1:{do{printf(" 请输入宿舍房间号,房间面积,可容纳人数,已住入人数 :( 以空格隔开 )\n");fflush(stdin);scanf("%c%d %d%d%d",&storynum,&roomnum,&roomarea,&totalnum,&stunum);S=StorySearch(control,storynum);R=RoomCreat(roomnum,roomarea,totalnum,stunum); RoomInsert(S,R);printf(" 宿舍信息录入成功! \n");fflush(stdin);printf(" 是否继续录入宿舍信息 (Y/N)\n");scanf("%c",&judge);}while(judge=='Y'); break;}case 2:{do{printf(" 请输入该生要入住的宿舍 :\n"); fflush(stdin);scanf("%c%d",&storynum,&roomnum); fflush(stdin);S=StorySearch(control,storynum); R=S->room;R=RoomSearch(R,roomnum);printf(" 请输入该生姓名,性别,学院,专业,年龄 :( 以空格隔开 )\n");scanf("%s%s%s%s",name,sex,institute,specialty); scanf("%d",&age);Stu=StudentCreat(age,name,institute,specialty,sex);StudentInsert(R,Stu);printf(" fflush(stdin); printf("scanf("%c",&judge);}while(judge=='Y');break;break;do { printf(" 请输入要删除的宿舍号码 :\n"); fflush(stdin); scanf("%c%d",&storynum,&roomnum); fflush(stdin); S=StorySearch(control,storynum); R=S->room; R=RoomSearch(R,roomnum); RoomDelete(R); printf(" 宿舍信息删除成功! \n"); fflush(stdin); printf(" 是否继续删除宿舍信息 (Y/N)\n"); scanf("%c",&judge); }while(judge=='Y'); break; break;do{printf(" 请输入要删除学生现住宿舍 :\n"); fflush(stdin); scanf("%c%d",&storynum,&roomnum); fflush(stdin); S=StorySearch(control,storynum);R=S->room;R=RoomSearch(R,roomnum);printf(" 请输入要删除学生的姓名 :\n");scanf("%s",name);Stu=StudentSearch(R,name);StudentDelete(R,Stu);printf(" 学生信息删除成功! \n"); } case 3: {}case 4:{ 学生信息录入成功! \n"); 是否继续录入学生信息 (Y/N)\n");fflush(stdin);printf(" 是否继续删除学生信息(Y/N)\n");scanf("%c",&judge);}while(judge=='Y');break;break;}case 5:{do{printf(" 请输入要浏览的宿舍号码 :\n");fflush(stdin);scanf("%c%d",&storynum,&roomnum);fflush(stdin);S=StorySearch(control,storynum);R=S->room;R=RoomSearch(R,roomnum);RoomScan(R);fflush(stdin);printf(" 是否继续浏览宿舍 (Y/N)\n");scanf("%c",&judge);}while(judge=='Y');break;break;}case 6:{do{printf(" 请输入要浏览学生的宿舍号码:\n");fflush(stdin);scanf("%c%d",&storynum,&roomnum);fflush(stdin);S=StorySearch(control,storynum);R=S->room;R=RoomSearch(R,roomnum);printf(" 请输入要浏览学生的姓名 :\n");scanf("%s",name);Stu=StudentSearch(R,name);StudentScan(Stu);fflush(stdin);printf(" 是否继续浏览学生 (Y/N)\n");scanf("%c",&judge);}while(judge=='Y');break;break;}case 7:{do{printf(" 请输入要修改的宿舍号码 :\n");fflush(stdin);scanf("%c%d",&storynum,&roomnum);fflush(stdin);S=StorySearch(control,storynum);R=S->room;R=RoomSearch(R,roomnum);RoomRevamp(R);printf(" 宿舍信息修改成功! \n");fflush(stdin);printf(" 是否继续修改 (Y/N)\n");scanf("%c",&judge);}while(judge=='Y');break;break;}case 8:{do{printf(" 请输入要修改学生的宿舍号码:\n");fflush(stdin); scanf("%c%d",&storynum,&roomnum);fflush(stdin);S=StorySearch(control,storynum);R=S->room;R=RoomSearch(R,roomnum);printf(" 请输入要修改学生的姓名 :\n");scanf("%s",name);Stu=StudentSearch(R,name);StudentRevamp(Stu);printf(" 学生信息修改成功! \n");fflush(stdin);printf(" 是否继续修改 (Y/N)\n");scanf("%c",&judge);}while(judge=='Y');break;break;}}fflush(stdin);printf(" 是否继续其他操作 (Y/N)\n");scanf("%c",&judge);}while(judge=='Y');system("pause");}欢迎您的下载,资料仅供参考!致力为企业和个人提供合同协议,策划案计划书,学习资料等等打造全网一站式需求。
学生宿舍管理系统源代码
数据结构课程设计源代码设计题目:学生宿舍管理系统院系:计算机学院班级:软件1501组别:六组长:周佳理组员: 韩壮壮陈义安起止日期: 2016年12月20日~2016年12月24日指导教师:韩丽娜源代码:#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>void AppendNode(long studentID, char studentName[15], char roomNumber[4], char bedNumber[4]);//向链表中添加数据void DisplayNode(struct link *head);//打印链表中数据void Display(struct link *head);//表头格式控制void DeleteMemory(struct link *head);//删除链表所占用的内存void Save();//保存数据void Open();//打开数据void FindID();//按学号查找学生void FindName();//按姓名查找学生void InsertNodeNumber(long studentID, char studentName[15], char roomNumber[4], char bedNumber[4]);//按学号从小到大排序void NumberSorting();//排序void Menu();//菜单控制模块功能代码://主函数int main(){long studentID;char studentName[15];char roomNumber[4];char bedNumber[4];//定义要输入学生信息的变量;char c;int menu;//保存要进行的选项;while (1) {system("pause");Menu();printf("请输入要进行的操作:");scanf("%d", &menu);switch (menu) {case 0:exit(0); break;case 1:printf("请输入Y或y来添加数据\n");scanf(" %c", &c);while (c == 'y' ||c == 'Y') {printf("请输入学生学号:");scanf("%lld", &studentID);printf("请输入学生姓名:");scanf("%s", &studentName);printf("请输入房间号:");scanf("%s", &roomNumber);printf("请输入床位号:");scanf("%s", &bedNumber);AppendNode(studentID, studentName, roomNumber, bedNumber);printf("请输入Y或y来添加数据\n");scanf(" %c", &c);}Display(head); break;case 2:FindID(); break;case 3:FindName(); break;case 4:Display(head);//显示信息break;case 5:NumberSorting();Display(head1);//排序后的学生信息head1 = NULL; break;case 6:Save(); break;case 7:Open(); break;default:printf("输入有误!请重新输入"); break;}}DeleteMemory(head);DeleteMemory(head1);system("pause");return 0;}//菜单void Menu() {system("cls");//清屏操作;printf("\n\n\n\n\n");printf("\t\t|.......学生宿舍管理系统..............|\n");printf("\t\t|\t 0.退出|\n");printf("\t\t|\t 1.添加学生住宿信息|\n");printf("\t\t|\t 2.查找学生(按学号)信息|\n");printf("\t\t|\t 3.查找学生(按姓名)信息|\n");printf("\t\t|\t 4.显示学生信息|\n");printf("\t\t|\t 5.按学号排序|\n");printf("\t\t|\t 6.保存信息|\n");printf("\t\t|\t 7.打开信息|\n");printf("\t\t|.......学生宿舍管理系统..............|\n");}//表头格式控制void Display(struct link *head) {printf("-----------------------------------------------------------\n");printf(" 学号姓名宿舍号床号\n");printf("-----------------------------------------------------------\n");DisplayNode(head);}数据模块功能代码://定义结构体typedef struct student {long studentID; //学号char studentName[15];//姓名char roomNumber[4];//房间号char bedNumber[4];//床号}STU;//初始化链表struct link {STU student;struct link *next;};struct link *head = NULL;//保存输入的学生信息数据struct link *head1 = NULL;//保存排序后的学生信息数据//添加数据void AppendNode(long studentID, char studentName[15], char roomNumber[4], char bedNumber[4]) { struct link *p = NULL, *pr = head;p = (struct link *) malloc(sizeof(struct link));if (p == NULL) {printf("申请内存失败"); return;}if (head == NULL) {head = p;}else {while (pr->next != NULL) {pr = pr->next;}pr->next = p;}p->student.studentID = studentID;strcpy(p->student.studentName, studentName);strcpy(p->student.roomNumber, roomNumber);strcpy(p->student.bedNumber,bedNumber);p->next = NULL; return;}//打印数据void DisplayNode(struct link *head) {struct link *p = head;if (p == NULL) {return;}printf("%lld%15s%13s%13s",p->student.studentID,p->student.studentName,p->student.roomNumber, p->student.bedNumber);printf("\n"); p=p->next; DisplayNode(p);}//保存链表中的数据void Save() {FILE *fp;struct link *p = head;fp = fopen("demo.txt", "w");if (fp== NULL) {printf("打开文件失败"); return;}while (p != NULL) {fprintf(fp,"%20lld%15s%5s%4s", p->student.studentID, p->student.studentName, p->student.roomNumber,p->student.bedNumber);p = p->next;}fclose(fp); return;}//将文件中获得的数据写入到链表中void Open() {fflush(stdin);fflush(stdout);long studentID;char studentName[15];char roomNumber[4];char bedNumber[4];FILE *fp; char c;fp = fopen("demo.txt", "a+");if (fp== NULL) {printf("文件打开失败"); return;}while ((c = fgetc(fp))!=EOF) {fscanf(fp, "%20lld", &studentID);fscanf(fp, "%15s", studentName);fscanf(fp, "%5s", roomNumber);fscanf(fp,"%4s",bedNumber);AppendNode(studentID, studentName, roomNumber, bedNumber);}fclose(fp);}功能模块功能代码://排序函数void NumberSorting() {struct link *p = head;struct link *p1 = head1;int sum = 0;if(p == NULL) {printf("没有数据,无法排序"); return;}while (p!=NULL) {InsertNodeNumber(p->student.studentID,p->student.studentName,p->student.roomNumber, p->student.bedNumber);p = p->next;}}//按学号的从小到大排序void InsertNodeNumber(long studentID, char studentName[15], char roomNumber[4], char bedNumber[4]) {struct link *pr = head1, *p = head1, *temp = NULL;p = (struct link *)malloc(sizeof(struct link));if (p == NULL) {printf("内存申请失败"); return;}p->next = NULL;p->student.studentID = studentID;strcpy(p->student.studentName, studentName);strcpy(p->student.roomNumber, roomNumber);strcpy(p->student.bedNumber,bedNumber);if (head1 == NULL) {head1 = p;}else {while (pr->student.studentID < studentID&&pr->next != NULL) { temp = pr; pr = pr->next;}if (pr->student.studentID >= studentID) {if (pr == head1) {p->next = head1; head1 = p;}else {pr = temp; p->next = pr->next; pr->next = p;}}else {pr->next = p;}}}//删除链表所占用的内存void DeleteMemory(struct link *head) {struct link *p = head, *pr = NULL;while (p != NULL) {pr = p; p = p->next; free(pr);}}//按学号查找学生void FindID() {struct link *p = head;long studentID=0;if (head == NULL) {printf("没有数据查找"); return;}printf("请输入你要查找的学生的学号:");scanf("%lld", &studentID);while (studentID != p->student.studentID&&p->next != NULL) {p = p->next;}if (p->student.studentID == studentID) {printf("-----------------------------------------------------------\n");printf(" 学号姓名宿舍号床号\n");printf("-----------------------------------------------------------\n");printf("%lld%15s%13s%13s", p->student.studentID, p->student.studentName, p->student.roomNumber, p->student.bedNumber);;}else {printf("没有你要查找的数据");} return;}//按姓名查找学生void FindName() {struct link *p = head;char studentName[15] = "";if (head == NULL) {printf("没有数据查找"); return;}printf("请输入你要查找的学生的姓名:");scanf("%s", studentName);while (0!=strcmp(studentName,p->student.studentName)&&p->next != NULL) {p = p->next;}if (0==strcmp(studentName,p->student.studentName)) {printf("-----------------------------------------------------------\n");printf(" 学号姓名宿舍号床号\n");printf("-----------------------------------------------------------\n");printf("%lld%15s%13s%13s",p->student.studentID,p->student.studentName,p->student.roomNumber,p->student.bedNumber);}else {printf("没有你要查找的数据");} return;}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
scanf( "%s" ,S[flag].S_name);_name);getchar(); _class); getchar();printf( " 请输入学生的学号 (15个字符以内 ):" ); scanf( "%s" ,S[S->Total].S_number); getchar();S_number_Judge(S,S->Total);_number); getchar();printf(" 请输入学生地址 :"); scanf("%s",S[S->Total].S_address); getchar();printf( “请输入学生电话号码 : ”); scanf("%s",&S[S->Total]. S_phone); getchar(); dirty=1;printf( " 添加成功 !\n\n" );_name,name)==0)flag=i;if (!flag)printf( else" 你所要修改的学生信息在表中不存在! \n" ); printf( printf(" 新信息如下 :\n" );" 请输入学生姓名 (30个字符以内 ):" );getchar();printf( “请输入学生班级 (30 个字符以内 ): ”); scanf("%s",S[flag].S_class);getchar();源程序代码:int dirty=0; _number,S[t].S_number)==0)printf( "学号输入失败 , 该学号已存在 ,请重新输入学号 !\n" );printf( "请输入学生的学号 (15 个字符以内 ):" );getchar(); i=1;#include <> #include <> #include <> #define M 100scanf("%s",S[t].S_number);}_number>S[j].D_number){strcpy(name,S[i].S_name); strcpy(number,S[i].S_number);printf( " 请输入学生的学号 (15个字符以内 ):" ); scanf( "%s" ,S[flag].S_number); getchar();S_number_Judge(S,flag); printf( " 请输入宿舍号 :" ); scanf( "%d",&S[flag].D_number); getchar();printf(" 请输入学生地址 :"); scanf("%s",S[flag].S_address); getchar(); 请输入学生电话号码 : ”);printf(scanf("%s",&S[flag]. S_phone);getchar(); dirty=1;printf( " 修改成功 !\n" ); }putchar( '\n' );_name,name)==0)flag=i;if (!flag)printf( " 你所要删除的学生在表中不存在! ");elsefor (i=flag;i<S->Total;i++)j=i+1;strcpy(S[i].S_name,S[j].S_name); strcpy(S[i].S_number,S[j].S_number); S[i].D_number=S[j].D_number;(S->Total)--; dirty=1;printf( " 删除成功 !" );}printf( "\n\n");_name,S[i].S_class,S[i].S_number,S[i].D_number ,S[i].S_address,S[i].S_phone );putchar( '\n\n');strcpy(address,S[i].S_address);strcpy(Cnumber,S[i].S_class);t=S[i].D_number;strcpy(S[i].S_name,S[j].S_name);strcpy(S[i].S_number,S[j].S_number);strcpy(S[i].S_address,S[j].S_address);;strcpy(S[i].S_class,S[j].S_class);S[i].D_number=S[j].D_number;strcpy(S[j].S_name,name);strcpy(S[j].S_number,number);strcpy(S[j].S_address,address);strcpy(S[j].S_class,Cnumber);S[j].D_number=t;}_number,S[j].S_number)>0)strcpy(name,S[i].S_name);strcpy(number,S[i].S_number);strcpy(address,S[i].S_address);strcpy(Cnumber,S[i].S_class);t=S[i].D_number;strcpy(S[i].S_name,S[j].S_name);strcpy(S[i].S_number,S[j].S_number);strcpy(S[i].S_address,S[j].S_address);;strcpy(S[i].S_class,S[j].S_class);S[i].D_number=S[j].D_number;strcpy(S[j].S_name,name);strcpy(S[j].S_number,number);strcpy(S[j].S_address,address);strcpy(S[j].S_class,Cnumber);S[j].D_number=t;_class,S[j].S_class)>0){strcpy(name,S[i].S_name);strcpy(number,S[i].S_number);strcpy(address,S[i].S_address);t=S[i]. D_number;strcpy(S[i].S_name,S[j].S_name);strcpy(S[i].S_number,S[j].S_number);strcpy(Cnumber,S[i].S_class);strcpy(S[i].S_address,S[j].S_address);;}else if (strcmp(number,S[mid].S_number)>0)strcpy(S[i].S_class,S[j].S_class);S[i]. D_number =S[j]. D_number; strcpy(S[j].S_name,name); strcpy(S[j].S_number,number);strcpy(S[j].S_address,address); strcpy(S[j].S_class,Cnumber);S[j]. D_number =t;_class)==0)printf("%-20s%-20s %-15s%-5d%s-10%s\n",S[i].S_name,S[i].S_class,S[i].S_number,S[i].D_number,S[i].S_address,S[i].S_phone);j=1;}if(!j)printf ("\n 查找失败 , 表中不存在该学生的信息 !\n\n");_name)==0)printf( "%-20s%-20s %-15s%-5d %s-10%s\n" ,S[i].S_name,S[i].S_class, S[i].S_number,S[i].D_number ,S[i].S_address,S[i].S_phonej=1;if (!j )printf ( "\n 查找失败 , 表中不存在该学生的信息 !\n\n" );_number)>=0&&strcmp(number,S[S->Total].S_number)<=0)while (base<=top)mid=(base+top)/2;if (strcmp(number,S[mid].S_number)==0)printf( "%-20s%-20s%-15s%-5d%s-10%s\n" ,S[i].S_name,S[i].S_class, S[i].S_number,S[i].D_number ,S[i].S_address,S[i].S_phone );putchar( '\n' ); j=1; break ;base=mid+1;elsetop=mid-1;);}(!j)printf( "\n 查找失败 , 表中不存在该学生的信息 !\n\n" );}_number&&i<=S[S->Total].D_number)while (base<=top){mid=(base+top)/2;m=mid;n=mid-1;while (S[m].D_number==i){printf( "%-20s%-20s %-15s%-5d %s-10%s\n" ,S[m].S_name,S[i].S_class, S[m].S_number,S[m].D_number ,S[i].S_address,S[i].S_phonem++;if (m>S->Total)break ;while (S[n].D_number==i){printf( "%-20s%-15s%-5d\n" ,S[n].S_name,S[n].S_number,S[n].D_number);n--;break ;base=mid+1; elsetop=mid-1;}if (!j)printf( "\n 查找失败 , 表中不存在该寝室的信息 !\n\n" );if if (i==S[mid].D_number));if (n>0)if (n<1)break ;j=1;putchar( '\n' );else if (i>S[mid].D_number)int i; Student S; S->Total=0; doMenu();printf( "请选择所要实现的功能 (请输入 1~14中的任意一个数字 ):" ); scanf( "%d",&i); getchar(); // 获取换行符 putchar( '\n' );switch (i) case 1:Add(S);break ;case 2:Alter(S);break ;case 3:Delete(S);break ;case 4:Query_S_name(S);break ;case 5:Query_S_number(S);break ;case 6:Query_D_number(S); break ; case 7: Query_S_class (S);break;case 8: Sort_S_class (S);printf(" 排序完成 !\n\n"); break;case 9:Sort_D_number(S);printf( " 排序完成 !\n\n" ); break ;加学生信息|8.按照班级号从小到大排序 \n ”);printf( "2. 修改学生信息 |9. 按照寝室号从小到大排序\n" ); printf( "3. 删除学生信息 | 10.按照学号从小到大排序 \n" ); printf( "4. 以姓名查询学生信息 | 11. 显示所有学生的相关信息\n" printf( "5. 以学号查询学生信息| 12.保存操作 \n" );printf( "6. 以寝室号查询该寝室中的全部学生信息 | 13. 加载记录 \n" );printf( “7. 以班级号查询该班级中的全部学生信息 | 14. 退出程序 \n" );printf("******************************************************************************\n"}void main());}{);}10:Sort_S_number(S); printf(" 排序完成 !\n\n" );break ;break ;break ;exit(0); break ;default :printf( " 选择错误 : 请在选项到之间选择 !\n\n" );break ;}}while (i!=14);case 11:Display_All(S);casecase 12:Save(S); case 13:Load(S);break ;case 14:Judge_Save(dirty,S);。