谁能帮我修改下C语言程序代码,使之能成功运行
#include"stdio.h"
#include"stdlib.h"
struct home
{char roomNO;
char name;
char sex;
char person;
char time;
char contain;
char money;
struct home *next;
struct home *prior;
}list_entry;
struct home *start;
struct home *last;
void search1();
main()
{
int b;
struct home *info;
start=0;
for(;;){
switch(menu_select()){
case 1:enter();break;
case 2:alter();break;
case 3:search();break;
case 4:cost();break;
case 5:delete();break;
case 6:tongji();break;
case 7:tuichu();
}
}
}
menu_select()
{ intc;
printf("\t\t=========================================================\n");
printf("\t\t=========================================================\n");
printf("\t\t==== 宾馆客房管理系统 ====\n");
printf("\t\t==== 请选择功能 ====\n");
printf("\t\t==== 1输入客房情况 ====\n");
printf("\t\t==== 2修改客房情况 ====\n");
printf("\t\t==== 3查询客房情况 ====\n");
printf("\t\t==== 4客房费用 ====\n");
printf("\t\t==== 5删除指定客房 ====\n");
printf("\t\t==== 6统计客房情况 ====\n");
printf("\t\t==== 7退出系统 ====\n");
printf("\t\t=========================================================\n");
printf("\t\t=========================================================\n");
do{
printf(" 请按数字选择\n");
scanf("%d",&c);getchar();
}while(c<0||c>10);
return c;
}
enter()
{struct home *info,*dls_store(); char s;char a="have";
for(;;)
{
info=malloc(sizeof(list_entry));
if(info==0)
{printf(" 内存已用完\n");
return;
}
inputs(" \t客房号码 \n",info->nember,10);
if(!info->nember) break;
inputs(" \t能住的人数\n",info->contain,10);
inputs(" \t有人输入have无人输入null\n",info->person,10);
if(!strcmp(a,info->person)){
inputs("\t姓名:\n",info->name,10);
inputs("\t姓别:\n",info->sex,10);
inputs("\t住入时间:\n",info->time,10);
}
inputs(" \t有人时输入时间无人输入\n",info->time,10);
inputs(" \t输入客房费用\n",info->money,10);
start=dls_store(info,start);
}
}
inputs(prompt,s,count)
char *prompt;
char *s;
int count;
{
char p;
do{
printf(prompt);
gets(p);
if(strlen(p)>count)
printf(" 太长啦\n ");
}while(strlen(p)>count);
strcpy(s,p);
}
struct home *dls_store(i,top)
struct home *i,*top;
{
static struct home *last=0;
struct home *old,*p;
if(last==0){
i->next=0;
i->prior=0;
last=i;
return i;
}
p=top;
old=0;
while(p){
if(strcmp(p->nember,i->nember)<0){
old=p;
p=p->next;
}
else{
if(p->prior){
p->prior->next=i;
i->next=p;
p->prior=i;
return top;
}
i->next=p;
i->prior=0;
p->prior=i;
return i;
}
} old->next=i;
i->next=0;
i->prior=old;
last=i;
return start;
}
alter()
{
struct home *info,*find();
char roomNO;char a="have"; char c="null";
intb;
printf(" \t如想查看客房情况输入1\n");
printf(" \t想修改输入2\n");
printf(" \t不想修改输入3\n");
scanf("%d",&b);
if(b==1)search();
if(b==2){
printf(" \t请输入要客房号码\n");
scanf("%s",nember);getchar();
if(!(info=find(nember)))printf("\t没找到\n");
else
{
display(info);printf("\t下面是修改项目\n");
if(!strcmp(a,info->person))
inputs("\t请输入null:\n",info->person,10);
if(!strcmp(c,info->person)){
inputs("\t请输入名字\n",info->name,10);
inputs("\t请输入性别\n",info->sex,10);
inputs("\t请输入时间\n",info->time,10);
}
}
}
if(b==3) return;
}
struct home *find(nember)
char *nember;
{ struct home *info;
info=start;
while(info){
if(!strcmp(nember,info->nember)) return info;
info=info->next;
}
printf(" \t没找到\n");
return(NULL);
} display(info)
struct home *info;
{ char a="have";
printf("\t客房号码: %s\n",info->nember);
printf("\t能住人数: %s\n",info->contain);
printf("\t无人住时显示null有人住时显示have:%s\n",info->person);
if(!strcmp(a,info->person)){
printf("\t名字%s\n",info->name);
printf("\t性别%s\n",info->sex);
printf("\t时间%s\n",info->time);}
printf("\t客房每天费用: %s\n",info->money);
printf("\n");
}
search()
{
intb;
printf(" \t查询只定客房输入1\n");
printf(" \t查询已住客房输入2\n");
printf(" \t查询未住客房输入3\n");
printf(" \t返回主菜单请输入4\n");
do{
scanf("%d",&b);
switch(b){
case 1: search1();break;
case 2: search2();break;
case 3: search3();break;
case 4: return;
}
}while(b<1||b>5);
}
void search1()
{ char nember;
struct home *info,*find();
printf("\t输入房号码\n");
scanf("%s",nember); getchar();
if(!(info=find(nember))) printf("\t没找到\n");
else display(info);
}
search2()
{struct home *info;
char a="have";
info=start;
while(info){
if(!strcmp(info->person,a))
display(info);
printf("\n");
info=info->next;
}
}
search3()
{struct home *info;
char b="null";
info=start;
while(info){
if(!strcmp(b,info->person))
display(info);
printf(" \n ");
info=info->next;
}
}
save()
{
register int t,size;
struct home *info;
char *p;
FILE *fp;
if((fp=fopen("mlist","wb"))==0){
printf(" \t文件打不开\n");
exit(0);
}
printf("\t 正存入内存\n");
size=sizeof(list_entry);
info=start;
while(info){
p=(char*)info;
for(t=0;t<size;++t)
putc(*p++,fp);
info=info->next;
}
putc(EOF,fp);
fclose(fp);
printf("\t已存完\n");
}
cost()
{
char nember;
struct home *info;
printf(" \t请输入客房号码\n");
gets(nember);
if(!(info=find(nember)))printf("\t没找到\n");
else{ display(info);
printf(" \t如果退房时间在12:00后按一天时间计算\n");
}
}
delete()
{struct home *info,*find();
char nember;
printf(" \t请输入指定客房号码\n");
scanf("%s",&nember);
info=find(nember);
if(info){
if(start==info){
start=info->next;
if(start)
start->prior=0;}
else
last=0;
}
else
{
info->prior->next=info->next;
if(info!=last)
info->next->prior=info->prior;
else
last=info->prior;
}
free(info);
}
tuichu()
{
int c;
printf("\t建议您最好存盘如果存盘输入1不存输入2\n");
scanf("%d",&c);
if(c==1) save();
if(c==2){
printf("\t谢谢您使用本系统:\n");
exit(0);
}
}tongji()
{
struct home *info;
char a="have";
char b="null";
int c,count=0;
printf("\t统计未住客房号码输入1已住客房号码输入2:\n");
scanf("%d",&c);
if(c==1){
info=start;
while(info)
{
if(!strcmp(a,info->person)) {
printf("\客房号码 %s \n",info->nember);
count++; }
info=info->next;
}
printf("\t共有未住客房%d个\n",count); }
if(c==2)
{info=start;
while(info)
{ if(!strcmp(b,info->person))
{printf("\t客房号码 %s \n",info->nember);
count++;}
info=info->next;
} printf("\t共有已住客房%d\n",count);
}
}
LZ啊,你让我又回到了大二那会儿,记得我们的数据结构课程设计就有这个题目,不过当时我选的不是这个,我帮你改了半天终于没法而进行下去了。其中错误比较多的就是自定义函数声明部分,要想在主函数中使用自定义函数,要么你的自定义函数在主函数编译之前已经实现,要么你在主函数中或其上声明一下,这样才能调用的。还有部分函数更本就没实现,我现在也没太多时间在帮LZ想算法了。下面是我改好的部分,LZ如果在C、C++方面可以M我,可以和我讨论一下。#include"stdio.h"
#include"stdlib.h"
struct home{
char roomNO;
char name;
char sex;
char person;
char time;
char contain;
char money;
struct home *next;
struct home *prior;
}list_entry,*start,*last;
void search1();
int menu_select();
void enter();
void alter();
void search();
void cost();
void delete_fix();
void tongji();
void tuichu();
void inputs(int prompt,int s,int count);
void main()
{
start=0;
for(;;){
switch(menu_select()){
case 1:enter();break;
case 2:alter();break;
case 3:search();break;
case 4:cost();break;
case 5:delete_fix();break;
case 6:tongji();break;
case 7:tuichu();
}
}
}
int menu_select()
{
intc;
printf("\t\t=========================================================\n");
printf("\t\t=========================================================\n");
printf("\t\t==== 宾馆客房管理系统 ====\n");
printf("\t\t==== 请选择功能 ====\n");
printf("\t\t==== 1输入客房情况 ====\n");
printf("\t\t==== 2修改客房情况 ====\n");
printf("\t\t==== 3查询客房情况 ====\n");
printf("\t\t==== 4客房费用 ====\n");
printf("\t\t==== 5删除指定客房 ====\n");
printf("\t\t==== 6统计客房情况 ====\n");
printf("\t\t==== 7退出系统 ====\n");
printf("\t\t=========================================================\n");
printf("\t\t=========================================================\n");
do{
printf(" 请按数字选择\n");
scanf("%d",&c);getchar();
}while(c<0||c>10);
return c;
}
void enter()
{
struct home *info,*dls_store(); char s;char a="have";
for(;;)
{
info=(home *)malloc(sizeof(list_entry));
if(info==0)
{printf(" 内存已用完\n");
return;
}
inputs(" \t客房号码 \n",info->nember,10);
if(!info->nember) break;
inputs(" \t能住的人数\n",info->contain,10);
inputs(" \t有人输入have无人输入null\n",info->person,10);
if(!strcmp(a,info->person)){
inputs("\t姓名:\n",info->name,10);
inputs("\t姓别:\n",info->sex,10);
inputs("\t住入时间:\n",info->time,10);
}
inputs(" \t有人时输入时间无人输入\n",info->time,10);
inputs(" \t输入客房费用\n",info->money,10);
start=dls_store(info,start);
}
}
/*==============================
函数没实现啊亲~
===============================*/
void inputs(int prompt,int s,int count)
{
}
char *prompt;
char *s;
int count;
{
char p;
do{
printf(prompt);
gets(p);
if(strlen(p)>count)
printf(" 太长啦\n ");
}while(strlen(p)>count);
strcpy(s,p);
}
struct home *dls_store(i,top)
struct home *i,*top;
{
static struct home *last=0;
struct home *old,*p;
if(last==0){
i->next=0;
i->prior=0;
last=i;
return i;
}
p=top;
old=0;
while(p){
if(strcmp(p->nember,i->nember)<0){
old=p;
p=p->next;
}
else{
if(p->prior){
p->prior->next=i;
i->next=p;
p->prior=i;
return top;
}
i->next=p;
i->prior=0;
p->prior=i;
return i;
}
}
old->next=i;
i->next=0;
i->prior=old;
last=i;
return start;
}
void alter()
{
struct home *info,*find();
char roomNO;char a="have"; char c="null";
intb;
printf(" \t如想查看客房情况输入1\n");
printf(" \t想修改输入2\n");
printf(" \t不想修改输入3\n");
scanf("%d",&b);
if(b==1)search();
if(b==2){
printf(" \t请输入要客房号码\n");
scanf("%s",nember);getchar();
if(!(info=find(nember)))printf("\t没找到\n");
else
{
display(info);printf("\t下面是修改项目\n");
if(!strcmp(a,info->person))
inputs("\t请输入null:\n",info->person,10);
if(!strcmp(c,info->person)){
inputs("\t请输入名字\n",info->name,10);
inputs("\t请输入性别\n",info->sex,10);
inputs("\t请输入时间\n",info->time,10);
}
}
}
if(b==3) return;
}
struct home *find(nember)
char *nember;
{ struct home *info;
info=start;
while(info){
if(!strcmp(nember,info->nember)) return info;
info=info->next;
}
printf(" \t没找到\n");
return(NULL);
}
display(info)
struct home *info;
{ char a="have";
printf("\t客房号码: %s\n",info->nember);
printf("\t能住人数: %s\n",info->contain);
printf("\t无人住时显示null有人住时显示have:%s\n",info->person);
if(!strcmp(a,info->person)){
printf("\t名字%s\n",info->name);
printf("\t性别%s\n",info->sex);
printf("\t时间%s\n",info->time);}
printf("\t客房每天费用: %s\n",info->money);
printf("\n");
}
void search()
{
intb;
printf(" \t查询只定客房输入1\n");
printf(" \t查询已住客房输入2\n");
printf(" \t查询未住客房输入3\n");
printf(" \t返回主菜单请输入4\n");
do{
scanf("%d",&b);
switch(b){
case 1: search1();break;
case 2: search2();break;
case 3: search3();break;
case 4: return;
}
}while(b<1||b>5);
}
void search1()
{ char nember;
struct home *info,*find();
printf("\t输入房号码\n");
scanf("%s",nember); getchar();
if(!(info=find(nember))) printf("\t没找到\n");
else display(info);
}
search2()
{struct home *info;
char a="have";
info=start;
while(info){
if(!strcmp(info->person,a))
display(info);
printf("\n");
info=info->next;
}
}
search3()
{struct home *info;
char b="null";
info=start;
while(info){
if(!strcmp(b,info->person))
display(info);
printf(" \n ");
info=info->next;
}
}
save()
{
register int t,size;
struct home *info;
char *p;
FILE *fp;
if((fp=fopen("mlist","wb"))==0){
printf(" \t文件打不开\n");
exit(0);
}
printf("\t 正存入内存\n");
size=sizeof(list_entry);
info=start;
while(info){
p=(char*)info;
for(t=0;t<size;++t)
putc(*p++,fp);
info=info->next;
}
putc(EOF,fp);
fclose(fp);
printf("\t已存完\n");
}
void cost()
{
char nember;
struct home *info;
printf(" \t请输入客房号码\n");
gets(nember);
if(!(info=find(nember)))printf("\t没找到\n");
else{ display(info);
printf(" \t如果退房时间在12:00后按一天时间计算\n");
}
}
void delete_fix()
{
struct home *info,*find();
char nember;
printf(" \t请输入指定客房号码\n");
scanf("%s",&nember);
info=find(nember);
if(info){
if(start==info){
start=info->next;
if(start)
start->prior=0;}
else
last=0;
}
else
{
info->prior->next=info->next;
if(info!=last)
info->next->prior=info->prior;
else
last=info->prior;
}
free(info);
}
void tuichu()
{
int c;
printf("\t建议您最好存盘如果存盘输入1不存输入2\n");
scanf("%d",&c);
if(c==1) save();
if(c==2){
printf("\t谢谢您使用本系统:\n");
exit(0);
}
}
void tongji()
{
struct home *info;
char a="have";
char b="null";
int c,count=0;
printf("\t统计未住客房号码输入1已住客房号码输入2:\n");
scanf("%d",&c);
if(c==1){
info=start;
while(info)
{
if(!strcmp(a,info->person)) {
printf("\客房号码 %s \n",info->nember);
count++; }
info=info->next;
}
printf("\t共有未住客房%d个\n",count);
}
if(c==2)
{info=start;
while(info)
{ if(!strcmp(b,info->person))
{printf("\t客房号码 %s \n",info->nember);
count++;}
info=info->next;
}
printf("\t共有已住客房%d\n",count);
}
}下面在给你个成品连接(含课题报告)
旅店管理系统--数据结构课程设计报告:http://www.doc88.com/p-363142549896.html 求帮助啊 函数放上面,或者先声明
页:
[1]