Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Ada.Text_IO; use Ada.Text_IO; with Ada.Numerics.Discrete_Random;
- procedure lampa is
- type lampaszinek is (piros,sarga,pirossarga,zold);
- type iranyok is (egyenesen_megy, fordul);
- package Random_Irany is new Ada.Numerics.Discrete_Random(iranyok);
- task type auto is
- entry setVar( name: in string := ""; time : in duration := 0.0); --afféle konstruktor
- end auto;
- type Pauto is access auto;
- protected veletlenGyarto is
- function gyarto return iranyok;
- end veletlenGyarto;
- protected body veletlenGyarto is
- function gyarto return iranyok is
- seed : Random_Irany.Generator;
- irany : iranyok;
- begin
- Random_Irany.Reset(seed);
- irany := Random_Irany.Random(seed);
- return irany;
- end gyarto;
- end veletlenGyarto;
- protected jelzolampa is
- entry athalad(rendszam : in string);
- procedure valt;
- procedure kiir;
- function szin return lampaszinek;
- private
- aktszin : lampaszinek := piros;
- end jelzolampa;
- protected body jelzolampa is
- function szin return lampaszinek is begin return aktszin; end szin;
- procedure valt is begin aktszin := lampaszinek'Val( (lampaszinek'Pos(aktszin) + 1) mod 4); end valt;
- procedure kiir is begin put_line(lampaszinek'Image(aktszin)); end kiir;
- entry athalad(rendszam : in string) when aktszin = zold is begin put_line(rendszam & " " & iranyok'Image(veletlenGyarto.gyarto) & "."); end athalad;
- end jelzolampa;
- task utemezo is
- entry leall;
- end utemezo;
- task lampaszerelo;
- task body lampaszerelo is
- begin
- delay 15.0;
- utemezo.leall;
- end lampaszerelo;
- task body utemezo is
- begin
- loop
- select
- accept leall do
- put_line("A szimulacio veget ert.");
- end leall;
- exit;
- else
- jelzolampa.valt; jelzolampa.kiir;
- delay 3.0;
- jelzolampa.valt; jelzolampa.kiir;
- delay 0.5;
- jelzolampa.valt; jelzolampa.kiir;
- delay 2.0;
- jelzolampa.valt; jelzolampa.kiir;
- delay 1.0;
- end select;
- end loop;
- end utemezo;
- task body auto is
- rendszam : access string;
- menetidoalampaig : access duration;
- begin
- accept setVar( name : in string := ""; time : in duration := 0.0) do
- rendszam := new string'(name);
- menetidoalampaig := new duration'(time);
- end;
- put_line(rendszam.all & " elindult.");
- delay menetidoalampaig.all;
- put_line(rendszam.all & " odaert.");
- loop
- select
- jelzolampa.athalad(rendszam.all);
- exit;
- or
- delay 0.2;
- put_line(rendszam.all & " var.");
- end select;
- end loop;
- end auto;
- autok : array (0..2) of Pauto;
- rendszamok : constant array (integer range 0..2) of string (1..7) := ("AAA-111", "BBB-222", "CCC-333");
- varakozasok: constant array (integer range 0..2) of duration := (1.5, 3.3, 7.5);
- begin
- for I in 0..2 loop
- autok(i) := new auto;
- autok(i).setVar(rendszamok(i), varakozasok(i));
- end loop;
- end lampa;
Advertisement
Add Comment
Please, Sign In to add comment