非常急~~~请教高手帮忙解决一道C语言题目

机房机位预约模拟20台机器,从早8点到晚8点,每两小时一个时间段.需要实现的功能:(1)查询,根据输入时间,输出机位信息(2)机位预定,根据输入的日期和时间段查询是否有空... 机房机位预约模拟
20台机器,从早8点到晚8点,每两小时一个时间段.
需要实现的功能:
(1) 查询,根据输入时间,输出机位信息
(2)机位预定,根据输入的日期和时间段查询是否有空机位,若有则预约,若无则提供最近空机时间段.另:若用户要求在非空时间上机,则将用户信息插入该时间段的等待列表.
(3)退出预定,根据输入的时间,撤销该时间的预定.
(4)查询是否有等待信息,若有则按顺序现实联系方式,若无则显示提示信息
在线等,非常急~~~~~~~~~~
展开
 我来答
魔方宫殿
2008-09-24 · TA获得超过287个赞
知道小有建树答主
回答量:103
采纳率:0%
帮助的人:67.9万
展开全部
开发工具:vc6.0
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

void Display();
void Search();
void Book();
void Quit();
void Wait(int time);
void SearchWait();
void Exit();

int computernum[6]={20,20,20,20,20,20};

struct waitlist{
char phonenumber[12];
waitlist *next;
};

waitlist wait[6]={{"0",NULL},{"0",NULL},{"0",NULL},{"0",NULL},{"0",NULL},{"0",NULL}};

int main()
{
Display();
return 0;
}

void Display()
{
system("cls");
printf("\n\n\n\n\n");
printf("\t===============================================================\n");
printf("\t| COMPUTER BOOK SYSTEM |\n");
printf("\t===============================================================\n");
printf("\t| Choice: |\n");
printf("\t---------------------------------------------------------------\n");
printf("\t| 1: Search! |\n");
printf("\t---------------------------------------------------------------\n");
printf("\t| 2: BOOK! |\n");
printf("\t---------------------------------------------------------------\n");
printf("\t| 3: Quit! |\n");
printf("\t---------------------------------------------------------------\n");
printf("\t| 4: SearchWait! |\n");
printf("\t---------------------------------------------------------------\n");
printf("\t| 5: Exit! |\n");
printf("\t---------------------------------------------------------------\n");
printf("\tInput choice(1/2/3/4/5): ");
char c=getche();
printf("\n");
switch(c)
{
case '1':
Search();
break;
case '2':
Book();
break;
case '3':
Quit();
break;
case '4':
SearchWait();
break;
case '5':
Exit();
break;
default:
printf("\n\t\tWarning: ERROR chocie!!!\n");
Sleep(1000);
system("cls");
Display();
}
}

void Search()
{
int time;
char c;
system("cls");
printf("\t==========================================================\n");
printf("\t| Search() |\n");
printf("\t==========================================================\n");

printf("\tInput time(8-19):");
scanf("%d",&time);
while(time<8||time>19)
{
printf("\tWarning : Wrong time!\n");
printf("\tInput time(8-19):");
scanf("%d",&time);
}
printf("\tRemain computer(s) : %d\n",computernum[(time-8)/2]);
printf("\tContinue Search()? Y/N? ");
c=getche();
getch();
if(c=='Y'||c=='y')
Search();
else
Display();
}

void Book()
{
int time,i;
char c;
system("cls");
printf("\t==========================================================\n");
printf("\t| Book() |\n");
printf("\t==========================================================\n");
printf("\tInput time you book(8-19):");
scanf("%d",&time);
while(time<8||time>19)
{
printf("\tWarning : Wrong time!\n");
printf("\tInput time you book(8-19):");
scanf("%d",&time);
}
if(computernum[(time-8)/2]>0)
{
computernum[(time-8)/2]--;
printf("\tBook successed!\n");
getch();
Display();
}
else
{
printf("\tNo computer left at that time!\n");

for(i=(time-8)/2+1;i<6;i++)
if(computernum[i]>0)
printf("\tRecent free time is %d-%d\n",i+8,i+10);

printf("\n\tWait or not : Y/N? ");
if(c=='Y'||c=='y')
Wait(time);
else
Display();
}
}

void Wait(int time)
{
waitlist *p,*p1,*p2;
p=(waitlist *)malloc(sizeof(waitlist));
system("cls");
printf("\t==========================================================\n");
printf("\t| Wait() |\n");
printf("\t==========================================================\n");

printf("\tInput your telephone number:");
scanf("%s",p->phonenumber);

p1=wait[(time-8)/2].next;
while(p1!=NULL)
p1=p1->next;
p->next=p1->next;
p1->next=p;

printf("\t OK,Wait our phone please!");
getch();
Display();
}

void Quit()
{
int time;
system("cls");
printf("\t==========================================================\n");
printf("\t| Quit() |\n");
printf("\t==========================================================\n");
printf("\tInput time you book(8-19):");
scanf("%d",&time);
while(time<8||time>19)
{
printf("\tWarning : Wrong time!\n");
printf("\tInput time you book(8-19):");
scanf("%d",&time);
}
computernum[(time-8)/2]++;
printf("\tQuit successed!\n");
getch();
Display();
}

void SearchWait()
{
int time;
waitlist *p;
system("cls");
printf("\t==========================================================\n");
printf("\t| SearchWait() |\n");
printf("\t==========================================================\n");
printf("\tInput time you search(8-19):");
scanf("%d",&time);
while(time<8||time>19)
{
printf("\tWarning : Wrong time!\n");
printf("\tInput time you search(8-19):");
scanf("%d",&time);
}
if(wait[(time-8)/2].next==NULL)
printf("\tNo customer wait!\n");
else
{
p=wait[(time-8)/2].next;
while(p!=NULL)
{
printf("\t%s\n",p->phonenumber);
p=p->next;
}
}
getch();
Display();
}

void Exit()
{
system("cls");
printf("\n\n\n\n\n\n\t\t\tSee you next time!\n\n\n\n\n\n\n");
exit(0);
}
对水持f
2008-09-27
知道答主
回答量:9
采纳率:0%
帮助的人:4.1万
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define LENGTH 6
#define MAX 20
#define S(r) (r-8)/2
#define NULL 0

struct node{
int locat;
char data[10];
struct node *next;
};

struct node *head;

struct cell{
int CNum;
struct node *first;
struct node *middle;
struct node *last;
}TimeQueue[LENGTH];

void Inquir()
{
int n;
char Infor[10];
struct node *Rem;
printf("Please input the time you want to search!(24 hours 8~20 o'clock,include 8o'clock)\n");
scanf("%d",&n);
if(n>=8&&n<20){
n=S(n);
printf("Please input your No.!\n");
scanf("%s",Infor);
Rem=TimeQueue[n].first;
for(;Rem->next!=NULL;Rem=Rem->next)
if(strcmp(Rem->data,Infor)==0)break;
if(Rem->locat!=0)
printf("The computer number is %d\n",Rem->locat);
else printf("Sorry,you are still in the queue or you haven't booked!");
}
else printf("Error!Please input again.\n");
}

void inquir()
{
int n;
printf("Please input the time you want to search!(24 hours 8~20o'clock,include 8 o'clock)\n");
scanf("%d",&n);
if(n>=8&&n<20){
n=S(n);
if(TimeQueue[n].CNum<MAX)
printf("There are %d empty computer!\n",MAX-TimeQueue[n].CNum);
else printf("Sorry,there is no empty computer!\n");
}
else printf("Error!Please input again.\n");
}

void booking()
{
int n;
char Infor[10];
struct node *Rem;
struct node *p;
printf("Please input the time you want to book!\n");
scanf("%d",&n);
if(n>=8&&n<20){
n=S(n);
if(TimeQueue[n].CNum<MAX){

printf("Please input your No.!\n");
scanf("%s",Infor);

if(TimeQueue[n].first==NULL){
Rem=(struct node *)malloc(sizeof(struct node));
Rem->locat=1;
strcpy(Rem->data,Infor);
Rem->next=NULL;
TimeQueue[n].first=Rem;
TimeQueue[n].last=Rem;
TimeQueue[n].CNum++;
printf("Succeed to book!\n");
}
else{
Rem=(struct node *)malloc(sizeof(struct node));
strcpy(Rem->data,Infor);
Rem->next=NULL;
p=TimeQueue[n].last;
Rem->locat=TimeQueue[n].CNum+1;
printf("%d",Rem->locat);
TimeQueue[n].last=Rem;
p->next=Rem;
TimeQueue[n].CNum++;
printf("Succeed to book!\n");
}
}
else printf("There in no empty computer!");
}
else printf("Error!Please input again.\n");
}

void waiting()
{
int n;
char Infor[10];
struct node *Rem;
struct node *p;
printf("Please input the time you want to queue!\n");
scanf("%d",&n);
if(n>=8&&n<20){
n=S(n);
if(TimeQueue[n].CNum>=MAX){
printf("Please input your No.!\n");
scanf("%s",Infor);

if((TimeQueue[n].CNum)==MAX){
Rem=(struct node *)malloc(sizeof(struct node));
strcpy(Rem->data,Infor);
Rem->next=NULL;
Rem->locat=0;
p=TimeQueue[n].last;
TimeQueue[n].last=Rem;
p->next=Rem;
TimeQueue[n].middle=Rem;
TimeQueue[n].CNum++;
printf("Succeed to in the queue!\n");
}
else{
Rem=(struct node *)malloc(sizeof(struct node));
strcpy(Rem->data,Infor);
Rem->next=NULL;
Rem->locat=0;
p=TimeQueue[n].last;
TimeQueue[n].last=Rem;
p->next=Rem;
TimeQueue[n].CNum++;
printf("Succeed to in the queue!\n");
}
}
else printf("There have empty computer!No waiting!\n");
}
else printf("Error!Please input again.\n");
}

void cancel()
{
int n;
int i;
char Infor[10];
struct node *Rem;
struct node *q;
struct node *p;
printf("Please input the time you have booked!\n");
scanf("%d",&n);
if(n>=8&&n<20){
printf("Please input your No.!\n");
scanf("%s",Infor);
n=S(n);
Rem=TimeQueue[n].first;
q=Rem;
for(i=1;;q=Rem,Rem=Rem->next,i++)
if(strcmp(Rem->data,Infor)==0)break;
if(i>MAX){
if(Rem->next==NULL){
q->next=NULL;
TimeQueue[n].last=q;
free(Rem);
TimeQueue[n].CNum--;
printf("Succeed to out the queue!\n");
}
else{
q->next=Rem->next;
free(Rem);
TimeQueue[n].CNum--;
printf("Succeed to out the queue!\n");
}
}
else{
if(TimeQueue[n].CNum>MAX){
TimeQueue[n].middle->locat=Rem->locat;
TimeQueue[n].middle=TimeQueue[n].middle->next;
}
if(i==1) TimeQueue[n].first=Rem->next;
else q->next=Rem->next;
free(Rem);
TimeQueue[n].CNum--;
printf("Succeed to exit booking!\n");

}
}
else printf("Error!Please input again.\n");
}

void inquir_waiting()
{
int n;
struct node *q;
printf("Please input the time you want to search if there are waiter!\n");
scanf("%d",&n);
if(n>=8&&n<20){
n=S(n);
if(TimeQueue[n].CNum>MAX){
printf("The waiting queue are:\n");
q=TimeQueue[n].middle;
for(;q->next!=NULL;q=q->next) printf("%s\n",q->data);
printf("%s\n",TimeQueue[n].last->data);
}
else printf("There are no waiter during this period !\n");
}
else printf("Eroor!Please input again.\n");
}

main()
{
int i;
for(i=0;i<LENGTH;i++){
TimeQueue[i].CNum=0;
TimeQueue[i].first=NULL;
TimeQueue[i].middle=NULL;
TimeQueue[i].last=NULL;
}

while(1){
printf("Please input the number!:\n");
printf("1. search my booking state 2.search empty computer 3.booking 4. cancel booking 5.queue 6.search wainting 0.exit\n");
scanf("%d",&i);
switch(i)
{
case 1:Inquir();break;
case 2:inquir();break;
case 3:booking();break;
case 4:cancel();break;
case 5:waiting();break;
case 6:inquir_waiting();break;
case 0:exit(0);
default:printf("error\n");
}
}
}
已经运行过了,没有错误

参考资料: 我也是人家给的,呵呵

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
高金山
2008-09-24 · TA获得超过1万个赞
知道大有可为答主
回答量:4101
采纳率:0%
帮助的人:1650万
展开全部
还需要网络功能的吧。比较麻烦啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
飘渺孤舟
2008-09-24
知道答主
回答量:87
采纳率:0%
帮助的人:0
展开全部
好难啊……
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
流水不腐小夏
2008-09-24 · 超过41用户采纳过TA的回答
知道小有建树答主
回答量:174
采纳率:0%
帮助的人:129万
展开全部
不会……
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2008-09-26
展开全部
你搞定了吗,我的问题跟你一样,搞完了也发给我啊,我的问题也在上面
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 5条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式