宿舍管理系统

洛阳理工学院实验报告

宿舍管理系统

宿舍管理系统

宿舍管理系统

附:源程序:

#include #include #include typedef struct

{

char name[20];

char xuehao[20];

char fanghao[20];

}stu;

typedef struct

{

stu student[100];

int last;

}seqlist;

void input(seqlist *s,int i)

{

printf("请输入第%d位学生的信息结束:over\n",i);

printf("输入学生的姓名: ",i);

gets(s->student[i].name);

printf("输入学生的学号: ",i);

gets(s->student[i].xuehao);

printf("输入学生的房号: ",i);

gets(s->student[i].fanghao);

s->last++;

}

void print(seqlist *s)

{

int i;

printf(" 姓名学号房号\n");

for(i=1;ilast+1;i++)

{

printf("%8s %8s %8s \n",s->student[i].name,s->student[i].xuehao,s->student[i].fanghao ); }

}

int compare(char s1[],char s2[])

{

int i;

int j;

for(i=0;(s1[i]!='\0')&&(s2[i]!='\0');i++)

{

j=s1[i]-s2[i];

if(j!=0)

break;

}

if((s1[i]=='\0')&&(s2[i]=='\0'))

{ if(j>0)

j=1;

else

j=0;

return j;

}

else

{if(s1[i]-s2[i]>0)

j=1;

else

j=0;

return j;

}

}

void paixu1(seqlist *s,int length)

{

int i;

int j;

for(i=2;i<=length;i++)

{

s->student[0]=s->student[i];

j=i-1;

while(!compare(s->student[0].name,s->student[j].name))

{

s->student[j+1]=s->student[j];

j=j-1;

}

s->student[j+1]=s->student[0];

}

}

void paixu2(seqlist *s,int length)

{

int i;int j;

for(i=2;i<=length;i++)

{

s->student[0]=s->student[i];j=i-1;

while(!compare(s->student[0].xuehao,s->student[j].xuehao))

{

s->student[j+1]=s->student[j];

j=j-1;

}

s->student[j+1]=s->student[0];

}

}

void paixu3(seqlist *s,int length)

{

int i;int j;

for(i=2;i<=length;i++)

{

s->student[0]=s->student[i];j=i-1;

while(!compare(s->student[0].fanghao,s->student[j].fanghao))

{

s->student[j+1]=s->student[j];

j=j-1;

}

s->student[j+1]=s->student[0];

}

}

int chazhao1(seqlist *s, char k[])

{ int d=1;

int i;

for(i=1;i<=s->last;i++)

if(strcmp(s->student[i].name,k)==0)

{

if(d==1)

printf(" 姓名学号房号\n");

printf( "你查找的该生信息是:%8s %8s %8s \n",s->student[i].name,s->student[i].xuehao,s->student[i].fanghao );

d=0;

}

if(i>s->last+1)

{printf("输入错误");

return -1;

}

}

int chazhao2(seqlist *s, char k[])

{ int d=1;

int i;

for(i=1;i<=s->last;i++)

if(strcmp(s->student[i].xuehao,k)==0)

{

if(d==1)

printf(" 姓名学号房号\n");

printf( "你查找的该生信息是:%8s %8s %8s \n",s->student[i].name,s->student[i].xuehao,s->student[i].fanghao );

d=0;

}

if(i>s->last+1)

{

printf("输入错误");

return -1;

}

}

int chazhao3(seqlist *s, char k[])

{ int d=1;

int i;

i=1;

for(i=1;i<=s->last;i++)

if(strcmp(s->student[i].fanghao,k)==0)

{if(d==1)

printf(" 姓名学号房号\n");

printf( "你查找的学生信息是:%8s %8s %8s \n",s->student[i].name,s->student[i].xuehao,s->student[i].fanghao );

d=0;

}

if(i>s->last+1)

{printf("输入错误");

return -1;

}

}

void main()

{

int c,d;

seqlist s;

int i=0 ;

char xinxi[100],chazhao[100],jieshu[]="over";

http://m.wendangku.net/doc/6d3537744b35eefdc9d33330.htmlst=0;

printf(" 录入学生信息\n");

do

{

i++;

input(&s,i);

gets(xinxi);

}

while(!(strcmp(jieshu,xinxi)==0));

printf("***********************欢迎进入宿舍管理查询系统*************************\n"); printf("\n");

while(1)

{

printf(" *************************请按键选择操作*************************\n " );

printf("\n");

printf(" * 1:按姓名排序2:按学号排序3:按房号排序*\n");

printf("\n");

printf(" * 4:按姓名查找5:按学号查找6:房号查找*\n");

printf("\n");

printf(" * 0: 退出*\n");

printf("\n");

printf(" ****************************************************************\n");

printf("请选择排序操作或退出系统:");

scanf("%d",&c);

getchar();

if(c==0) break;

if(c==1)

{ printf("按姓名排序为:\n");

paixu1(&s,http://m.wendangku.net/doc/6d3537744b35eefdc9d33330.htmlst);

print(&s);

}

if(c==2)

{ printf("按学号排序为:\n");

paixu2(&s,http://m.wendangku.net/doc/6d3537744b35eefdc9d33330.htmlst);

print(&s);

}

if(c==3)

{ printf("按房号排序为:\n");

paixu3(&s,http://m.wendangku.net/doc/6d3537744b35eefdc9d33330.htmlst);

print(&s);

}

printf("请选择查找操作:");

scanf("%d",&d);

getchar();

if(d==4)

while(1)

{

printf("输入你要查找学生的姓名: 结束:over\n");

gets(chazhao);

if(strcmp(jieshu,chazhao)==0) break;

chazhao1(&s,chazhao);

}

if(d==5)

while(1)

{

printf("请输入要查找学生的学号: 结束:over\n");

gets(chazhao);

if(strcmp(jieshu,chazhao)==0) break;

chazhao2(&s,chazhao);

}

if(d==6)

while(1)

{

printf("请输入要查找学生的房号: 结束:over\n");

gets(chazhao);

if(strcmp(jieshu,chazhao)==0) break;

chazhao3(&s,chazhao);

}

}

}

相关推荐
相关主题
热门推荐