c语言楼层查询系统源代码.docx

上传人:b****6 文档编号:7487513 上传时间:2023-01-24 格式:DOCX 页数:19 大小:18.33KB
下载 相关 举报
c语言楼层查询系统源代码.docx_第1页
第1页 / 共19页
c语言楼层查询系统源代码.docx_第2页
第2页 / 共19页
c语言楼层查询系统源代码.docx_第3页
第3页 / 共19页
c语言楼层查询系统源代码.docx_第4页
第4页 / 共19页
c语言楼层查询系统源代码.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

c语言楼层查询系统源代码.docx

《c语言楼层查询系统源代码.docx》由会员分享,可在线阅读,更多相关《c语言楼层查询系统源代码.docx(19页珍藏版)》请在冰豆网上搜索。

c语言楼层查询系统源代码.docx

c语言楼层查询系统源代码

#include"conio.h"

#include"stdio.h"

#include"stdlib.h"

#include"string.h"

#defineMAX100

#defineN3

 

structchaoxiang_type;//位置

structloupans_type;//房间详情

intread_file(structloupans_typeloupan[]);//读取信息模块

voidsave_file(structloupans_typeloupan[],intsum);//保存信息模块

intinput(structloupans_typeloupan[]);//输入模块

voidoutput(structloupans_typeloupan[],intsum);//输出模块

voidmodify(structloupans_typeloupan[],intsum);//修改模块

voidreserch(structloupans_typeloupan[],intsum);//查询模块

voidsort(structloupans_typeloupan[],intsum);//排序模块

intdel(structloupans_typeloupan[],intsum);//删除模块

voidadd(structloupans_typeloupan[],int*sum);//添加模块

structchaoxiang_type//位置

{

intdanyu;//单元

intloucen;//楼层

};

 

structloupans_type//房间详情

{

charnum[8];//楼号

charprice[20];//价格

charchaoxiang[20];//朝向

intarea;//面积

structchaoxiang_typeweizhi;//单元信息

structchaoxiang_typekind;//类型

};

/*读取信息模块*/

intread_file(structloupans_typeloupan[])

{

FILE*fp;//FILE文件、文件夹,fp=filepointer文件指针。

inti=0;

if((fp=fopen("loupans.txt","rt"))==NULL)//fopen函数用来打开一个文件,其调用形式为:

文件指针名=fopen(文件名,文件使用方法);rt只读打开一个文件文本。

{

printf("\n库存文件不存在,请创建!

\n");

return0;//正常退出;return表示从被调函数返回到主调函数继续执行,返回时可带一个返回值(0正常,非0非正常)。

}

while(!

feof(fp))//feof(fp)用于测试fp文件指针是否已经到达文件结尾,如果fp指针已经到达文件结尾,则返回1,否则返回0;

{//!

表示非,这里while(!

feof(fp))表示当没有到文件末尾就循环,否则就退出。

fread(&loupan[i],sizeof(structloupans_type),1,fp);//fread从文件中读取。

if(loupan[i].num==0)

break;

else

i++;

}

fclose(fp);//文件关闭

returni-1;

}

 

/*保存信息模块*/

voidsave_file(structloupans_typeloupan[],intsum)//save_file保存文件

{

FILE*fp;

inti;

if((fp=fopen("loupans.txt","wt"))==NULL)

{

printf("读文件错误\n");

return;

}

for(i=0;i

{

if(fwrite(&loupan[i],sizeof(structloupans_type),1,fp)!

=1)

printf("写文件错误\n");

}

fclose(fp);

}

/*输入模块*/

intinput(structloupans_typeloupan[])

{

inti=0;

intnumber;

system("cls");

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

printf("\n\t请输入要录入的楼盘的个数(最多%d个):

",MAX);

scanf("%d",&number);

printf("\n\n\t录入楼盘信息(最多录入%d个)\n",number);

printf("---------------------------------------\n");

while(i

{

printf("\n\t\t第%d个楼盘",i+1);

printf("\n\n\t\t\t楼盘楼号:

");

scanf("%s",loupan[i].num);

if(loupan[i].num==0)

break;

printf("\n\t\t\t价格(元/㎡):

");

scanf("%s",loupan[i].price);

printf("\n\t\t\t面向:

");

scanf("%s",loupan[i].chaoxiang);

printf("\n\t\t\t面积(单位:

㎡):

");

scanf("%d",&loupan[i].area);

printf("\n\t\t\t楼盘单元信息(单元-层):

");

scanf("%d-%d",&loupan[i].weizhi.danyu,&loupan[i].weizhi.loucen);

printf("\n\t\t\t楼盘类型(厅-室):

");

scanf("%d-%d",&loupan[i].kind.danyu,&loupan[i].kind.loucen);

i++;

}

printf("\n\t\t\t%d个楼盘信息录入完毕!

\n",i);

getchar();//getchar()函数等待输入直到按回车才结束,回车前所有输入字符都会显示在屏幕上,但只有第一个字符作为函数的返回值。

返回类型为int型,返回值为用户输入的ASCII码,出错返回EOF。

printf("\n\t\t\t按回车键返回主菜单!

");

getchar();

returni;

}

 

/*输出模块*/

voidoutput(structloupans_typeloupan[],intsum)

{

FILE*fp;

inti=0;

intj;

system("cls");

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

fp=fopen("loupans.txt","rt");

printf("\n\t\t\t----楼盘信息表----\n\n");

printf("楼盘楼号--单元信息(单元-层)--类型(厅-室)---面积(单位:

㎡)--面向--价格(元/㎡)\n");

printf("----------------------------------------------------------------------------\n");

for(j=0;j

{

fread(&loupan[i],sizeof(structloupans_type),1,fp);

if(loupan[i].num!

=0)

{

printf("%6s%10d-%d%10d-%d\t%4d㎡%8s%3s\n",loupan[i].num,loupan[i].weizhi.danyu,loupan[i].weizhi.loucen,loupan[i].kind.danyu,loupan[i].kind.loucen,loupan[i].area,loupan[i].chaoxiang,loupan[i].price);

printf("----------------------------------------------------------------------------\n");

i++;

}

}

getchar();

printf("\t\t\t按回车键返回主菜单");

getchar();

fclose(fp);

}

 

/*修改模块*/

voidmodify(structloupans_typeloupan[],intsum)

{

inti=0;

intchoice;

intflag;

charmodify_num[8];

do

{

system("cls");

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

printf("\n输入要修改的楼盘的楼号:

");

scanf("%s",modify_num);

for(i=0;i

{

if(!

strcmp(loupan[i].num,modify_num))

{

printf("\n\t\t\t----楼盘信息----\n");

printf("楼盘楼号--单元信息(单元-层)--类型(厅-室)---面积(单位:

㎡)--面向--价格(元/㎡)\n");

printf("----------------------------------------------------------------------------\n");

printf("%6s%10d-%2d%10d-%2d\t%4d㎡%8s%3s\n",loupan[i].num,loupan[i].weizhi.danyu,loupan[i].weizhi.loucen,loupan[i].kind.danyu,loupan[i].kind.loucen,loupan[i].area,loupan[i].chaoxiang,loupan[i].price);

printf("\t\t\t1.楼盘楼号\n\n\t\t\t2.价格(/㎡)\n\n\t\t\t3.面向\n\n\t\t\t4.面积(单位:

㎡)\n\n\t\t\t5.单元信息(单元-层)\n\n\t\t\t6.类型(厅-室)\n");

printf("请输入要修改项的楼号(选择1-6):

");

scanf("%d",&choice);

switch(choice)

{

case1:

printf("\n\t\t\t输入修改后的楼盘楼号:

");

scanf("%s",loupan[i].num);

break;

case2:

printf("\n\t\t\t输入修改后的价格(元/㎡):

");

scanf("%s",loupan[i].price);

break;

case3:

printf("\n输入修改后的面向:

");

scanf("%s",loupan[i].chaoxiang);

break;

case4:

printf("\n\t\t\t输入修改后的面积(单位:

㎡):

");

scanf("%d",&loupan[i].area);break;

case5:

printf("\n输入修改后的楼盘单元信息(单元-层):

");

scanf("%d-%d",&loupan[i].weizhi.danyu,&loupan[i].weizhi.loucen);

break;

case6:

printf("\n\t\t\t输入修改后的楼盘类型(厅-室):

");

scanf("%d-%d",&loupan[i].kind.danyu,&loupan[i].kind.loucen);

break;

}

printf("\n\t\t\t----楼盘信息----(修改后)\n");

printf("楼盘楼号--单元信息(单元-层)--类型(厅-室)---面积(单位:

㎡)--面向--价格(元/㎡)\n");

printf("----------------------------------------------------------------------------\n");

printf("%6s%10d-%2d%10d-%2d\t%4d㎡%8s%3s\n",loupan[i].num,loupan[i].weizhi.danyu,loupan[i].weizhi.loucen,loupan[i].kind.danyu,loupan[i].kind.loucen,loupan[i].area,loupan[i].chaoxiang,loupan[i].price);

getchar();

break;

}

if(i==sum)

{

printf("\n\t\t\t该楼盘不存在");

getchar();

}

save_file(loupan,sum);

printf("\n\n继续修改吗?

(Y/N(选择N则返回主菜单))");

choice=getchar();

if(choice=='Y'||choice=='y')

{

flag=1;

printf("\n\t\t\t继续修改!

\n");

}

else

flag=0;

}

}

while(flag==1);

printf("\n");

}

 

/*查询模块*/

voidreserch(structloupans_typeloupan[],intsum)

{

inti=0;

intflag;

intchoice;

intkey=0;

charreserch1[10],reserch2[10];

do

{

system("cls");

printf("\n\t\t\t请输入要查询的楼盘的价格范围(元/㎡):

\n\n\n");

printf("\t\t\t请输入最低价格:

\n\t\t\t");

scanf("%s",reserch1);

printf("\n\n\t\t\t请输入最高价格:

\n\t\t\t");

scanf("%s",reserch2);

for(i=0;i

if(strcmp(loupan[i].price,reserch1)>0&&strcmp(loupan[i].price,reserch2)<0)

{

key=1;

}

if(key==1)

{

printf("\n\t\t\t----楼盘信息----\n");

printf("楼盘楼号--单元信息(单元-层)--类型(厅-室)---面积(单位:

㎡)--面向--价格(元/㎡)\n");

printf("----------------------------------------------------------------------------\n");

}

for(i=0;i

if(strcmp(loupan[i].price,reserch1)>0&&strcmp(loupan[i].price,reserch2)<0)

{

printf("%6s%10d-%2d%10d-%2d\t%4d㎡%8s%3s\n",loupan[i].num,loupan[i].weizhi.danyu,loupan[i].weizhi.loucen,loupan[i].kind.danyu,loupan[i].kind.loucen,loupan[i].area,loupan[i].chaoxiang,loupan[i].price);

}

printf("----------------------------------------------------------------------------\n");

printf("\n\n\t\t\t价格范围:

%6s-------%s",reserch1,reserch2);

getch();

break;

if(key==0)

{

printf("\n\t\t\t该楼盘不存在");

getchar();

}

printf("\n\n\t\t继续查询吗?

(Y/N(选择N则返回主菜单))");

choice=getchar();

if(choice=='Y'||choice=='y')

{

flag=1;

printf("\n\t\t\t按任意键继续查询!

\n");

getch();

}

else

{

flag=0;

}

}

while(flag==1);

printf("\n");

}

 

/*排序模块*/

voidsort(structloupans_typeloupan[],intsum)

{

inti,j;

structloupans_typet;

system("cls");

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

for(i=0;i

for(j=i+1;j

if(strcmp(loupan[i].num,loupan[j].num)>0)

{

t=loupan[i];

loupan[i]=loupan[j];

loupan[j]=t;

}

printf("\n\t\t\t按楼号排序:

\n\n");

printf("\n\t\t\t----楼盘信息表----\n\n");

printf("楼盘楼号--单元信息(单元-层)--类型(厅-室)---面积(单位:

㎡)--面向--价格(元/㎡)\n");

printf("----------------------------------------------------------------------------\n");

for(i=0;i

{

printf("%6s%10d-%2d%10d-%2d\t%4d㎡%8s%3s\n",loupan[i].num,loupan[i].weizhi.danyu,loupan[i].weizhi.loucen,loupan[i].kind.danyu,loupan[i].kind.loucen,loupan[i].area,loupan[i].chaoxiang,loupan[i].price);

printf("----------------------------------------------------------------------------\n");

}

getchar();

printf("\n\t\t\t按回车键返回主菜单!

");

getchar();

}

 

/*删除模块*/

intdel(structloupans_typeloupan[],intsum)

{

inti;

intj;

intk=0;

chardel_num[8];

system("cls");

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

printf("\t\t请输入需要删除的楼盘信息的楼号\n\n");

scanf("%s",del_num);

for(i=0;i

if(!

strcmp(loupan[i].num,del_num))

for(j=i;j

loupan[j]=loupan[j+1];

else

k++;

if(k==sum)

{

printf("\t\t\t该楼盘不存在\n");

getchar();

printf("\t\t\t按回车键返回主菜单");

getchar();

return(sum);

}

else

{

save_file(loupan,sum);

printf("\t\t\t删除成功:

\n");

getchar();

printf("\n\t\t\t按回车键返回主菜单!

");

getchar();

return(sum-1);

}

}

 

/*添加模块*/

voidadd(structloupans_typeloupan[],int*sum)

{

inti;

intflag;

charchoice;

system("cls");

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

i=(*sum);

do

{

if(i

{

printf("\t\t请输入要添加的楼盘的信息:

\n");

printf("\n\t\t\t楼盘楼号:

");

scanf("%s",loupan[i].num);

if(loupan[i].num==0)

break;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1