icebit

Ada18052016

May 18th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 2.82 KB | None | 0 0
  1. https://en.wikibooks.org/wiki/Ada_Programming
  2. type wskaznikdoczegos is access TypT
  3.  
  4. := new ...
  5.  
  6. kopiowanie plytkie i glebokie
  7. obj1.all := obj2.all
  8. -to pierwsze to typ access (wskaznik)
  9.  
  10. procedure freevector is new Ada.Unchecked.Deallocation (Object=>Vector, Name =>Vector_Ref);
  11.  
  12. ----------
  13. liczby pseudolosowe
  14.  
  15. Ada.Numerics.Discrete_Random;
  16. Type Rand_Range is range  0..8;
  17. package Rand_Int is new Discrete_Random(Rand_Range);
  18. gen: Rand_int.Generator;
  19. num: Rand_range
  20.  
  21. begin Rand_int.reset(gen);
  22. num: = Rand_int.Random(gen);
  23. -----------------
  24. ustalanie pozycji na ekranie
  25.  
  26. Ada.Text_IO:
  27.     Set_Line(x);
  28.     Set_Col(y);
  29. lub
  30.  
  31. Biblioteka Screen:
  32.     specjalne sciagi znakow (escpae sequence) ANSI VT 100
  33.     ... tez takie sobie xD
  34.  
  35. Biblioteka WIN32_Console z katalogu instalacyjnego AdaCore2015
  36.     trzeba skopiowac pliki do projektu GNAT/2015/share/examples/gnar/knights_tour/src/consoles do swojego katalogu z projektem
  37. ----------
  38. wypisywanie na ekranie z losowymi odstępami
  39. with Ada.Text_IO; use Ada.Text_IO;
  40. with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
  41. with Win32_Console; use Win32_Console;
  42. with Console; use Console;
  43. with Ada.Numerics.Discrete_Random;
  44. use Ada.Numerics;
  45. with Ada.Float_Text_IO; use Ada.Float_Text_IO;
  46.  
  47. procedure Main is
  48.  
  49. function Generate_Number (MaxValue : Integer) return Integer is
  50.    subtype Random_Type is Integer range 0 .. MaxValue;
  51.    package Random_Pack is new Ada.Numerics.Discrete_Random (Random_Type);
  52.  
  53.    G : Random_Pack.Generator;
  54. begin
  55.    Random_Pack.Reset (G);
  56.    return Random_Pack.Random (G);
  57. end Generate_Number;
  58.  
  59.  
  60. function Generate_Number (MinValue : Integer;
  61.                           MaxValue : Integer) return Integer
  62. is
  63.    subtype Random_Type is Integer range MinValue .. MaxValue;
  64.    package Random_Pack is new Ada.Numerics.Discrete_Random (Random_Type);
  65.  
  66.    G : Random_Pack.Generator;
  67. begin
  68.    Random_Pack.Reset (G);
  69.    return Random_Pack.Random (G);
  70.    end Generate_Number;
  71.    
  72.    task ekran is
  73.       entry print(n,x,y:Integer);
  74.    end ekran;
  75.  
  76.    task type Zadanie (n,kol:Integer);
  77.  
  78.    task body Zadanie is
  79.       d: Duration;
  80.       rnd: Integer;
  81.       --a: Integer;
  82.    begin
  83.             Put("xD");
  84.       d:= 0.5;
  85.       -- a:= 0;
  86.      
  87.       for i in  3..100 loop
  88.       rnd:=Generate_Number(10);
  89.          --a:=a+1;
  90.          d:= Duration(Float(rnd)/(100.0));
  91.          delay d;
  92.          ekran.print(n,i,kol);
  93.       end loop;
  94.    end Zadanie;
  95.  
  96.  
  97.    task body ekran is
  98.       loc: Location;
  99.       d: WIN32_Console.Device;
  100.  
  101.    begin
  102.       Put("xD");
  103.       loop
  104.          accept print(n,x,y:Integer) do
  105.             loc:=(x,y);
  106.             Move_Cursor(d,loc);
  107.             Put("WITAJ" );
  108.             Put(n);
  109.          end print;
  110.       end loop;
  111.    end ekran;
  112.    z1: Zadanie(1,1);
  113.    z2: Zadanie(2,20);
  114.    --e1: ekran;
  115. begin
  116.    null;
  117. end Main;
Add Comment
Please, Sign In to add comment