We help IT Professionals succeed at work.
Get Started

How do I set up a teller array for this program?

ali_t89
ali_t89 asked
on
459 Views
Last Modified: 2012-05-10
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Label2: TLabel;
    Edit3: TEdit;
    Label3: TLabel;
    Edit4: TEdit;
    RadioGroup1: TRadioGroup;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit5: TEdit;
    Edit6: TEdit;
    Label7: TLabel;
    RadioGroup2: TRadioGroup;
    Label8: TLabel;
    Edit7: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Edit12: TEdit;
    Edit13: TEdit;
    Label18: TLabel;
    Label19: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;




implementation
uses math;
//uses IDOMNode;

{$R *.dfm}
type EUserError = class(Exception);

var NextClient: integer; //index in queue
var OpenHours: integer;
var NumberOfTellers: integer;
var Average: integer;
var Spread: integer;
var Average2: integer;
var Spread2: integer;

var Queue: array of integer;
var QueCount: integer;
var QueSize: integer;

function ArrivalRate( const distribution : integer ; //0 is Linear, 1 is Normal
                      const mean : integer ;
                      const spread : integer ) : real ;
var value: real;
begin
//compute actual value
     case distribution of
          0: value := RandomRange((mean-spread),(mean+spread)) ;
          1: value := RandG(mean,spread);
     else value := -1; //won't happen due to default selection
     end;
     ArrivalRate := value;
end;

procedure AppendToQueue( var xQueue: array of integer ;
                         var xCount: integer ;
                         const xTime: integer );
begin
    xQueue[xCount] := xTime;
    xCount := xCount + 1;
end;

procedure RemoveFromQueue( var xQueue: array of integer ;
                         var xCount: integer ;
                         out xTime: integer );
var i: integer;
begin
    xTime := xQueue[0];

    for i := 1 to (xCount - 1)
    do xQueue[i-1] := xQueue;

    xCount := xCount - 1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var time: integer;
var rate: real;
var need: real;
begin
try
//get and validate user inputs
   OpenHours       := StrToInt(Edit1.text);
   NumberofTellers := StrToInt(Edit2.text);
   Average         := StrToInt(Edit3.text);
   Spread          := StrToInt(Edit4.text);
   Average2        := StrToInt(Edit5.text);
   Spread2         := StrToInt(Edit6.text);

   if (OpenHours < 1) or (NumberOfTellers < 1)
   or (Average < 1) or (Spread < 1)
   or (Average2 < 1) or (Spread2 < 1)
   then raise EUserError.Create('UserError');

   QueCount := 0;
   SetLength(Queue, (60 * OpenHours));

   for time := 1 to (60 * OpenHours)
       do begin
          Rate := ArrivalRate(RadioGroup1.ItemIndex, Average, Spread);
          If Random < (1.0/Rate)
          then begin //person arrives this minute
                     //person gets on queue
                   AppendToQueue(Queue, QueCount, Time);
               end ;

          Need := ArrivalRate(RadioGroup2.ItemIndex, Average2, Spread2);

       end;

except
   on EConvertError do ShowMessage('Integers only please!');
   on EUserError do ShowMessage('Values greater than 0, please!');
end

end;

end.
Comment
Watch Question
Freelance Project Manager
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE