background image

 

!

 

type

 Pan_Mlody 

is

 (Druciarz, Krawiec, Zolnierz, Marynarz, Bogacz, Biedak, 

 

Zebrak, Zlodziej); 

  !

"

!

Pan_Mlody

 

"

#

! $

! %

&

 

# $

#

 

'

#

!

(

&

N = 10

)

*

Pan_Mlody'Val((N-1) 

mod

 8) 

$

Pan_Mlody'Val((N-1) 

mod

 (Pan_Mlody'Pos(Pan_Mlody'Last) +1)) 

 

N = 10

 

 

&

 

Krawiec

 

+

+

+

+

(

!

"

&

type

 

Wind 

is

 

(North, North_East, East, South_East, South, South_West, 

 

West, North_West); 

%

&,

!

$

 

Przeciwne

   

Prostopadle

 

 

!

!

#

)

*

function

 Przeciwne (X : Wind; Y : Wind) 

return

 Boolean 

is

  

begin 

  

return

 

(Wind'Pos (X) - Wind'Pos (Y)) 

mod

 

4

end

 Przeciwne; 

 

function

 Prostopadle (X : Wind; Y : Wind) 

return

 Boolean 

is

  

begin 

  

return

 

(Wind'Pos (X) - Wind'Pos (Y)) 

mod

 

2

end

 Prostopadle; 

 

-

-

-

-

.

!

#

,

X, Y : Integer; 

-- To jest deklaracja

 

 

 

.. 

if

 (X > (Y + 10)) 

and

 (X /= Y) 

then

 

 

 

..

 

+

&

!

 X,Y

 

 

 

 

)

*

if

 (X > (Y + 10)) 

then

  

-- Je eli pierwszy warunek jest 

 

 

 

 

 

-- prawdziwy, to drugi te . 

-+

-+

-+

-+

% "

Poziom : Natural; 
.. 

–- Obliczamy Poziom

 

if

 Poziom < 100 

then

 

  Put (Item => "Poziom niski"); 

elsif

 Poziom < 200 

then

 

  Put (Item => "Poziom sredni"); 

background image

 

!

  ----

elsif

 

Poziom < 300 

then

 

  Put (Item => "Poziom wysoki"); 

else 

  Put (Item => "Alarm");

 

end if

;

 

.

!

!

!

!

)

*

case

 Poziom 

is

 

  

when

 0..99 => Put (Item => "Poziom niski"); 

  

when

 100..199 => Put (Item => "Poziom sredni"); 

  

when

 200..299 => Put (Item => "Poziom wysoki"); 

  

when

 

others

 => Put (Item => "Alarm");

 

end case

 

/+

/+

/+

/+

&

!

 

for

 na

!

while

 

for

 Licznik 

in

 1..10 

loop

 

  Put ("Licznik petli = "); 
  Put (Licznik); 

end loop

)

*

Licznik : Integer 

range

 1..11 := 1; 

.. 

while

 Licznik < 11 

loop

 

  Put ("Licznik petli = "); 
  Put (Licznik); 
  Licznik := Licznik + 1; 

end loop

 

/

/

/

/

+

!

 

while

 

!

$

 

2

 

#

!

 

1..10000

Potega := 1; 

while

 Potega < 10000 

loop

 

  Ada.Integer_Text_IO.Put (Item => Potega, Width => 5); 
  Potega := Potega * 2; 

end loop

;

 

.

!

$

!

 

!

$

)

*

 

Potega := 1; 

loop

  

exit when

 Potega >= 10000; 

  Ada.Integer_Text_IO.Put (Item => Potega, Width => 5); 
  Potega := Potega * 2; 

end loop

 

0+

0+

0+

0+

 

Max_Size : 

constant

 := 30; 

background image

 

!

  ////

 

subtype

 Index_Range 

is

 Integer 

range

 1..Max_Size; 

 

type

 Name_String 

is array

 (Index_Range) 

of

 Character; 

 

 

 

First_Name : Name_String; 

%

&

!

#

 

First_Name

 

!

 

&

 

'A'

  .  1

#&

!

 

Put

 

$

!

$ 2

&

"

,

3

 

&

 

14 

'

#

First_Name

)

*

First_Name(1) := 'A'; 
Ada.Text_IO.Put (First_Name(14)); 

 

0

0

0

0

% "

 

type

 Tablica_Napisow_4D 

is array

 (Positive 

range

 <>) 

of

 String (1..4); 

+

&

$

 

Kura, Pies, Koza   Owca

!

 

Zwierzeta

 

$

!

 

&

"

%

!

 

Psa

   

Biesa

)

*

Zwierzeta : Tablica_Napisow_4D := ("Kura", "Pies", "Koza", "Owca"); 
  : 
Zwierzeta (2)(1) := 'B'; 

-- albo 

Zwierzeta (2) := "Bies"; 

 

4+

4+

4+

4+

type

 Matrix 

is array

 

(Integer

 

range

 < >, Integer 

range

 < >) 

of

 Float; 

,

!

 

Create_Unit_Matrix

,

N

N

 

"

" 5

,

!

#

Unit_Matrix_N

  

 

N

N

)

*

function

 Create_Unit_Matrix (N : Positive) 

return

 Matrix 

is

 

  M : Matrix (1..N, 1..N); 

begin 

  

for

 I 

in

 1..N 

loop

 

    

for

 J 

in

 1..N 

loop

 

      

if

 

I = J

 

then

 

        M(I,J) := 1.0; 
      

else 

        M(I,J) := 0.0; 
    

end loop

  

end loop

  

return

 M; 

end

 

Create_Unit_Matrix

.. 
Unit_Matrix_N :

 

constant

 

Matrix := Create_Unit_Matrix(N);

 

 

background image

 

!

  0000

4

4

4

4

% "

type

 Wektor_6 

is array

 (1..6) 

of

 Float; 

type

 Macierz_3_Na_6 

is array

 (1..3) 

of

 Wektor_6; 

M : Macierz_3_Na_6;

 

%

!

!$

 

M

)

*

M (1..2) := (M(2), M(1)); 
 

6

6

6

6

+

&

&

 

M

 

N

 

&

#

&

7$

!

M

N

 

!

*

 

8

 

N

1

M

N

M

!

 

M

N

M

M

(N

1)

%

&,

!

 

Mnozenie

!

$

 

)

*

function

 Mnozenie (M : 

in

 Integer; N : 

in

 Positive) 

return

 Integer 

is

  

  Wynik : Integer;   

begin 

  

if

 N = 1 

then

 

    Wynik := M; 

-- Przypadek podstawowy

 

  

else 

    Wynik := M + Mnozenie (M, N-1); 

-- Rekurencja

 

  

end if

  

return

 Wynik; 

end

 Mnozenie; 

 

6+

6+

6+

6+

%

&,

!

 

Suma_Kwadratow

 

!

"

 

N

 

#

"

"

%

&

!

 

Oblicz_Sume_Kwadratow

,

!

Suma_Kwadratow

)

*

function

 Suma_Kwadratow (N : 

in

 Positive) 

return

 Positive 

is

 

-- Funkcja oblicza sum  kwadratów pierwszych N liczb  
-- całkowitych, dodatnich

 

  Suma : Integer := 0; 
  Licznik : Positive := 1; 

begin 

  

while

 Licznik <= N 

loop

 

    Suma := Suma + Licznik*Licznik; 
    Licznik := Licznik + 1; 

  

end loop

  

return

 

Suma; 

end

 

Suma_Kwadratow; 

 

procedure

 Oblicz_Sume_Kwadratow (N : 

in

 Positive; S : 

out

 Positive) 

is

 

background image

 

!

  4444

-- Procedura oblicza sum  kwadratów pierwszych N liczb  
-- całkowitych, dodatnich

 

  Suma : Integer := 0; 
  Licznik : Positive := 1; 

begin 

  

while

 Licznik <= N 

loop

 

    Suma := Suma + Licznik*Licznik; 
    Licznik := Licznik + 1; 

  

end loop

  

S :=

 

Suma; 

end

 

Oblicz_Sume_Kwadratow; 

 

9

9

9

9

:

 

Complex

 

!

&

!

*

type

 Complex 

is record

 

  Re : Float; 
  Im : Float; 

end record

!

#

 

I

  $

!

!

 

–1

!

#

 

Zero

   

Jeden

  $

!

!

!

" 5

$ $

"

 

"

# "

%

,

!

 

"+"

   

"*"

 

!

"

!

 

Complex

)

*

I : 

constant

 Complex := (Re => 0.0, Im => 1.0); 

Zero : 

constant

 Complex := (Re => 0.0, Im => 0.0); 

Jeden : 

constant

 Complex := (Re => 1.0, Im => 0.0); 

 

function

 "+" (A, B : Complex) 

return

 Complex 

is

 

  

C : Complex; 

begin 

  

C.Re := A.Re + B.Re; 

  C.Im := A.Im + B.Im;  

  

return

 

C; 

end

 "+"; 

 

function

 "*" (A, B : Complex) 

return

 Complex 

is

 

  

C : Complex; 

begin 

  

C.Re := A.Re*B.Re - A.Im*B.Im; 

  C.Im := A.Re*B.Im + A.Im*B.Re;  

  

return

 

C; 

end

 "*"; 

9+

9+

9+

9+

:

 

Complex

 

!

&

!

*

type

 Complex 

is record

 

background image

 

!

  6666

  Re : Float; 
  Im : Float; 

end record

%

,

!

 

Re_Part

Im_Part

   

Adjoint

 

 

&

'

 

&!

!

 

Complex

)

*

function

 Adjoint (X : Complex) 

return

 Complex 

is

 

  C : Complex; 

begin 

  C.Re := X.Re; 
  C.Im := -X.Im; 
  

return

 C; 

end

 Conjugate; 

 

function

 Re_Part (X : Complex) 

return

 Float 

is

 

begin 

  

return

 X.Re; 

end

 Re_Part; 

 

function

 Im_Part (X : Complex) 

return

 Float 

is

 

begin 

  

return

 X.Im; 

end

 Im_Part;