发布时间 : 星期六 文章随机模拟事件操作系统实验delphi - 图文更新完毕开始阅读d2b2f136a8114431b90dd8ee
随机事件模拟
一、实验名称
Simulation of random occurrence
(随机事件模拟) 二、实验目的
以银行业务处理为例,理解随机事件的发生、处理过程及处理的一般原则,为处理操作系统中的随机事件做准备。
三、实验内容
模拟银行的业务处理过程。假设银行有三个窗口,每天8点开门,12点关门。银行业务主要包括
两种:存钱和取钱,每件业务的处理时间为3-5分钟。
六、实验思路
1.如果程序开始运行时产生的随机时间在8-12点之间,则运行该程序,否则提示
银行已关门;
2.程序开始运行时,随机产生当时银行存在的人数,及三个窗口的排列情况,并按其先后顺序排序1,2,3……;
3.随机产生每个窗口正在办理业务的情况,包括存钱和取钱,及其每个窗口正在办理业务所剩余的时间,并表示出来;
4.程序运行中随机产生每个时刻进来的人数,并进行排列; 5.假如第一个人处理完业务,则队列依次前移; 6.假如到了12点,系统提示银行停止办理业务。
本程序运用delphi软件运行 运行程序如下:
第一个界面的代码如下: unit Unit1;
interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls; type
TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Label2: TLabel; Button1: TButton; Image1: TImage; Timer1: TTimer;
procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private
{ Private declarations }
public
{ Public declarations } end; var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin Randomize; i := random(20);
edit1.Text:=inttostr(i); if edit1.Text<'12' then Form2.show
ELSE
messagedlg('对不起,银行已关门',mtInformation,[mbOk],0); end;
procedure TForm1.Timer1Timer(Sender: TObject); begin
label1.Font.Color:=rgb(random(255),random(255),random(255)); end; end.
第二个界面的代码如下: unit Unit2;
interface