课题名称:食堂就餐仿真(2).课题描述:
设计一个描述莫校城建学院学生一食堂工作过程的离散模拟系统。设食堂内有N个窗口同时为同学
们服务,当同学们进入食堂时,自行选择某一窗口排队。试设计一个模拟系统,模拟食堂的就
餐情况,分析每位同学排队时间、队列平均长度。设计要求:
选择合适的数据结构和算法,让计算机模拟模拟食堂就餐情况,求出相应的经营参数。要求采
用链式存储结构。以下是例子: 食堂就餐仿真(1)
课题编号:DE-0168
课题名称:食堂就餐仿真(1)
课题描述:
设计一个描述莫校城建学院学生一食堂工作过程的离散模拟系统。设食堂内有N个窗口同时为同学们服务,当同学们进入食堂时,自行选择某一窗口排队。试设计一个模拟系统,模拟食堂的就餐情况,分析每位同学排队时间、队列平均长度。
设计要求:
选择合适的数据结构和算法,让计算机模拟食堂就餐情况,求出相应的经营参数。要求采用顺序存储结构。需求分析 :
1 用户输入F(fast)或N(normal)或S(slow)来选择模拟速度(大小写均可)。2 输出显示学生到达(Come)以及从不同窗口离开(Go)的时间,并统计出相应的经营参数:平均排队时间、平均队列长度。3 本程序模拟了食堂中午就餐情况,并统计出相应的经营参数(平均排队时间、平均队列长度)。4测试数据:
1).输入 k
输出 输入无效!
请输入模拟速度(F.N.S):
2).输入 F
输出 11: 0: 0 COME
11: 0:10 COME
11: 0:13 COME
11: 0:16 COME
11: 0:18 COME
11: 0:24 2GO
.
.
.
12:59:48 1GO
12:59:48 3GO
12:59:49 3GO
12:59:53 COME
12:59:59 4GO
平均队列长度:12人
平均排队时间:5分/人
总体设计:
1 数据类型:
int //整型
long //长整型
char //字符型
struct c;//结构体元素类型
struct Queue;//顺序存储队列
void InitQueue(Queue& Q);
//初始化队列Q,即置Q为空
int QueueEmpty(Queue& Q);
//判断队列Q是否为空,若是则返回1,否则返回0
int QLength(Queue& Q)
//返回队列Q的长度
ElemType QFront(Queue& Q)
//返回队首元素,但不改变队列的状态
void QInsert(Queue& Q,const ElemType& item)
//将新元素item插入到队尾
void QDelete(Queue& Q)
//从队列Q中删除队首元素
2 主程序流程:模拟速度选取
队列、时间初始化
启动模拟时钟,出队入队操作
统计数据
3 各模块功能:
输入模块——模拟速度选取
初始模块——时间队列初始化
到达模块——处理入队操作
离开模块——处理出队操作
输出模块——统计经营参数
时钟模块——模拟全过程
主程序模块——模拟统计
4 模块层次关系图:
主程序模块
输入模块 初始模块 时钟模块 输出模块
到达模块 离开模块详细设计:
1数据类型具体实现:
const int QueueMaxSize=100; //队列最大空间struct c{
long ArrivalTime;
long LeaveTime;
}customer;
typedef c ElemType;
struct Queue{
ElemType queue[QueueMaxSize];
long front,rear;
}; int i,
s, //秒
m, //分
h, //时
n=0,
a[240];
long x=0, //队列总长
num=0, //人数
DuraTime=0, //排队时间
ComeTime, //到达时间
GoTime1=0,GoTime2=0,GoTime3=0,GoTime4=0; //各队离开时间
long k,
Size;
char O; //输入变量
Queue q1,q2,q3,q4; //4个队列
void InitQueue(Queue& Q)
{
Q.front=Q.rear=0;
}int QueueEmpty(Queue& Q)
{
return Q.front==Q.rear;
}int QLength(Queue& Q)
{
return (QueueMaxSize+Q.rear-Q.front)%QueueMaxSize;
}ElemType QFront(Queue& Q)
{
return Q.queue[(Q.front+1)%QueueMaxSize];
}
void QInsert(Queue& Q,const ElemType& item)
{
int k=(Q.rear+1)%QueueMaxSize;
Q.rear=k;
Q.queue[k]=item;
}void QDelete(Queue& Q)
{
Q.front=(Q.front+1)%QueueMaxSize;
}
2 伪码算法设计
void Speed()
{
putin;
if(s) Size=30000000; //选择快速
else if(n) Size=3000000; //选择中速
else if(f) Size=3000; //选择慢速
else
{
out;
Speed(); //无效输入,返回
}
}//速度选取void Open()
{
customer.ArrivalTime=0; //第一个到达时间为0
InitQueue; //队列置空
}//初始化操作void Go()
{
if(!QueueEmpty(q1)) //如果队列非空
{
customer=QFront(q1); //读取q1的首元素
if(time==customer.LeaveTime)//如果此时为离开时间
{
showLeave; //输出此时刻一号窗有人离开
QDelete(q1); //从q1将其删除
}
} //一号窗口的离开时间
if(!QueueEmpty(q2))
{
customer=QFront(q2);
if(time==customer.LeaveTime)
{
showLeave;
QDelete(q2);
}
} //二号窗口的离开时间
if(!QueueEmpty(q3))
{
customer=QFront(q3);
if(time==customer.LeaveTime)
{
showLeave;
QDelete(q3);
}
} //三号窗口的离开时间
if(!QueueEmpty(q4))
{
customer=QFront(q4);
if(time==customer.LeaveTime)
{
showLeave;
QDelete(q4);
}
} //四号窗口的离开时间
}//处理离开时间void Choice()
{
srand(t); //随机初始化
i=random; //随机选择窗口
if(i==1)
{
srand(t);
if(customer.ArrivalTime>GoTime1)
GoTime1=random+customer.ArrivalTime;
else
GoTime1=random+GoTime1;
customer.LeaveTime=GoTime1; //生成离开时间
QInsert(q1,customer); //插入q1 DuraTime=customer.LeaveTime-customer.ArrivalTime+DuraTime;
//累计排队时间
}//到达一号窗口事件
if(i==2)
{
srand(t);
if(customer.ArrivalTime>GoTime2)
GoTime2=random+customer.ArrivalTime;
else
GoTime2=random+GoTime2;
customer.LeaveTime=GoTime2;
QInsert(q2,customer);
DuraTime=customer.LeaveTime-customer.ArrivalTime+DuraTime;
}//到达二号窗口事件
if(i==3)
{
srand(t);
if(customer.ArrivalTime>GoTime3)
GoTime3=random+1+customer.ArrivalTime;
else
GoTime3=random+1+GoTime3;
customer.LeaveTime=GoTime3;
QInsert(q3,customer);
DuraTime=customer.LeaveTime-customer.ArrivalTime+DuraTime;
}//到达三号窗口事件
if(i==4)
{
srand(t);
if(customer.ArrivalTime>GoTime4)
GoTime4=random+1+customer.ArrivalTime;
else
GoTime4=random+1+GoTime4;
customer.LeaveTime=GoTime4;
QInsert(q4,customer);
DuraTime=customer.LeaveTime-customer.ArrivalTime+DuraTime;
}//到达四号窗口事件
}//窗口选择void Come()
{
if(ComeTime<t)
{
srand(t);
ComeTime=random+1+ComeTime;
customer.ArrivalTime=ComeTime;
} //生成到达时间,但尚未到达时
if(ComeTime==t)
{
customer.ArrivalTime=ComeTime;
num++;
showcome; //显示到达
Choice(); //窗口选择
} //已到达
}到达事件void Record()
{
if(s==59)
{
a[n]=QLength(q1)+QLength(q2)+QLength(q3)+QLength(q4);
n++;
}
}//30秒记录一次队列总长void Stumilation()
{
for(i=0;i<120;i++)
x=a[i]/4+x;
showlongth; //显示平均队列长度
showtime; //显示平均排队时间
}//统计经营参数 void main()
{
Right();
设计一个描述莫校城建学院学生一食堂工作过程的离散模拟系统。设食堂内有N个窗口同时为同学
们服务,当同学们进入食堂时,自行选择某一窗口排队。试设计一个模拟系统,模拟食堂的就
餐情况,分析每位同学排队时间、队列平均长度。设计要求:
选择合适的数据结构和算法,让计算机模拟模拟食堂就餐情况,求出相应的经营参数。要求采
用链式存储结构。以下是例子: 食堂就餐仿真(1)
课题编号:DE-0168
课题名称:食堂就餐仿真(1)
课题描述:
设计一个描述莫校城建学院学生一食堂工作过程的离散模拟系统。设食堂内有N个窗口同时为同学们服务,当同学们进入食堂时,自行选择某一窗口排队。试设计一个模拟系统,模拟食堂的就餐情况,分析每位同学排队时间、队列平均长度。
设计要求:
选择合适的数据结构和算法,让计算机模拟食堂就餐情况,求出相应的经营参数。要求采用顺序存储结构。需求分析 :
1 用户输入F(fast)或N(normal)或S(slow)来选择模拟速度(大小写均可)。2 输出显示学生到达(Come)以及从不同窗口离开(Go)的时间,并统计出相应的经营参数:平均排队时间、平均队列长度。3 本程序模拟了食堂中午就餐情况,并统计出相应的经营参数(平均排队时间、平均队列长度)。4测试数据:
1).输入 k
输出 输入无效!
请输入模拟速度(F.N.S):
2).输入 F
输出 11: 0: 0 COME
11: 0:10 COME
11: 0:13 COME
11: 0:16 COME
11: 0:18 COME
11: 0:24 2GO
.
.
.
12:59:48 1GO
12:59:48 3GO
12:59:49 3GO
12:59:53 COME
12:59:59 4GO
平均队列长度:12人
平均排队时间:5分/人
总体设计:
1 数据类型:
int //整型
long //长整型
char //字符型
struct c;//结构体元素类型
struct Queue;//顺序存储队列
void InitQueue(Queue& Q);
//初始化队列Q,即置Q为空
int QueueEmpty(Queue& Q);
//判断队列Q是否为空,若是则返回1,否则返回0
int QLength(Queue& Q)
//返回队列Q的长度
ElemType QFront(Queue& Q)
//返回队首元素,但不改变队列的状态
void QInsert(Queue& Q,const ElemType& item)
//将新元素item插入到队尾
void QDelete(Queue& Q)
//从队列Q中删除队首元素
2 主程序流程:模拟速度选取
队列、时间初始化
启动模拟时钟,出队入队操作
统计数据
3 各模块功能:
输入模块——模拟速度选取
初始模块——时间队列初始化
到达模块——处理入队操作
离开模块——处理出队操作
输出模块——统计经营参数
时钟模块——模拟全过程
主程序模块——模拟统计
4 模块层次关系图:
主程序模块
输入模块 初始模块 时钟模块 输出模块
到达模块 离开模块详细设计:
1数据类型具体实现:
const int QueueMaxSize=100; //队列最大空间struct c{
long ArrivalTime;
long LeaveTime;
}customer;
typedef c ElemType;
struct Queue{
ElemType queue[QueueMaxSize];
long front,rear;
}; int i,
s, //秒
m, //分
h, //时
n=0,
a[240];
long x=0, //队列总长
num=0, //人数
DuraTime=0, //排队时间
ComeTime, //到达时间
GoTime1=0,GoTime2=0,GoTime3=0,GoTime4=0; //各队离开时间
long k,
Size;
char O; //输入变量
Queue q1,q2,q3,q4; //4个队列
void InitQueue(Queue& Q)
{
Q.front=Q.rear=0;
}int QueueEmpty(Queue& Q)
{
return Q.front==Q.rear;
}int QLength(Queue& Q)
{
return (QueueMaxSize+Q.rear-Q.front)%QueueMaxSize;
}ElemType QFront(Queue& Q)
{
return Q.queue[(Q.front+1)%QueueMaxSize];
}
void QInsert(Queue& Q,const ElemType& item)
{
int k=(Q.rear+1)%QueueMaxSize;
Q.rear=k;
Q.queue[k]=item;
}void QDelete(Queue& Q)
{
Q.front=(Q.front+1)%QueueMaxSize;
}
2 伪码算法设计
void Speed()
{
putin;
if(s) Size=30000000; //选择快速
else if(n) Size=3000000; //选择中速
else if(f) Size=3000; //选择慢速
else
{
out;
Speed(); //无效输入,返回
}
}//速度选取void Open()
{
customer.ArrivalTime=0; //第一个到达时间为0
InitQueue; //队列置空
}//初始化操作void Go()
{
if(!QueueEmpty(q1)) //如果队列非空
{
customer=QFront(q1); //读取q1的首元素
if(time==customer.LeaveTime)//如果此时为离开时间
{
showLeave; //输出此时刻一号窗有人离开
QDelete(q1); //从q1将其删除
}
} //一号窗口的离开时间
if(!QueueEmpty(q2))
{
customer=QFront(q2);
if(time==customer.LeaveTime)
{
showLeave;
QDelete(q2);
}
} //二号窗口的离开时间
if(!QueueEmpty(q3))
{
customer=QFront(q3);
if(time==customer.LeaveTime)
{
showLeave;
QDelete(q3);
}
} //三号窗口的离开时间
if(!QueueEmpty(q4))
{
customer=QFront(q4);
if(time==customer.LeaveTime)
{
showLeave;
QDelete(q4);
}
} //四号窗口的离开时间
}//处理离开时间void Choice()
{
srand(t); //随机初始化
i=random; //随机选择窗口
if(i==1)
{
srand(t);
if(customer.ArrivalTime>GoTime1)
GoTime1=random+customer.ArrivalTime;
else
GoTime1=random+GoTime1;
customer.LeaveTime=GoTime1; //生成离开时间
QInsert(q1,customer); //插入q1 DuraTime=customer.LeaveTime-customer.ArrivalTime+DuraTime;
//累计排队时间
}//到达一号窗口事件
if(i==2)
{
srand(t);
if(customer.ArrivalTime>GoTime2)
GoTime2=random+customer.ArrivalTime;
else
GoTime2=random+GoTime2;
customer.LeaveTime=GoTime2;
QInsert(q2,customer);
DuraTime=customer.LeaveTime-customer.ArrivalTime+DuraTime;
}//到达二号窗口事件
if(i==3)
{
srand(t);
if(customer.ArrivalTime>GoTime3)
GoTime3=random+1+customer.ArrivalTime;
else
GoTime3=random+1+GoTime3;
customer.LeaveTime=GoTime3;
QInsert(q3,customer);
DuraTime=customer.LeaveTime-customer.ArrivalTime+DuraTime;
}//到达三号窗口事件
if(i==4)
{
srand(t);
if(customer.ArrivalTime>GoTime4)
GoTime4=random+1+customer.ArrivalTime;
else
GoTime4=random+1+GoTime4;
customer.LeaveTime=GoTime4;
QInsert(q4,customer);
DuraTime=customer.LeaveTime-customer.ArrivalTime+DuraTime;
}//到达四号窗口事件
}//窗口选择void Come()
{
if(ComeTime<t)
{
srand(t);
ComeTime=random+1+ComeTime;
customer.ArrivalTime=ComeTime;
} //生成到达时间,但尚未到达时
if(ComeTime==t)
{
customer.ArrivalTime=ComeTime;
num++;
showcome; //显示到达
Choice(); //窗口选择
} //已到达
}到达事件void Record()
{
if(s==59)
{
a[n]=QLength(q1)+QLength(q2)+QLength(q3)+QLength(q4);
n++;
}
}//30秒记录一次队列总长void Stumilation()
{
for(i=0;i<120;i++)
x=a[i]/4+x;
showlongth; //显示平均队列长度
showtime; //显示平均排队时间
}//统计经营参数 void main()
{
Right();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货