简易电梯模拟程序
2006-10-16 17:43
871 查看
问题描述:公司要建立一幢两层的办公大楼并装上“最新”的电梯。公司要求开发一个面向对象的软件模拟程序,仿真电梯的操作,确定这个电梯能否满足需要。 这个电梯只限乘载一人,为了省电,只在需要时才使用,电梯每天在一楼关门等待。模拟程序包括一个时钟,每天从时间0开始,每秒滴答一次。模拟程序的调度器组件随机设置每一层第一个人到来的时间。当时钟的时间等于第一个人到来的时间时,模拟程序对指定层生成一个新到的人并将人放在这一层。然后这个人按下该层的按钮,请求电梯开门。这个人的目的地楼层不能与他上电梯时所在的楼层相同。如果第1个人到达第1层,则他可以按下按钮和等待电梯开门之后立即进入电梯。如果第1个人在第2层,则电梯要升至第2层去接这个人。电梯从1层移至2层需要5秒钟。电梯到达一层时,打开该层的电梯门上的灯,并在电梯内发出铃声。该层的按钮和电梯中中表示该层的按钮复位,电梯门打开,乘客(如果有人)走出电梯,另一乘客(如果有人等待)进入电梯并按下目的地楼层的按钮,电梯门关上。如果电梯要开始移动,则要确定移动的方向(对只有两层的电梯很简单)并移到下一层,为了简单起见,假设电梯到达一层时发生所有事件
部分代码:
Building类,电梯、楼层等都是大楼的实体
#ifndef BUILDING_H
#define BUILDING_H
#include "Floor.h"
#include "Scheduler.h"
#include "Elevator.h"
#include "Clock.h"
class Building
...{
public:
Building();
virtual ~Building();
void run(int);
private:
Floor floor1;
Floor floor2;
Scheduler scheduler;
Elevator elevator;
Clock clock;
};
#endif
Building.cpp
// Building.cpp: implementation of the Building class.
//
/**///////////////////////////////////////////////////////////////////////
#include "Building.h"
#include <iostream>
#include <ctime>
using std::cout;
using std::endl;
/**///////////////////////////////////////////////////////////////////////
// Construction/Destruction
/**///////////////////////////////////////////////////////////////////////
Building::Building():floor1(1,elevator),floor2(2,elevator),scheduler(floor1,floor2),elevator(floor1,floor2)
...{
}
Building::~Building()
...{
}
void Building::run(int runTime/**//*模拟运行时间*/)
//模拟程序运行
...{
int currentClockTime = 0;
cout<<" ******start simulation*******"<<endl;
while(currentClockTime < runTime)
...{
clock.tick();
currentClockTime = clock.getTime();
scheduler.proccessTime(currentClockTime);
elevator.processTime(currentClockTime);
cout<<endl;
}
cout<<" *******time over*******"<<endl;
}
电梯问题始终是一个复杂的问题,我只做了简单的模拟实现,希望CSDN的网友多多指点。
程序源代码下载
欢迎大家评论!
部分代码:
Building类,电梯、楼层等都是大楼的实体
#ifndef BUILDING_H
#define BUILDING_H
#include "Floor.h"
#include "Scheduler.h"
#include "Elevator.h"
#include "Clock.h"
class Building
...{
public:
Building();
virtual ~Building();
void run(int);
private:
Floor floor1;
Floor floor2;
Scheduler scheduler;
Elevator elevator;
Clock clock;
};
#endif
Building.cpp
// Building.cpp: implementation of the Building class.
//
/**///////////////////////////////////////////////////////////////////////
#include "Building.h"
#include <iostream>
#include <ctime>
using std::cout;
using std::endl;
/**///////////////////////////////////////////////////////////////////////
// Construction/Destruction
/**///////////////////////////////////////////////////////////////////////
Building::Building():floor1(1,elevator),floor2(2,elevator),scheduler(floor1,floor2),elevator(floor1,floor2)
...{
}
Building::~Building()
...{
}
void Building::run(int runTime/**//*模拟运行时间*/)
//模拟程序运行
...{
int currentClockTime = 0;
cout<<" ******start simulation*******"<<endl;
while(currentClockTime < runTime)
...{
clock.tick();
currentClockTime = clock.getTime();
scheduler.proccessTime(currentClockTime);
elevator.processTime(currentClockTime);
cout<<endl;
}
cout<<" *******time over*******"<<endl;
}
电梯问题始终是一个复杂的问题,我只做了简单的模拟实现,希望CSDN的网友多多指点。
程序源代码下载
欢迎大家评论!
相关文章推荐
- 设计电梯调度的程序,简易介绍。-------赵静娜和尹亚男
- 【操作系统】进程程序替换之模拟实现一个简易的Shell
- JAVA小程序开发之模拟电梯APP (源码详解)
- 【C语言】模拟登陆程序(简易)
- ASP.NET一个简易的WebServer,用控制台程序模拟IIS 托起web服务
- JS模拟超市简易收银台小程序代码解析
- 如何实现用Java编写程序,设计一个模拟电梯运行的类
- ASP.NET一个简易的WebServer,用控制台程序模拟IIS 托起web服务
- JS模拟超市简易收银台小程序
- 简易程序模拟ATM
- 51单片机模拟电梯汇编程序
- ASP.NET一个简易的WebServer,用控制台程序模拟IIS服务器 托起web服务
- Sys请教下如何用C#开发一个简易的电路模拟程序<qi>
- ASP.NET一个简易的WebServer,用控制台程序模拟IIS 托起web服务
- 开发自定义的web IIS服务器 WebDev.WebHost 用控制台托起web服务 上次写了一篇ASP.NET一个简易的WebServer,用控制台程序模拟IIS 托起web服务 看见有一朋友说在
- JAVA小程序开发之模拟电梯APP(代码优化)
- PHP程序百行代码快速构建简易聊天室方法
- 很久以前写的一个java模拟扑克牌洗牌发牌的小程序,学的知识少写的比较麻烦,不过也放上来吧
- ucGUI 使用VC模拟运行第一个程序
- PDA程序模拟测试工具