PROGRAM WarteSchlange(INPUT,OUTPUT); uses crt; CONST maxlaenge = 12; TYPE t_matrix = ARRAY [0..maxlaenge, 0..10] OF INTEGER; t_schlange = ARRAY [1..10] OF INTEGER; t_dauer = ARRAY [1..8] OF INTEGER; VAR matrix, neuankommer : t_matrix; wartezeit : t_schlange; anzahl, i, verzoegern: INTEGER; uhrzeit : REAL; {---------------------------------------------------------------------------} PROCEDURE zufall(VAR dauer: t_dauer; VAR anzauto: INTEGER; i: INTEGER); VAR schnitt, j: INTEGER; BEGIN IF i IN [1..6] THEN schnitt := 4; IF i IN [7..12] THEN schnitt := 2; IF i IN [13..18] THEN schnitt := 1; IF i IN [19..24] THEN schnitt := 2; IF i IN [25..36] THEN schnitt := 4; IF i IN [37..42] THEN schnitt := 2; IF i IN [43..56] THEN schnitt := 3; IF i IN [57..60] THEN schnitt := 4; anzauto := random (2*schnitt+1); FOR j := 1 TO anzauto DO dauer[j] := 10 * (random (3) + 1); END; {---------------------------------------------------------------------------} PROCEDURE Uhrstellen(VAR uhrzeit: REAL); BEGIN uhrzeit:= uhrzeit + 0.1; IF Frac(uhrzeit) > 0.55 THEN uhrzeit:= uhrzeit - 0.6 + 1; gotoxy(10,4); write(uhrzeit:5:2); END; {---------------------------------------------------------------------------} PROCEDURE Wartezeitberechnung(anzahl: INTEGER; matrix: t_matrix; VAR wartezeit: t_schlange); VAR i, j , zeit: INTEGER; BEGIN FOR j := 1 TO anzahl DO BEGIN zeit := 0; FOR i := 1 TO maxlaenge DO IF matrix[i,j] <> 0 THEN BEGIN zeit := zeit + matrix[i,j] END; wartezeit[j] := zeit; END; Window(35,22,78,25); gotoxy(1,2); FOR j:= 1 TO anzahl DO write(#179,wartezeit[j]:3); write(#179); Window(1,1,80,25); END; {---------------------------------------------------------------------------} PROCEDURE Nachruecken(anzahl: INTEGER; VAR matrix: t_matrix); VAR i, j: INTEGER; BEGIN FOR j := 1 TO anzahl DO IF matrix[1,j] = 0 THEN FOR i := 2 TO maxlaenge DO matrix[i-1,j] := matrix[i,j]; Window(35,4,78,15); ClrScr; Window(35,1,78,25); gotoxy(1,2); write(#186); FOR j:= 1 TO anzahl DO IF matrix[1,j] <> 0 THEN write(matrix[1,j]:3,#179) ELSE write(' ',#179); write(#8,#186); gotoxy(1,4); FOR i:=2 TO maxlaenge DO BEGIN FOR j:= 1 TO anzahl DO IF matrix[i,j] <> 0 THEN write(' ',matrix[i,j]:3) ELSE write(' '); writeln; END; Window(1,1,80,25); END; {---------------------------------------------------------------------------} PROCEDURE Abfertigen(anzahl: INTEGER; VAR matrix: t_matrix); VAR j: INTEGER; BEGIN FOR j := 1 TO anzahl DO IF matrix[1,j] <> 0 THEN matrix[1,j] := matrix[1,j] - 10; Window(35,1,78,3); gotoxy(1,2); write(#186); FOR j:= 1 TO anzahl DO IF matrix[1,j] <> 0 THEN write(matrix[1,j]:3,#179) ELSE write(' ',#179); write(#8,#186); Window(1,1,80,25); END; {---------------------------------------------------------------------------} PROCEDURE Einreihen(anzahl: INTEGER; matrix: t_matrix); VAR i, j: INTEGER; BEGIN Window(35,18,78,21); ClrScr; Window(35,4,78,15); ClrScr; Window(35,1,78,25); gotoxy(1,2); write(#186); FOR j:= 1 TO anzahl DO IF matrix[1,j] <> 0 THEN write(matrix[1,j]:3,#179) ELSE write(' ',#179); write(#8,#186); gotoxy(1,4); FOR i:=2 TO maxlaenge DO BEGIN FOR j:= 1 TO anzahl DO IF matrix[i,j] <> 0 THEN write(' ',matrix[i,j]:3) ELSE write(' '); writeln; END; Window(1,1,80,25); END; {---------------------------------------------------------------------------} PROCEDURE Eintragen(anzahl, anzauto: INTEGER; dauer: t_dauer; VAR matrix, neuankommer: t_matrix); VAR i, j, k, l: INTEGER; BEGIN FOR j := 1 TO anzahl DO FOR i:= 1 TO maxlaenge DO neuankommer[i,j] := 0; i:= 1; j:= 1; k:= 1; WHILE (i <= maxlaenge) AND (k <= anzauto) DO BEGIN WHILE (j <= anzahl) AND (matrix[i,j] <> 0) DO j:= Succ(j); IF j > anzahl THEN BEGIN j:= 1; i:= Succ(i); END ELSE BEGIN matrix[i,j]:= dauer[k]; l:= 1; WHILE neuankommer[l,j] <> 0 DO l:= l + 1; neuankommer[l,j] := dauer[k]; k:= Succ(k); END; END; END; {---------------------------------------------------------------------------} PROCEDURE Ankommaus(neuankommer: t_matrix; anzahl: INTEGER); VAR i, j : INTEGER; BEGIN Window(35,18,78,21); gotoxy(1,1); FOR i:= 1 TO 3 DO BEGIN FOR j:= 1 TO anzahl DO IF neuankommer[i,j] <> 0 THEN write(' ',neuankommer[i,j]:3) ELSE write(' '); writeln; END; FOR j:= 1 TO anzahl DO IF neuankommer[4,j] <> 0 THEN write(' ',neuankommer[4,j]:3) ELSE write(' '); Window(1,1,80,25); END; {---------------------------------------------------------------------------} PROCEDURE Ankunft(i, anzahl: INTEGER; VAR matrix, neuankommer: t_matrix); VAR dauer : t_dauer; anzauto : INTEGER; BEGIN Zufall(dauer, anzauto, i); Eintragen(anzahl, anzauto, dauer,matrix, neuankommer); Ankommaus(neuankommer,anzahl); END; {---------------------------------------------------------------------------} PROCEDURE Initialisieren(VAR wartezeit: t_schlange; VAR uhrzeit: REAL; VAR anzahl: INTEGER; VAR matrix, neuankommer: t_matrix); VAR i, j: INTEGER; BEGIN ClrScr; writeln ('Warteschlangen beim TšV'); writeln ('========================='); writeln; writeln ('Wieviel Abfertigungsstraáen sind vorhanden?'); write ('(min. = 1 / max. = 10) '); readln (anzahl); writeln; writeln; writeln('Welche Verz”gerungszeit soll eingestellt werden?'); write ('(in Sekunden: 0, 1, 2, ...) '); readln(verzoegern); verzoegern:= 1000 * verzoegern; uhrzeit:= 8.00; FOR i := 0 TO maxlaenge DO FOR j := 0 TO anzahl DO BEGIN matrix[i,j] := 0; neuankommer[i,j] := 0; END; FOR j:=1 TO anzahl DO wartezeit[j]:= 0; END; {---------------------------------------------------------------------------} PROCEDURE Bildaufbau(wartezeit: t_schlange; uhrzeit: REAL; anzahl: INTEGER; matrix, neuankommer: t_matrix); VAR i, j: INTEGER; BEGIN ClrScr; writeln ('Warteschlangen beim TšV'); writeln ('========================='); writeln; writeln('Uhrzeit: ',uhrzeit:5:2); writeln; writeln; writeln('Warteschlange:'); writeln('Die Zahlen geben jeweils'); writeln('die Zeit (in min) der'); writeln('Abfertigung des Autos an.'); gotoxy(1,16); writeln('Eingang:'); gotoxy(1,23); writeln('Wartezeiten fr Neuankom-'); writeln('mende (in min).'); Window(35,1,78,25); gotoxy(1,1); write(#201); FOR j:=1 TO anzahl DO write(#205,#205,#205,#209); writeln(#8,#187); write(#186); FOR j:=1 TO anzahl DO IF matrix[1,j] <> 0 THEN write(matrix[1,j]:3,#179) ELSE write(' ',#179); writeln(#8,#186); write(#200); FOR j:=1 TO anzahl DO write(#205,#205,#205,#207); writeln(#8,#188); gotoxy(1,16); write(#218); FOR j:=1 TO anzahl DO write(#196,#196,#196,#194); writeln(#8,#191); FOR j:=1 TO anzahl DO write(#179,' '); writeln(#179); gotoxy(1,22); write(#218); FOR j:=1 TO anzahl DO write(#196,#196,#196,#194); writeln(#8,#191); FOR j:= 1 TO anzahl DO write(#179,wartezeit[j]:3); writeln(#179); write(#192); FOR j:=1 TO anzahl DO write(#196,#196,#196,#193); writeln(#8,#217); Window(1,1,80,25); END; {------------------------- Hauptprogramm ---------------------------------} BEGIN Initialisieren(wartezeit, uhrzeit, anzahl, matrix, neuankommer); Bildaufbau(wartezeit, uhrzeit, anzahl, matrix, neuankommer); FOR i:= 1 TO 60 DO BEGIN Ankunft(i, anzahl, matrix, neuankommer); delay(verzoegern); Einreihen(anzahl, matrix); delay(verzoegern); Abfertigen(anzahl, matrix); delay(verzoegern); Nachruecken(anzahl, matrix); Wartezeitberechnung(anzahl, matrix, wartezeit); delay(verzoegern); Uhrstellen(uhrzeit); END; END.