Avatar of ali_t89
ali_t89 asked on

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

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.
Delphi

Avatar of undefined
Last Comment
ali_t89

8/22/2022 - Mon
Emmanuel PASQUIER

Can you explain what does your code and what you want to do with it ?
ASKER
ali_t89

the code and the answer to a question that Im trying to show is:

You are a bank branch manager and you are trying to determine the number of tellers you need during various parts of the week. The Number of tellers you need at any one time is based on the arrival rate of clients and the amount of service they need from the tellers.

Given an arrival rate and a service requirement distribution, the number of tellers determines how long the bank queue gets and therefore the average waiting time.

   
Emmanuel PASQUIER

Looks like homework to me.

Ok, I am not sure what a teller is. Still, here is a piece of code practice about functions :
a) you can use Result instead of the name of the function to store the result. While it does exactly the same in the compiled application, that is much better because if you change the function name or copy parts of code for another function, you don't have to change the name in your code.
b) in the same line, you don't need a temp value, you can use Result exactly is if it was a variable that you can set many times in your calculation. Only the last value when exiting the function counts.

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

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Emmanuel PASQUIER

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Emmanuel PASQUIER

Ok, that was about ways to produce *good* code, now can you explain a bit more what you want to achieve ?

what is the purpose of this Queue array ?
ASKER
ali_t89

wow thanks alot first of all :)

the purpose of the queue array is to show:
while the bank is open (banks operational hours) what does the queue look like. Although that sounds week thats the purpose of my assignment for the part about queue array.