C语言宿舍管理系统源码Word文档下载推荐.docx
《C语言宿舍管理系统源码Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C语言宿舍管理系统源码Word文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。
printf("
新建一个文件dorm.txt"
getch();
in_file=fopen("
w+"
}
else
fread(s,sizeof(structDorm),MAX,in_file);
fclose(in_file);
}
voidsave(structDorms[]){
FILE*out_file;
out_file=fopen("
fwrite(s,sizeof(structDorm),MAX,out_file);
fclose(out_file);
}
intcount(structDorms[]){
inti,count=0;
for(i=0;
i<
MAX;
i++)
if(s[i].Rmnum>
0)
count++;
return(count);
voidadd(structDorms[]){
inti,j;
system("
cls"
load(s);
printf("
新增一个数据\n\n"
i=count(s);
j=i;
if(i<
MAX){
\n学号:
"
fflush(stdin);
gets(s[j].Stnum);
寝室号:
scanf("
%d"
&
s[j].Rmnum);
姓名:
gets(s[j].name);
else
空间不够了T_T\a\n"
save(s);
intshow(structDorms[],intposition){
if(s[position].Rmnum>
\n\t学号:
%s;
"
s[position].Stnum);
\t\t寝室号:
%d;
s[position].Rmnum);
\t姓名:
s[position].name);
else
return0;
voidshow_all(structDorms[]){
inti=0,j=1;
\n总共住了%d位学生"
count(s));
if(j)
count(s);
j=show(s,i);
\n按任意键继续!
getch();
//按寝室号查找
voidfind_Rmnum(structDorms[]){
inti=0,j=0;
\n你想找的寝室号是?
:
scanf("
Rmnum);
while(i<
if(s[i].Rmnum==Rmnum)
{show(s,i);
j++;
i++;
if(j==0)printf("
无此宿舍!
//查询//二分查找学生号
voidfind_Stnum(structDorms[]){
inti=0,j=0,k;
intStnum,ref;
\n你想找的学号是?
ref);
while((ref!
=Stnum)&
&
(i<
MAX))
k=count(s)/2;
Stnum=atoi(s[k].Stnum);
if(ref>
Stnum)
{k=k+k/2;
Stnum=atoi(s[k].Stnum);
elseif(ref<
{k=k-k/2;
已找到该人:
\n"
show(s,Stnum);
j++;
无此人!
voidfind_Name(structDorms[]){
charName[10];
\n你想找的姓名是?
while(getchar()!
='
\n'
gets(Name);
if(strcmp(s[i].name,Name)==0)
//查询的主菜单////////////////////////////////////////////////
voidfind(structDorms[]){
inti;
do{
查找\n\n"
\n\t----------------------------------"
\n\t按学号号查找\t1"
\n\t按姓名查找\t2"
\n\t按寝室号查找\t3"
\n\t退出\t0"
\n\tOption:
i);
switch(i){
case1:
find_Stnum(s);
break;
case2:
find_Name(s);
case3:
find_Rmnum(s);
case0:
default:
{
\n你选错啦\n按任意键继续!
);
}
}while(i!
=0);
///////////////////////////////////////////////////////////////
///删除全部
voiddelete_all(structDorms[]){
structDormnos[MAX]={"
0,0};
s=nos;
所有信息都删除了.\n"
//这个全部删除
voiddelete_(structDorms[]){
inti=0,j=0,x=0,y;
charany[20];
y=count(s);
请输入学号\n"
gets(any);
i++){
if(strcmp(s[i].Stnum,any)==0)
for(x=i;
x<
x++)
s[x]=s[x+1];
查无此人"
elseprintf("
这件学生已经删除.\n"
/////////////////////////////////////////////////////////////////
//编辑
voideditt(structDorms[]){
delete_(s);
getch();
\n请新增一个学生."
add(s);
////编辑主菜单////////////////////////////////////////////////
voidedit(structDorms[]){
do{
衣柜管理\n\n"
\n\t------------------------------"
\n\t修改一个信息\t1"
\n\t仅删除一件衣服\t2"
\n\t-----------------------------"
switch(i){
editt(s);
delete_(s);
case0:
\n按错了,亲\n按任意键结束!
/////////////////////////排序//////////////////////////////////
voidpaixu_Rmnum(structDorms[])//按照宿舍号排序
structDorms1;
if(s[i].Rmnum>
s[i+1].Rmnum)
{
s1=s[i];
s[i]=s[i+1];
s[i+1]=s1;
按宿舍号排序结果:
show_all(s);
voidpaixu_Stnum(structDorms[])//按照学生号排序
inti,count1;
for(count1=count(s);
count1>
0;
count1--)
for(i=0;
if(atoi(s[i].Stnum)>
atoi(s[cou