帮忙,急救!

vampire_3 2009-06-16 10:09:14
请各位把我的这个程序改一下,改成能够运行

设计题目是电梯模拟(或者帮忙传个C语言的代码给我)

#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define datatype int
#define MaxSize 9
#define ok 1
typedef struct //队列,结构体定义
{
int data;
int num;
int curtime;
int front;
int rear;
int count;
typedef struct *next;
}SeQueue;
datatype Mg[MaxSize];
void Init_Queue(SeQueue *q)//初始化队列Q
{
q->count=0;//定义初始计数器值
q->front=0;//定义初始队头指针下标值
q->rear=0;//定义初始队尾指针下标值
}

int Empty_Queue(SeQueue *q)
{
if(q->count!=0)
return 1;
else
return 0;
}
int In_Queue(SeQueue *q,datatype x,datatype y,datatype z)//入队列
{
int i=1;
if(q->count>0 && q->rear==q->front)
{
printf("队列已满无法插入!\n");
return 0;
}
else
{
q->data=x;
while(i<=y)
{
q->num=i;
i++;
}
q->curtime=z;
q->count++;
return 1;
}
}
int Out_Queue(SeQueue *q, int *x,int *y,datatype *z)//出队列
{
if(q->count=0)
{
printf("队列已空无数据元素出队列!\n");
return 0;
}
else
{
*x=q->data;
*y=q->num;
*z=q->curtime;
q->count--;
return q->count;
}
}
datatype Front_Queue(SeQueue *q,datatype x)//取队列元素
{
if(q->count=0)
{
printf("队列已空无数据元素可取!\n");
return 0;
}
else
{
x=q->data;
return x;
}
}
int up(int floor,int Mg[MaxSize],int Rg[MaxSize])//上楼
{
int time=0,time2;
int c,b=0,d;
while(floor<=5)
{
c=Mg[b];
d=Rg[b];
if(d>c)
printf("电梯正在往上运行,乘客请等待");
else if(c!=floor&&d!=floor)
printf("电梯正在运行");
else if(c==floor&&d!=floor)
{
printf("目的楼层已经到了,乘客请出电梯");
time=time+20*(d-c);
printf("\t\t%d 时刻,电梯到达第%d层\n",time,floor);
time2=time2+50;
}
else if(c!=floor&&d==floor)
{
printf("楼层已到,请乘客入电梯");
time2=time2+50;
}
else
{
printf("目的楼层已经到了,相关乘客请出电梯");
time=20*(d-c);
printf("\t\t%d 时刻,电梯到达第%d层\n",time,floor);
time2=time2+50;
printf("楼层已到,相关乘客请入电梯");
}
b++;
floor++;
time=time2;
}
return b;
}
void down(int b,int Mg[MaxSize],int Rg[MaxSize])//下楼
{
int time,time2,floor=5,c,d;
while(floor>=1)
{
c=Mg[b];
d=Rg[b];
if(d<c)
printf("电梯正在往下运行,乘客请等待");
else if(c!=floor&&d!=floor)
printf("电梯正在运行");
else if(c==floor&&d!=floor)
{
printf("目的楼层已经到了,乘客请出电梯");
time=time+20*(d-c);
printf("\t\t%d 时刻,电梯到达第%d层\n",time,floor);
time2=time2+50;
}
else if(c!=floor&&d==floor)
{
printf("楼层已到,请乘客入电梯");
time2=time2+50;
}
else
{
printf("目的楼层已经到了,相关乘客请出电梯");
time=20*(d-c);
printf("\t\t%d 时刻,电梯到达第%d层\n",time,floor);
time2=time2+50;
printf("楼层已到,相关乘客请入电梯");
}
b++;
floor--;
time=time2;
}
}
void paixu(datatype Mg[],int n)
{
int i,j,temp;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
if(Mg[i]>Mg[j])
{
temp=Mg[i];
Mg[j]=temp;
Mg[i]=Mg[j];
}
}
}
int main()
{
int *p,*t,*r;
int i,x,y,z,flag=1,m,n,c,b,k=1;
int j=1,floor=1;
int Mg[MaxSize],Rg[MaxSize];//记录到达的楼层信息
SeQueue from,go;
int time1;
int state=1;
Init_Queue(&from);
Init_Queue(&go);
printf("\t\t *****************************************************\n");
printf("\t\t * *\n");
printf("\t\t * 电梯模拟程序 *\n");
printf("\t\t * *\n");
printf("\t\t *****************************************************\n");
printf("电梯在本垒层候命");
printf("此电梯的层数为5");
while(flag)
{
printf("是否有人要进入此电梯,是的输入1,否则输入0");
scanf("%",&i);
if(i==0)
{
flag=0;
printf("over");
printf("谢谢光顾");
}
else
{
printf("请输入你所在的楼层");
scanf("%d",&x);
printf("此人向电梯发送的时间");
scanf("%d",&z);
printf("请输入你的最大容忍时间是");
scanf("%d",&time1);
In_Queue(&from,&x,&y,&z);
printf("请输入你要到达的楼层");
scanf("%d",&n);
In_Queue(&go,&n,&y,&z);
Mg[j-1]=n;
Rg[j-1]=x;
j++;
y++;
}
k=j;
from=from->next;
go=go->next;
}
paixu(Mg,y);
paixu(Rg,y);
while(k!=0)
{
Out_Queue(go,p,t,r);
printf("第%d名乘客到%d层",*p,*t);
k=Out_Queue(go,p,t,r);
}
while(state)
{
printf("如果你想结束电梯的运行请输入0,否则输入1");
scanf("%d",&m);
state=m;
printf("电梯准备运行");
up(floor,Mg,Rg);
b=up(floor,Mg,Rg);
down(b,Mg,Rg);
}
printf("欢迎乘坐该电梯");
return ok;
}
错误是:

-------------------Configuration: 电梯模拟4 - Win32 Debug--------------------
Compiling...
电梯模拟4.cpp
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(207) : error C2664: 'In_Queue' : cannot convert parameter 2 from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(210) : error C2664: 'In_Queue' : cannot convert parameter 2 from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(217) : error C2819: type 'SeQueue' does not have an overloaded member 'operator ->'
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(9) : see declaration of 'SeQueue'
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(217) : error C2227: left of '->next' must point to class/struct/union
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(218) : error C2819: type 'SeQueue' does not have an overloaded member 'operator ->'
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(9) : see declaration of 'SeQueue'
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(218) : error C2227: left of '->next' must point to class/struct/union
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(224) : error C2664: 'Out_Queue' : cannot convert parameter 1 from 'SeQueue' to 'SeQueue *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Documents and Settings\01.01-0DFBDBB6E43B\桌面\电梯模拟4.cpp(226) : error C2664: 'Out_Queue' : cannot convert parameter 1 from 'SeQueue' to 'SeQueue *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.

电梯模拟4.obj - 1 error(s), 0 warning(s)



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/luojie1990go/archive/2009/06/16/4272345.aspx
...全文
30 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
vampire_3 2009-06-16
  • 打赏
  • 举报
回复
非常感谢!
太乙 2009-06-16
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define datatype int
#define MaxSize 9
#define ok 1
typedef struct A//队列,结构体定义
{
int data;
int num;
int curtime;
int front;
int rear;
int count;
struct A *next;
}SeQueue;
datatype Mg[MaxSize];
void Init_Queue(SeQueue *q)//初始化队列Q
{
q->count=0;//定义初始计数器值
q->front=0;//定义初始队头指针下标值
q->rear=0;//定义初始队尾指针下标值
}

int Empty_Queue(SeQueue *q)
{
if(q->count!=0)
return 1;
else
return 0;
}
int In_Queue(SeQueue *q,datatype x,datatype y,datatype z)//入队列
{
int i=1;
if(q->count>0 && q->rear==q->front)
{
printf("队列已满无法插入!\n");
return 0;
}
else
{
q->data=x;
while(i <=y)
{
q->num=i;
i++;
}
q->curtime=z;
q->count++;
return 1;
}
}
int Out_Queue(SeQueue *q, int *x,int *y,datatype *z)//出队列
{
if(q->count=0)
{
printf("队列已空无数据元素出队列!\n");
return 0;
}
else
{
*x=q->data;
*y=q->num;
*z=q->curtime;
q->count--;
return q->count;
}
}
datatype Front_Queue(SeQueue *q,datatype x)//取队列元素
{
if(q->count=0)
{
printf("队列已空无数据元素可取!\n");
return 0;
}
else
{
x=q->data;
return x;
}
}
int up(int floor,int Mg[MaxSize],int Rg[MaxSize])//上楼
{
int time=0,time2;
int c,b=0,d;
while(floor <=5)
{
c=Mg[b];
d=Rg[b];
if(d>c)
printf("电梯正在往上运行,乘客请等待");
else if(c!=floor&&d!=floor)
printf("电梯正在运行");
else if(c==floor&&d!=floor)
{
printf("目的楼层已经到了,乘客请出电梯");
time=time+20*(d-c);
printf("\t\t%d 时刻,电梯到达第%d层\n",time,floor);
time2=time2+50;
}
else if(c!=floor&&d==floor)
{
printf("楼层已到,请乘客入电梯");
time2=time2+50;
}
else
{
printf("目的楼层已经到了,相关乘客请出电梯");
time=20*(d-c);
printf("\t\t%d 时刻,电梯到达第%d层\n",time,floor);
time2=time2+50;
printf("楼层已到,相关乘客请入电梯");
}
b++;
floor++;
time=time2;
}
return b;
}
void down(int b,int Mg[MaxSize],int Rg[MaxSize])//下楼
{
int time,time2,floor=5,c,d;
while(floor>=1)
{
c=Mg[b];
d=Rg[b];
if(d <c)
printf("电梯正在往下运行,乘客请等待");
else if(c!=floor&&d!=floor)
printf("电梯正在运行");
else if(c==floor&&d!=floor)
{
printf("目的楼层已经到了,乘客请出电梯");
time=time+20*(d-c);
printf("\t\t%d 时刻,电梯到达第%d层\n",time,floor);
time2=time2+50;
}
else if(c!=floor&&d==floor)
{
printf("楼层已到,请乘客入电梯");
time2=time2+50;
}
else
{
printf("目的楼层已经到了,相关乘客请出电梯");
time=20*(d-c);
printf("\t\t%d 时刻,电梯到达第%d层\n",time,floor);
time2=time2+50;
printf("楼层已到,相关乘客请入电梯");
}
b++;
floor--;
time=time2;
}
}
void paixu(datatype Mg[],int n)
{
int i,j,temp;
for(i=1;i <=n;i++)
for(j=i+1;j <=n;j++)
{
if(Mg[i]>Mg[j])
{
temp=Mg[i];
Mg[j]=temp;
Mg[i]=Mg[j];
}
}
}
int main()
{
int *p,*t,*r;
int i,x,y,z,flag=1,m,n,c,b,k=1;
int j=1,floor=1;
int Mg[MaxSize],Rg[MaxSize];//记录到达的楼层信息
SeQueue from,go;
int time1;
int state=1;
Init_Queue(&from);
Init_Queue(&go);
printf("\t\t *****************************************************\n");
printf("\t\t * *\n");
printf("\t\t * 电梯模拟程序 *\n");
printf("\t\t * *\n");
printf("\t\t *****************************************************\n");
printf("电梯在本垒层候命");
printf("此电梯的层数为5");
while(flag)
{
printf("是否有人要进入此电梯,是的输入1,否则输入0");
scanf("%",&i);
if(i==0)
{
flag=0;
printf("over");
printf("谢谢光顾");
}
else
{
printf("请输入你所在的楼层");
scanf("%d",&x);
printf("此人向电梯发送的时间");
scanf("%d",&z);
printf("请输入你的最大容忍时间是");
scanf("%d",&time1);
In_Queue(&from,x,y,z);
printf("请输入你要到达的楼层");
scanf("%d",&n);
In_Queue(&go,n,y,z);
Mg[j-1]=n;
Rg[j-1]=x;
j++;
y++;
}
k=j;
from=*(from.next);
go=*(go.next);
}
paixu(Mg,y);
paixu(Rg,y);
while(k!=0)
{
Out_Queue(&go,p,t,r);
printf("第%d名乘客到%d层",*p,*t);
k=Out_Queue(&go,p,t,r);
}
while(state)
{
printf("如果你想结束电梯的运行请输入0,否则输入1");
scanf("%d",&m);
state=m;
printf("电梯准备运行");
up(floor,Mg,Rg);
b=up(floor,Mg,Rg);
down(b,Mg,Rg);
}
printf("欢迎乘坐该电梯");
return ok;
}





能编译,后面的就不保证了!

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧