资源简介
完整的六层电梯程序,已经试验过,可用,希望对各位有用,有什么建议,欢迎提出
![](http://www.nz998.com/pic/46091.jpg)
代码片段和文件信息
#include
#include
#include
#include “lift.h“
/* some global stats */
int total_waiting = 0;
int no_of_waits = 0;
int max_wait = 0;
int min_wait = 10000000;
/*
* Initialize the floors
*/
void init_floors(struct floor_s* floors)
{
int i = 0;
for(i = 0; i < NO_OF_FLOORS; i++) {
floors[i].floor_number = i;
floors[i].num_waiting = 0;
floors[i].num_not_waiting = 0;
}
}
/*
* arrive_on_floor is called when a person arrives at a new floor.
*/
void arrive_on_floor(int time struct floor_s* floor struct person_s* person)
{
person->target_floor = -1; /* just arrived don‘t want to go
anywhere yet */
person->floor = floor->floor_number;
/* store them in the first free slot in the array */
floor->people_not_waiting[floor->num_not_waiting] = person;
floor->num_not_waiting++;
if (person->start_waiting != -1) {
total_waiting += time - person->start_waiting;
printf(“Their journey time was %d\n“ time - person->start_waiting);
if (time - person->start_waiting > max_wait) {
max_wait = time - person->start_waiting;
}
if (time - person->start_waiting < min_wait) {
min_wait = time - person->start_waiting;
}
no_of_waits++;
person->start_waiting = -1;
}
}
/*
* init_people initialized the people to start from the ground floor
*/
void init_people(struct floor_s* floors struct person_s* people)
{
int i = 0;
for(i = 0; i < NO_OF_PEOPLE; i++) {
people[i].name[0] = ‘A‘ + i;
people[i].name[1] = ‘\0‘;
people[i].start_waiting = -1;
arrive_on_floor(0 &floors[0] &people[i]);
}
}
/*
* init_lists initializes the lifts to start from the ground floor
*/
void init_lifts(struct lift_s* lifts)
{
int i;
for (i = 0; i < NO_OF_LIFTS; i++) {
lifts[i].lift_id = i;
lifts[i].occupants = 0;
lifts[i].position = 0;
lifts[i].speed = 0;
lifts[i].last_floor = 0;
lifts[i].mode = MODE_IDLE;
}
}
/*
* queue_for_list is called to add a person who was not previously
* queuing for a lift to the lift queue on their current floor
*/
void queue_for_lift(struct person_s* person struct floor_s* floor)
{
int i j = -1;
/* find the person and remoove them from the pool of people not
queuing */
for (i = 0; i < floor->num_not_waiting; i++) {
if (floor->people_not_waiting[i] == person) {
for (j = i; j < floor->num_not_waiting-1; j++) {
floor->people_not_waiting[j] = floor->people_not_waiting[j+1];
}
break;
}
}
assert(j != -1);
floor->num_not_waiting--;
floor->people_not_waiting[floor->num_not_waiting] = NULL;
/* add them to the queue of people waiting for the lift */
floor->people_waiting[floor->num_waiting] = person;
floor->num_waiting++;
}
/*
* decide_action is called to allow a person to randomly decide if
* they want to go to an
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 33792 2009-03-19 11:15 LIFT\Debug\vc60.idb
文件 28672 2009-03-19 11:15 LIFT\Debug\vc60.pdb
文件 4260 2009-03-19 11:15 LIFT\LIFT.dsp
文件 533 2009-03-19 11:15 LIFT\LIFT.dsw
文件 33792 2009-03-19 11:15 LIFT\LIFT.ncb
文件 48640 2009-03-19 11:15 LIFT\LIFT.opt
文件 771 2009-03-19 11:15 LIFT\LIFT.plg
文件 14893 2009-03-19 11:15 LIFT\main.cpp
目录 0 2009-03-19 11:15 LIFT\Debug
目录 0 2009-03-19 11:15 LIFT
----------- --------- ---------- ----- ----
165353 10
相关资源
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- VC 获得文件属性 获取文件的创建时
- 读者写者问题(读者优先,写者优先
- 用VC 编写的仿QQ聊天室程序源代码
- 外点法程序
- 外罚函数程序
- qt-电子点菜系统
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
- MUSIC算法c 实现
- C 餐厅叫号系统(QT平)
- 国际象棋c 完整版
-
ob
jectARX给Auto CAD加工具条 - 画图程序MFC/VC/VC CRectTracker 串行化
- MFC网络编程实例
- c 课程设计 职工信息管理系统
- VC 游戏编程—附源代码
- IpHlpApi.h&IpHlpApi.lib
- 清华大学 c 郑莉 ppt课件
- c 程序判断离散数学中命题公式
- 多项式求和(数据结构C 版)
- vc 6.0开发的流程图编辑器
- VC 天空盒(skyBox)实现(附源代码)
- linux C 电梯程序练习
- c MFC 画多边形
- 用C 实现的对网络上的ARP数据包进行
评论
共有 条评论