Précédent   Forum du club des développeurs et IT Pro > Autres langages > Autres langages > Ada
Ada Forum d'entraide sur la programmation en langage Ada
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 13/12/2012, 20h28   #1
Blair
Invité de passage
 
Femme
Étudiant
Inscription : décembre 2012
Messages : 5
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : décembre 2012
Messages : 5
Points : 0
Points : 0
Par défaut erreurs programme sémaphores

Bonsoir,
S'il vous plait je ne sais pas programmer en Ada et je dois arriver à compiler ce programme. le prof l'a écrit vite ou les élèves ont mal copié ou les deux parce- qu’il contient beaucoup d'erreurs!
c'est un programme de synchronisation moyennant les sémaphores.
Merci beaucoup pour toute aide !

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
with ada.calcular,ada.text_io;
use ....;
procedure Q2 is 
protected type Semaphore(Init:Integer:=1) is
entry P;procedure V;
private Compteur:Integer:=Init;
end Semaphore;
protected body Semaphore is
Entry P when Compteur>0 is begin
Compteur:=Compteur-1; end P;
procedure V is begin
Compteur:=Compteur+1; end V;
end Semaphore;
nb:constant;u,t,huit,seise:time;
Protected Type AC is 
Procedure Initialisation
procedure date_ticket;
Entity App_client(ng:positive);
Private
n-t-i:natural:=1;// n° ticket ? 
n-c-a-s:natural:=1; //n° client à servir 
end AC

Protected body is 
Protected dde_t is
x:natural:=(n-t-i)-(n-c-a-s);
Put_line("vs êtes N"&n-t-i'img&"E"&x'img&" en attente");--B
n-t-i:=n-t-i+1;
end dde_ticket; // dde_ticket c'est demande ticket

Entity App_client(ng:positive)
when n-c-a<n-t-i is
B
put_line ("le clt"& n-c-a-s'img&"est appelle au ghichet'&ng'img");
n-c-a=n-c-a+1;
end Ap_c;
end AC;
a:ac;
Task clt;
Task Type Guichet(ng:positive);
Task body clt is
B
t:=clock;huit-t-(seconds(t)-8-3600);
while(clock>hut and clock<seise)loop
a.d_ticket;
delay 20.0;
a.initialisation
delay until seise+16+3600;
end loop
end clt;
s.semaphore(1);
Task body Guichet is
B
while(c>h and c<seise)loop
SP;
a.Ap_client;
SV;
delay 10.0;
end loop;
end Ghuichet;
Type ptr acess Ghuichet;
tg:array(1..n)of ptr;
Begin
for i in 1..n loop
tg(i)=new Ghuichet(i);
end 
end Q2;
Blair est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/12/2012, 23h30   #2
jovalise
Membre éclairé
 
Inscription : juin 2006
Messages : 767
Détails du profil
Informations personnelles :
Âge : 43

Informations forums :
Inscription : juin 2006
Messages : 767
Points : 328
Points : 328
Code ada :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
with ada.calendar,ada.text_io;
use ada.calendar,ada.text_io;
procedure Q2 is

   protected type Semaphore(Init:Integer:=1) is
      entry P;
      procedure V;
   private
      Compteur:Integer:=Init;
   end Semaphore;

   protected body Semaphore is

      entry P when Compteur>0 is
      begin

         Compteur:=Compteur-1;
      end P;

      procedure V is
      begin

         Compteur:=Compteur+1;
      end V;
   end Semaphore;

   nb:constant Natural := 4;

   u,t,huit,seise:time;


   protected Type AC is

      Procedure Initialisation;

      procedure dde_ticket;

      Entry App_client(ng:positive);
   private

      N_T_I:natural:=1;-- n° ticket ?
      N_C_A_S:natural:=1; -- n° client à servir
   end AC;

   Protected body Ac is

      procedure Initialisation is
      begin
         null;
      end Initialisation;

      procedure dde_ticket is
         x:natural:=(N_T_I)-(N_C_A_S);
      begin

        Put_line("vs êtes N"&Natural'Image(N_T_I) &"E"& Natural'Image(X) &" en attente");--B
        N_T_I:=N_T_I+1;
      end dde_ticket; -- dde_ticket c'est demande ticket

     Entry App_Client(ng:positive) when N_C_A_S<N_T_I is
     begin
        put_line ("le clt"& Natural'image(N_C_A_S)&"est appelle au ghichet'&ng'img");
        N_C_A_S:=N_C_A_S+1;
     end App_client;
   end AC;

     A:ac;

     Task clt;
     Task Type Guichet(ng:positive);
     Task body clt is
     Begin
        t:=clock;
        --huit-t-(seconds(t)-8-3600);

        while(clock>huit and clock<seise)loop
           a.dde_ticket;
           delay 20.0;
           a.Initialisation;
           delay until seise+16.0+3600.0;
        end loop;
     end clt;

     S : semaphore(1);
     Task body Guichet is
     Begin
        while(Clock > huit and Clock <seise)loop
           S.P;
           A.App_Client(Ng);
           S.V;
           delay 10.0;
        end loop;
     end Guichet;

     Type ptr is access Guichet;
     tg:array(1..nb)of ptr;
Begin
   for i in 1..nb loop
      tg(i):=new Guichet(i);
   end loop;
end Q2;

A toi de faire le reste.
__________________
Mon développement
jovalise est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/12/2012, 23h53   #3
Blair
Invité de passage
 
Femme
Étudiant
Inscription : décembre 2012
Messages : 5
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : décembre 2012
Messages : 5
Points : 0
Points : 0
Citation:
Envoyé par jovalise Voir le message
Code ada :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
with ada.calendar,ada.text_io;
use ada.calendar,ada.text_io;
procedure Q2 is

   protected type Semaphore(Init:Integer:=1) is
      entry P;
      procedure V;
   private
      Compteur:Integer:=Init;
   end Semaphore;

   protected body Semaphore is

      entry P when Compteur>0 is
      begin

         Compteur:=Compteur-1;
      end P;

      procedure V is
      begin

         Compteur:=Compteur+1;
      end V;
   end Semaphore;

   nb:constant Natural := 4;

   u,t,huit,seise:time;


   protected Type AC is

      Procedure Initialisation;

      procedure dde_ticket;

      Entry App_client(ng:positive);
   private

      N_T_I:natural:=1;-- n° ticket ?
      N_C_A_S:natural:=1; -- n° client à servir
   end AC;

   Protected body Ac is

      procedure Initialisation is
      begin
         null;
      end Initialisation;

      procedure dde_ticket is
         x:natural:=(N_T_I)-(N_C_A_S);
      begin

        Put_line("vs êtes N"&Natural'Image(N_T_I) &"E"& Natural'Image(X) &" en attente");--B
        N_T_I:=N_T_I+1;
      end dde_ticket; -- dde_ticket c'est demande ticket

     Entry App_Client(ng:positive) when N_C_A_S<N_T_I is
     begin
        put_line ("le clt"& Natural'image(N_C_A_S)&"est appelle au ghichet'&ng'img");
        N_C_A_S:=N_C_A_S+1;
     end App_client;
   end AC;

     A:ac;

     Task clt;
     Task Type Guichet(ng:positive);
     Task body clt is
     Begin
        t:=clock;
        --huit-t-(seconds(t)-8-3600);

        while(clock>huit and clock<seise)loop
           a.dde_ticket;
           delay 20.0;
           a.Initialisation;
           delay until seise+16.0+3600.0;
        end loop;
     end clt;

     S : semaphore(1);
     Task body Guichet is
     Begin
        while(Clock > huit and Clock <seise)loop
           S.P;
           A.App_Client(Ng);
           S.V;
           delay 10.0;
        end loop;
     end Guichet;

     Type ptr is access Guichet;
     tg:array(1..nb)of ptr;
Begin
   for i in 1..nb loop
      tg(i):=new Guichet(i);
   end loop;
end Q2;

A toi de faire le reste.
Je vous remercie beaucoup pour votre aide !
Blair est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2012, 00h38   #4
jovalise
Membre éclairé
 
Inscription : juin 2006
Messages : 767
Détails du profil
Informations personnelles :
Âge : 43

Informations forums :
Inscription : juin 2006
Messages : 767
Points : 328
Points : 328
Code ada :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 Task body clt is
     begin
        loop
           t:=clock;
           huit := T-(seconds(t)+8.0*3600.0);
           seise := Huit+8.0*3600.0;

           a.Initialisation;
           while(Clock>huit and Clock<seise)loop
              a.dde_ticket;
              delay 5.0;

           end loop;
           delay until Seise+8.0*3600.0;
        end loop;
     end clt;

Voici la tache client complété. J'ai moi même appris à faire un truc.
__________________
Mon développement
jovalise est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2012, 11h37   #5
Blair
Invité de passage
 
Femme
Étudiant
Inscription : décembre 2012
Messages : 5
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : décembre 2012
Messages : 5
Points : 0
Points : 0
Citation:
Envoyé par jovalise Voir le message
Code ada :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 Task body clt is
     begin
        loop
           t:=clock;
           huit := T-(seconds(t)+8.0*3600.0);
           seise := Huit+8.0*3600.0;

           a.Initialisation;
           while(Clock>huit and Clock<seise)loop
              a.dde_ticket;
              delay 5.0;

           end loop;
           delay until Seise+8.0*3600.0;
        end loop;
     end clt;

Voici la tache client complété. J'ai moi même appris à faire un truc.
Tant mieux! Merci encore ! S'il vous plait qu'est ce qu'il reste à faire pour que le programme marche ? Et pouvez vous me conseillez un cours ou une bonne formation en Ada sur internet ? J'espère que je ne vous ai pas fait perdre beaucoup de temps!
Merci.
Blair est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2012, 12h31   #6
jovalise
Membre éclairé
 
Inscription : juin 2006
Messages : 767
Détails du profil
Informations personnelles :
Âge : 43

Informations forums :
Inscription : juin 2006
Messages : 767
Points : 328
Points : 328
Je ne peux pas te conseiller.

Code ada :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
with ada.calendar,ada.text_io;
use ada.calendar,ada.text_io;
procedure Q2 is

   protected type Semaphore(Init:Integer:=1) is
      entry P;
      procedure V;
   private
      Compteur:Integer:=Init;
   end Semaphore;

   protected body Semaphore is

      entry P when Compteur>0 is
      begin

         Compteur:=Compteur-1;
      end P;

      procedure V is
      begin

         Compteur:=Compteur+1;
      end V;
   end Semaphore;

   nb:constant Natural := 4;

   t,huit,seise:time;


   protected Type AC is

      Procedure Initialisation;

      procedure dde_ticket;

      Entry App_client(ng:positive);
   private

      N_T_I:natural:=1;-- n° ticket ?
      N_C_A_S:natural:=1; -- n° client à servir
   end AC;

   Protected body Ac is

      procedure Initialisation is
      begin
         null;
      end Initialisation;

      procedure dde_ticket is
         x:natural:=N_T_I-N_C_A_S;
      begin

        Put_line("vs êtes N"&Natural'Image(N_T_I) &"E"& Natural'Image(x) &" en attente");--B
        N_T_I:=N_T_I+1;
      end dde_ticket; -- dde_ticket c'est demande ticket

     Entry App_Client(ng:positive) when N_C_A_S<N_T_I is
     begin
        put_line ("le clt"& Natural'image(N_C_A_S)&"est appelle au gichet " & Natural'Image(Ng));
        N_C_A_S:=N_C_A_S+1;
     end App_client;
   end AC;

     A:ac;

     Task clt;
     Task Type Guichet(ng:positive);
     Task body clt is
     begin
        loop
           t:=clock;

           seise := T-Seconds(t)+16.0*3600.0;
           huit := Seise-8.0*3600.0;
           a.Initialisation;
           while(Clock>huit and Clock<seise)loop
              a.dde_ticket;
              delay 5.0;
           end loop;
           delay until Seise+16.0*3600.0;
        end loop;
     end clt;

     S : semaphore(1);
     Task body Guichet is
     Begin
        while(Clock > huit and Clock <seise)loop
           S.P;
           A.App_Client(Ng);
           S.V;
           delay 25.0;
        end loop;
     end Guichet;

     Type ptr is access Guichet;
     tg:array(1..nb)of ptr;
Begin
   for i in 1..nb loop
      tg(i):=new Guichet(i);
   end loop;
end Q2;

J'ai corrigé la tache client finalement, qui comportait il me semble une erreur.


Résultat : entre 8 et 16 heures les bureaux son ouvert et distribuent des tickets toutes les 5 secondes. Et traitent 4 clients toutes les 25 secondes.

Citation:
vs Ûtes N 1E 0 en attente
le clt 1est appelle au gichet 1
vs Ûtes N 2E 0 en attente
le clt 2est appelle au gichet 2
vs Ûtes N 3E 0 en attente
le clt 3est appelle au gichet 3
vs Ûtes N 4E 0 en attente
le clt 4est appelle au gichet 4
vs Ûtes N 5E 0 en attente
le clt 5est appelle au gichet 1
vs Ûtes N 6E 0 en attente
le clt 6est appelle au gichet 2
vs Ûtes N 7E 0 en attente
le clt 7est appelle au gichet 3
vs Ûtes N 8E 0 en attente
le clt 8est appelle au gichet 4
vs Ûtes N 9E 0 en attente
vs Ûtes N 10E 1 en attente
le clt 9est appelle au gichet 1
vs Ûtes N 11E 1 en attente
le clt 10est appelle au gichet 2
vs Ûtes N 12E 1 en attente
le clt 11est appelle au gichet 3
vs Ûtes N 13E 1 en attente
le clt 12est appelle au gichet 4
vs Ûtes N 14E 1 en attente
vs Ûtes N 15E 2 en attente
le clt 13est appelle au gichet 1
vs Ûtes N 16E 2 en attente
le clt 14est appelle au gichet 2
vs Ûtes N 17E 2 en attente
le clt 15est appelle au gichet 3
vs Ûtes N 18E 2 en attente
le clt 16est appelle au gichet 4
vs Ûtes N 19E 2 en attente
vs Ûtes N 20E 3 en attente
le clt 17est appelle au gichet 1
vs Ûtes N 21E 3 en attente
le clt 18est appelle au gichet 2
vs Ûtes N 22E 3 en attente
le clt 19est appelle au gichet 3
vs Ûtes N 23E 3 en attente
le clt 20est appelle au gichet 4
vs Ûtes N 24E 3 en attente
vs Ûtes N 25E 4 en attente
le clt 21est appelle au gichet 1
vs Ûtes N 26E 4 en attente
le clt 22est appelle au gichet 2
vs Ûtes N 27E 4 en attente
le clt 23est appelle au gichet 3
vs Ûtes N 28E 4 en attente
le clt 24est appelle au gichet 4
vs Ûtes N 29E 4 en attente
vs Ûtes N 30E 5 en attente
le clt 25est appelle au gichet 1
vs Ûtes N 31E 5 en attente
le clt 26est appelle au gichet 2
vs Ûtes N 32E 5 en attente
le clt 27est appelle au gichet 3
vs Ûtes N 33E 5 en attente
le clt 28est appelle au gichet 4
vs Ûtes N 34E 5 en attente
vs Ûtes N 35E 6 en attente
__________________
Mon développement
jovalise est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2012, 12h41   #7
Blair
Invité de passage
 
Femme
Étudiant
Inscription : décembre 2012
Messages : 5
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : décembre 2012
Messages : 5
Points : 0
Points : 0
Citation:
Envoyé par jovalise Voir le message
Je ne peux pas te conseiller.

Code ada :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
with ada.calendar,ada.text_io;
use ada.calendar,ada.text_io;
procedure Q2 is

   protected type Semaphore(Init:Integer:=1) is
      entry P;
      procedure V;
   private
      Compteur:Integer:=Init;
   end Semaphore;

   protected body Semaphore is

      entry P when Compteur>0 is
      begin

         Compteur:=Compteur-1;
      end P;

      procedure V is
      begin

         Compteur:=Compteur+1;
      end V;
   end Semaphore;

   nb:constant Natural := 4;

   t,huit,seise:time;


   protected Type AC is

      Procedure Initialisation;

      procedure dde_ticket;

      Entry App_client(ng:positive);
   private

      N_T_I:natural:=1;-- n° ticket ?
      N_C_A_S:natural:=1; -- n° client à servir
   end AC;

   Protected body Ac is

      procedure Initialisation is
      begin
         null;
      end Initialisation;

      procedure dde_ticket is
         x:natural:=N_T_I-N_C_A_S;
      begin

        Put_line("vs êtes N"&Natural'Image(N_T_I) &"E"& Natural'Image(x) &" en attente");--B
        N_T_I:=N_T_I+1;
      end dde_ticket; -- dde_ticket c'est demande ticket

     Entry App_Client(ng:positive) when N_C_A_S<N_T_I is
     begin
        put_line ("le clt"& Natural'image(N_C_A_S)&"est appelle au gichet " & Natural'Image(Ng));
        N_C_A_S:=N_C_A_S+1;
     end App_client;
   end AC;

     A:ac;

     Task clt;
     Task Type Guichet(ng:positive);
     Task body clt is
     begin
        loop
           t:=clock;

           seise := T-Seconds(t)+16.0*3600.0;
           huit := Seise-8.0*3600.0;
           a.Initialisation;
           while(Clock>huit and Clock<seise)loop
              a.dde_ticket;
              delay 5.0;
           end loop;
           delay until Seise+16.0*3600.0;
        end loop;
     end clt;

     S : semaphore(1);
     Task body Guichet is
     Begin
        while(Clock > huit and Clock <seise)loop
           S.P;
           A.App_Client(Ng);
           S.V;
           delay 25.0;
        end loop;
     end Guichet;

     Type ptr is access Guichet;
     tg:array(1..nb)of ptr;
Begin
   for i in 1..nb loop
      tg(i):=new Guichet(i);
   end loop;
end Q2;

J'ai corrigé la tache client finalement, qui comportait il me semble une erreur.


Résultat : entre 8 et 16 heures les bureaux son ouvert et distribuent des tickets toutes les 5 secondes. Et traitent 4 clients toutes les 25 secondes.
Merci beaucoup !
Blair est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/12/2012, 12h55   #8
jovalise
Membre éclairé
 
Inscription : juin 2006
Messages : 767
Détails du profil
Informations personnelles :
Âge : 43

Informations forums :
Inscription : juin 2006
Messages : 767
Points : 328
Points : 328
De rien.
__________________
Mon développement
jovalise est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/12/2012, 00h46   #9
Blackknight
Membre confirmé
 
Avatar de Blackknight
 
Homme Frédéric Praca
Ingénieur développement logiciels
Inscription : février 2009
Messages : 172
Détails du profil
Informations personnelles :
Nom : Homme Frédéric Praca
Âge : 39
Localisation : France, Seine Maritime (Haute Normandie)

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : février 2009
Messages : 172
Points : 292
Points : 292
Envoyer un message via AIM à Blackknight Envoyer un message via MSN à Blackknight
Citation:
Et pouvez vous me conseillez un cours ou une bonne formation en Ada sur internet ? J'espère que je ne vous ai pas fait perdre beaucoup de temps!
Il y a plusieurs choses :Il y a encore plein d'autres cours disponibles mais si tu lis tout ça, tu es paré
Les premiers liens te permettront de comprendre le langage mais c'est la norme qui te servira le plus souvent quand tu auras compris la philo
Blackknight est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/12/2012, 12h17   #10
Blair
Invité de passage
 
Femme
Étudiant
Inscription : décembre 2012
Messages : 5
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : décembre 2012
Messages : 5
Points : 0
Points : 0
Citation:
Envoyé par Blackknight Voir le message
Il y a plusieurs choses :Il y a encore plein d'autres cours disponibles mais si tu lis tout ça, tu es paré
Les premiers liens te permettront de comprendre le langage mais c'est la norme qui te servira le plus souvent quand tu auras compris la philo
Merci beaucoup, j'ai besoin d'apprendre Ada pour ma formation.
J'attaque tout de suite ! Bonne journée !
Blair est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 11h59.


 
 
 
 
Partenaires

Hébergement Web