朋友们帮我查找错误,帮忙改正.
''酒店房间管理系统''
要求:客户自动入住 查询房间情况 查询客户入住情况 客人退房
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
/*定义客户结构体*/
struct guest
{char no[20];
char Name[20];
char sex[6];
};
/*声明客户数组及客户数量*/
struct guest guests[200];
char T[200]; /*房间没人住*/
int num=0;
int temp;
/*通过客户返回数组下标*/
int guest_SearchByIndex(char no[])
{int i;
for (i=0;i<200;i++)
{if (strcmp(guests[i].no,no)==0)
{return i;}
}
return -1;
}
/*通过姓名返回数组下标*/
int guest_SearchByName(char name[])
{int i;
for (i=0;i<200;i++)
{if (strcmp(guests[i].Name,name)==0)
{return i;}
}
return -1;
}
/*插入客户信息*/
void guest_Insert()
{int i;
for (i=0;i<200;i++)
{ if (T[i]=='0')
{printf("The room's number is d%\n",i);
printf("请输入姓名:");
scanf("%s",&guests[num].Name);
getchar();
printf("请输入性别:");
scanf("%s",&guests[num].sex);
getchar();
T[i]='1'; }
else
printf("The rooms are full");
break;}
}
/*显示单条客户记录*/
void guest_DisplaySingle(int index)
{
printf("%10s%10s%10s\n","房间编号","姓名","性别");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%10s\n",guests[index].no,guests[index].Name,
guests[index].sex);
}
/*修改客户信息*/
void guest_Modify()
{
while(1)
{
char no[20];
char index;
int p;
printf("请输入要修改的客户的房号:");
scanf("%s",&no);
getchar();
index=guest_SearchByIndex(no);
if (index==-1)
{
printf("该客户不存在!\n");
}
else
{
printf("你要修改的客户信息为:\n");
guest_DisplaySingle(index);
printf("-- 请输入新值--\n");
printf("请输入房间编号:");
scanf("%s",&guests[index].no);
getchar();
{p=T[no];T[no]=T[index];T[index]=p;}
printf("请输入姓名:");
scanf("%s",&guests[index].Name);
getchar();
printf("请输入性别:");
scanf("%f",&guests[index].sex);
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*删除客户信息*/
void guest_Delete()
{
int i;
while(1)
{
char no[20];
int index;
printf("请输入要删除的客户房间编号:");
scanf("%s",&no);
getchar();
index=guest_SearchByIndex(no);
if (index==-1)
{
printf("该客户不存在!\n");
}
else
{
printf("你要删除的客户信息为:\n");
guest_DisplaySingle(index);
printf("是否真的要删除?(y/n)");
if (getchar()=='y')
{ T[num]=0;
for (i=index;i<num-1;i++)
{
guests[i]=guests[i+1];
}
num--;
}
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按姓名查询*/
void guest_Select()
{
while(1)
{
char name[20];
int index;
printf("请输入要查询的客户的姓名:");
scanf("%s",&name);
getchar();
index=guest_SearchByName(name);
if (index==-1)
{
printf("该客户不存在!\n");
}
else
{
printf("你要查询的客户信息为:\n");
guest_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*显示客户信息*/
void guest_Display()
{
int i;
printf("%10s%10s%10s\n","房间编号","姓名","性别");
printf("-------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf("%10s%10s10s\n",guests[i].no,guests[i].Name,guests[i].sex);
}
}
/*主程序*/
main()
{
char s[80];
int c;
int choice;
while(1)
{
/*主菜单*/
printf("\n*************** *酒店客户管理系统*******************\n");
printf(" 1. 增加客户记录 \n");
printf(" 2. 修改客户记录 \n");
printf(" 3. 删除客户记录 \n");
printf(" 4. 按姓名查询客户记录 \n");
printf(" 5. 输出所有客户记录 \n");
printf(" 6.退出 \n");
printf("******************************************************\n");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:
guest_Insert();
break;
case 2:
guest_Modify();
break;
case 3:
guest_Delete();
break;
case 4:
guest_Select();
break;
case 5:
guest_Display();
break;
case 6:
exit();
break;
}
}
}
我的QQ是303523577,请
加Q发给我
----------------解决方案--------------------------------------------------------
建议房间号用int型变量
你需要注意对数据的初始化
其他就是一些小疏忽了,比如把%d写成d%
把这些改下就OK了
----------------解决方案--------------------------------------------------------
客人姓名那方面是输入中文?
----------------解决方案--------------------------------------------------------
getchar();
{p=T[no];T[no]=T[index];T[index]=p;} 这一行要怎么改啊?
printf("请输入姓名:");
(26) : warning C4013: 'strcmp' undefined; assuming extern returning int
(142) : error C2107: illegal index, indirection not allowed
(142) : warning C4047: '=' : 'int ' differs in levels of indirection from 'char *'
(142) : error C2107: illegal index, indirection not allowed
(142) : warning C4047: '=' : 'char *' differs in levels of indirection from 'char '
(142) : error C2106: '=' : left operand must be l-value
(196) : warning C4133: 'function' : incompatible types - from 'char [20]' to 'int *'
(416) : error C2198: 'exit' : too few actual parameters
执行 cl.exe 时出错.
----------------解决方案--------------------------------------------------------
#include "stdio.h"
#include "conio.h"
/*定义客户结构体*/
struct guest
{ char no[20];
char Name[20];
char sex[6];
char id[20];
};
/*声明客户数组及客户数量*/
struct guest guests[200];
int num=0;
/*通过客户返回数组下标*/
int guest_SearchByIndex(char no[])
{ int i;
for (i=0;i<num;i++)
{
if (strcmp(guests[i].no,no)==0)
{
return i;
}
}
return -1;
}
/*通过姓名返回数组下标*/
int guest_SearchByName(char name[])
{ int i;
for (i=0;i<num;i++)
{
if (strcmp(guests[i].Name,name)==0)
return i;
else return -1;}
}
/*显示单条客户记录*/
void guest_DisplaySingle(int index)
{ printf("%10s%10s%10s%15s\n","房间编号","姓名","性别","身份号码");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%10s%10s\n",guests[index].no,guests[index].Name,guests[index].sex,guests[index].id);
}
/*插入客户信息*/
void guest_Insert()
{
while(1)
{
printf("请输入房间编号:");
scanf("%s",&guests[num].no);
getchar();
printf("请输入姓名:");
scanf("%s",&guests[num].Name);
getchar();
printf("请输入性别:");
scanf("%s",&guests[num].sex);
getchar();
printf("请输入身份号码:");
scanf("%s",&guests[num].id);
getchar();
num++;
printf("是否继续?(y/n)");
if (getch()!='y')/*发现用getch比用getchar好*/
{
break;
}
}
}
/*修改客户信息*/
void guest_Modify()
{
while(1)
{
char no[20];
int index;
printf("请输入要修改的客户的房号:");
scanf("%s",&no);
getchar();
index=guest_SearchByIndex(no);
if (index==-1)
{
printf("该客户不存在!\n");
}
else
{
printf("你要修改的客户信息为:\n");
guest_DisplaySingle(index);
printf("-- 请输入新值--\n");
printf("请输入房间编号:");
scanf("%s",&guests[index].no);
getchar();
printf("请输入姓名:");
scanf("%s",&guests[index].Name);
getchar();
printf("请输入性别:");
scanf("%s",&guests[index].sex);
getchar();
printf("请输入身份号码:");
scanf("%s",&guests[index].id);
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*删除客户信息*/
void guest_Delete()
{
int i;
while(1)
{
char no[20];
int index;
printf("请输入要删除的客户房间编号:");
scanf("%s",&no);
getchar();
index=guest_SearchByIndex(no);
if (index==-1)
{
printf("该房间没人住!\n");
}
else
{
printf("你要删除的客户信息为:\n");
guest_DisplaySingle(index);
printf("是否真的要删除?(y/n)");
if (getchar()=='y')
{
for (i=index;i<num-1;i++)
{
guests[i]=guests[i+1];
}
num--;
}
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按姓名查询*/
void guest_Select()
{
while(1)
{
char name[20];
int index;
printf("请输入要查询的客户的姓名:");
scanf("%s",&name);
getchar();
index=guest_SearchByName(name);
if (index==-1)
{
printf("该客户不存在!\n");
}
else
{
printf("你要查询的客户信息为:\n");
guest_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按房间号码查询*/
void guest_room()
{
while(1)
{
char no[20];
char index;
printf("请输入要查询的房间号码:");
scanf("%s",&no);
getchar();
index=guest_SearchByIndex(no);
if (index==-1)
{
printf("该房间为空!\n");
}
else
{
printf("你要查询的客户信息为:\n");
guest_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*显示客户信息*/
void guest_Display()
{ int i;
printf("%10s%10s%10s%15s\n","房间编号","姓名","性别","身份号码");
printf("-------------------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf("%10s%10s%10s%10s\n",guests[i].no,guests[i].Name,guests[i].sex,guests[i].id);
}
getch();
}
/*将客户信息从文件读出*/
void IO_ReadInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","rb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&guests[i],sizeof(struct guest),1,fp);
}
}
fclose(fp);
}
/*将学生信息写入文件*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("写入文件错误!\n");
}
for (i=0;i<num;i++)
{
if (fwrite(&guests[i],sizeof(struct guest),1,fp)!=1)
{
printf("写入文件错误!\n");
}
}
fclose(fp);
}
/*主程序*/
main()
{
int m;
IO_ReadInfo();
while(1)
{
system("cls");
/*主菜单*/
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(" ********************************************************** \n");
scanf("%d",&m);
getchar();
switch(m)
{
case 1:
guest_Insert();
break;
case 2:
guest_Modify();
break;
case 3:
guest_Delete();
break;
case 4:
guest_Select();
break;
case 5:
guest_room();
break;
case 6:
guest_Display();
break;
case 7:
exit();
break;
}
IO_WriteInfo();
}
getch();
}
----------------解决方案--------------------------------------------------------
还不能用中文输入名字,也不能自动输出空房间,在C++运行
----------------解决方案--------------------------------------------------------
这个程序有什么特色的算法吗??能不能提供点信息啊
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
#include <stdio.h>
#include <conio.h>
#include<string.h>
#include<stdlib.h>
/*定义客户结构体*/
struct guest
{ char no[20];
char Name[20];
char sex[6];
char id[20];
};
/*声明客户数组及客户数量*/
struct guest guests[200];
int num=0;
/*通过客户返回数组下标*/
int guest_SearchByIndex(char no[])
{ int i;
for (i=0;i<num;i++)
{
if (strcmp(guests[i].no,no)==0)
{
return i;
}
}
return -1;
}
/*通过姓名返回数组下标*/
int guest_SearchByName(char name[])
{ int i;
for (i=0;i<num;i++)
{
if (strcmp(guests[i].Name,name)==0)
return i;
else return -1;}
return 0;
}
/*显示单条客户记录*/
void guest_DisplaySingle(int index)
{ printf("%10s%11s%10s%15s\n","房间编号","姓名","性别","身份号码");
printf("-------------------------------------------------------------\n");
printf(" %-10s%9s%9s%15s\n",guests[index].no,guests[index].Name,guests[index].sex,guests[index].id);
}
/*插入客户信息*/
void guest_Insert()
{
while(1)
{
printf("请输入房间编号:");
scanf("%s",&guests[num].no);
getchar();
printf("请输入姓名:");
scanf("%s",&guests[num].Name);
getchar();
printf("请输入性别:");
scanf("%s",&guests[num].sex);
getchar();
printf("请输入身份号码:");
scanf("%s",&guests[num].id);
getchar();
num++;
printf("是否继续?(y/n)");
if (getch()!='y'||getch()=='Y')/*发现用getch比用getchar好*/
{
break;
}
}
}
/*修改客户信息*/
void guest_Modify()
{
while(1)
{
char no[20];
int index;
printf("请输入要修改的客户的房号:");
scanf("%s",&no);
getchar();
index=guest_SearchByIndex(no);
if (index==-1)
{
printf("该客户不存在!\n");
}
else
{
printf("你要修改的客户信息为:\n");
guest_DisplaySingle(index);
printf("-- 请输入新值--\n");
printf("请输入房间编号:");
scanf("%s",&guests[index].no);
getchar();
printf("请输入姓名:");
scanf("%s",&guests[index].Name);
getchar();
printf("请输入性别:");
scanf("%s",&guests[index].sex);
getchar();
printf("请输入身份号码:");
scanf("%s",&guests[index].id);
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n'||getchar()=='N')
{
break;
}
}
}
/*删除客户信息*/
void guest_Delete()
{
int i;
while(1)
{
char no[20];
int index;
printf("请输入要删除的客户房间编号:");
scanf("%s",&no);
getchar();
index=guest_SearchByIndex(no);
if (index==-1)
{
printf("该房间没人住!\n");
}
else
{
printf("你要删除的客户信息为:\n");
guest_DisplaySingle(index);
printf("是否真的要删除?(y/n)");
if (getchar()=='y')
{
for (i=index;i<num-1;i++)
{
guests[i]=guests[i+1];
}
num--;
}
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n'||getchar()=='N')
{
break;
}
}
}
/*按姓名查询*/
void guest_Select()
{
while(1)
{
char name[20];
int index;
printf("请输入要查询的客户的姓名:");
scanf("%s",&name);
getchar();
index=guest_SearchByName(name);
if (index==-1)
{
printf("该客户不存在!\n");
}
else
{
printf("你要查询的客户信息为:\n");
guest_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n'||getchar()=='N')
{
break;
}
}
}
/*按房间号码查询*/
void guest_room()
{
while(1)
{
char no[20];
char index;
printf("请输入要查询的房间号码:");
scanf("%s",&no);
getchar();
index=guest_SearchByIndex(no);
if (index==-1)
{
printf("该房间为空!\n");
}
else
{
printf("你要查询的客户信息为:\n");
guest_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n'||getchar()=='N')
{
break;
}
}
}
/*显示客户信息*/
void guest_Display()
{ int i;
printf("%10s%11s%10s%15s\n","房间编号","姓名","性别","身份号码");
printf("-------------------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf(" %-10s%9s%9s%15s\n",guests[i].no,guests[i].Name,guests[i].sex,guests[i].id);
}
getch();
}
/*将客户信息从文件读出*/
void IO_ReadInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","rb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&guests[i],sizeof(struct guest),1,fp);
}
}
fclose(fp);
}
/*将学生信息写入文件*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("写入文件错误!\n");
}
for (i=0;i<num;i++)
{
if (fwrite(&guests[i],sizeof(struct guest),1,fp)!=1)
{
printf("写入文件错误!\n");
}
}
fclose(fp);
}
/*主程序*/
void main()
{
int m;
IO_ReadInfo();
while(1)
{
system("cls");
/*主菜单*/
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(" ********************************************************** \n");
scanf("%d",&m);
getchar();
switch(m)
{
case 1:
guest_Insert();
break;
case 2:
guest_Modify();
break;
case 3:
guest_Delete();
break;
case 4:
guest_Select();
break;
case 5:
guest_room();
break;
case 6:
guest_Display();
break;
case 7:
exit(0);
break;
}
IO_WriteInfo();
}
getchar();
}
好了
我已经帮你修改过了
现在可以输入汉字了
是在VC6.0++里面运行可以
其他的编译器没有调试过.............
----------------解决方案--------------------------------------------------------