diff --git a/TD_R_LACROIX_ENG_06-01-2020.adb b/TD_R_LACROIX_ENG_06-01-2020.adb index 6924638..7237ec4 100644 --- a/TD_R_LACROIX_ENG_06-01-2020.adb +++ b/TD_R_LACROIX_ENG_06-01-2020.adb @@ -76,8 +76,8 @@ procedure td is Good : Boolean := True; -- if it stays good all along then it's good else it's not begin for I in 1 .. Fiche.NB_Palanquees loop - if Fiche.Tab_Palanquees(I).Duree_Reelle_Fond >= Fiche.Temps_Plongee_Max_Autorise then - Good := False; + if Fiche.Tab_Palanquees(I).Duree_Reelle_Fond >= Fiche.Temps_Plongee_Max_Autorise then -- if the length of the plongee was greater than the authorized time we set good to false + Good := False; -- therefore as soon as there is one palanquee that got past the limit it is and will remain false end if; end loop; return Good; @@ -85,14 +85,13 @@ procedure td is function Profondeur_Max(Table: T_palanq) return Integer is - I : Integer := 0; - Max : Integer := 0; - NB_Max_Plongeurs: constant Integer := 10; -- Not explicitely given so I figured out I'll put it to be 10 - + I : Integer := 0; -- to go through the table + Max : Integer := 0; -- to be returned + begin for I in 0 .. Max_Plongeurs loop - if Table.Plongeurs(I).Profondeur_Max_Autorisee < Max then -- it's smaller than because if smone can't go further the it become the new max + if Table.Plongeurs(I).Profondeur_Max_Autorisee < Max then -- it's smaller than because if smone can't go further it becomes the new maximum allowed Max := Table.Plongeurs(I).Profondeur_Max_Autorisee; end if; end loop; @@ -101,22 +100,24 @@ procedure td is end Profondeur_Max; function Profondeur_Fiche_OK(Fiche: T_Fiche_Secu) return Boolean is - I : Integer := 1; - Good : Boolean := True; + I : Integer := 1; -- to go through the table + Good : Boolean := True; -- to be returned begin for I in 1 .. Fiche.NB_Palanquees loop - if Fiche.Tab_Palanquees(I).Profondeur_Reelle >= Profondeur_Max(Fiche.Tab_Palanquees(I)) then - Good := False; - end if; + if Fiche.Tab_Palanquees(I).Profondeur_Reelle >= Profondeur_Max(Fiche.Tab_Palanquees(I)) then -- if the length of the plongee was greater than the authorized time we set good to false + Good := False; -- therefore as soon as there is one palanquee that got past the limit it is and will remain false + end if; end loop; return Good; end Profondeur_Fiche_OK; - + -- The answer to the question of the universe life and everything is ... 42 -- TD 3 -- Q1: exmample of events: + + --the race starts and the guys jumps -- (Signal_Feu:32400.0) -- (Plot,2,32400.8) -- (Plot,3,32400.9) @@ -124,7 +125,7 @@ procedure td is -- (Sud,3,32420.8) -- (Sud,2,32421.8) - -- (Sud,2,32421.85) + -- (Sud,2,32421.85) -- note there was an error here because of the capteur's bug -- (Sud,2,32421.90) -- (Sud,1,32423.8) @@ -143,15 +144,15 @@ procedure td is procedure Course is - Temp: Float := 0.0; + Temp: Float := 0.0; -- there to store a value Rank: Integer := 0; - Sorted: Boolean := False; - J : Integer := 0; - I : Integer := 0; + Sorted: Boolean := False; -- there to store the state of sorting of the array at the end + J : Integer := 0;-- there to increment + I : Integer := 0;-- there to increment NB_Swimmer: Integer :=8; -- could be more; Running : Boolean:= True; Event : T_Evenement; - TDepart : Float := 0.0; + TDepart : Float := 0.0; -- the time of the start of the race type T_TableTime is array (1..NB_Swimmer, 1..4) of Float; --time of the nth swimmer at 1: Start, 2:50 m, 3 finish, 4, the last time it reached a Nord base type T_TableNum is array (1..NB_Swimmer) of Integer; -- number of times the nth swimmer did a 50m type T_TableArr is array (1..NB_Swimmer) of Float; -- time at which the awimmer arrives @@ -162,70 +163,64 @@ procedure td is begin while Running loop - Event := Attend_Signal; - - -- I had done a case at first but we need to do something more complex --- case Event.emmeteur is --- when Capteur_Plot => --- when Capteur_Nord => --- when Capteur_Sud => null; --- when Signal_Feu => --- when Bouton_Fin => --- end case; - if Event.Emetteur = Signal_Feu then - TDepart := Event.Date; -- We stock the first value to have the time of the swimmers - elsif Event.Emetteur = Capteur_Plot then - if Event.Date - TDepart < 0.1 then -- it is a false start https://en.wikipedia.org/wiki/False_start - Running := False; - Put_Line("False start at line" & Integer'Image(Event.Num)); - else - TableTime(Event.Num,1) := Event.Date; -- starting value - TableTime(Event.Num,4) := Event.Date; -- Last value - end if; - elsif (Event.Emetteur = Capteur_Nord and (Event.Date - TableTime(Event.Num,4)>5.0)) then -- it's hard to do 50m in less than 5 seconds - if TableNum(Event.Num) = 0 then - TableTime(Event.Num,2) := Event.Date; - TableNum(Event.Num):=TableNum(Event.Num)+1; - end if; - if TableNum(Event.Num) = 15 then - TableTime(Event.Num,3) := Event.Date; - end if; - elsif Event.Emetteur = Bouton_Fin then - Running := False; - end if; + Event := Attend_Signal; + + if Event.Emetteur = Signal_Feu then + TDepart := Event.Date; -- We stock the first value to have the time of the swimmers + elsif Event.Emetteur = Capteur_Plot then + if Event.Date - TDepart < 0.1 then -- it is a false start: https://en.wikipedia.org/wiki/False_start + Running := False; -- we stop the race + Put_Line("False start at line" & Integer'Image(Event.Num)); + else + TableTime(Event.Num,1) := Event.Date; -- starting value + TableTime(Event.Num,4) := Event.Date; -- Last value + end if; + elsif (Event.Emetteur = Capteur_Nord and (Event.Date - TableTime(Event.Num,4)>5.0)) then -- it's hard to do 50m in less than 5 seconds + if TableNum(Event.Num) = 0 then + TableTime(Event.Num,2) := Event.Date; -- we store the value at the first 50 m + TableNum(Event.Num):=TableNum(Event.Num)+1; -- we increment the numer of runs + elsif TableNum(Event.Num) = 15 then -- it means he's finishing his last run + TableTime(Event.Num,3) := Event.Date; -- we store the arrival's date + end if; + elsif Event.Emetteur = Bouton_Fin then -- the director of the race stopped it (probably saw someone arrive) + Running := False; + end if; End loop; - for I in 1 .. NB_Swimmer loop - Arrival(I) := TableTime(I,3); + -- we store the times of arrival + for I in 1 .. NB_Swimmer loop + Arrival(I) := TableTime(I,3); end loop; -- We order the table: while not Sorted loop - for I in 1 .. NB_Swimmer-1 loop - if Arrival(I)>Arrival(I+1) then - Temp := Arrival(I); - Arrival(I) := Arrival(I+1); - Arrival(I+1) := Temp; - Temp :=0.0; - end if; - end loop; - - Sorted := True; - for I in 1 .. NB_Swimmer-1 loop - if Arrival(I)>Arrival(I+1) then - Sorted := False; - end if; - end loop; + for I in 1 .. NB_Swimmer-1 loop -- for every value if it is greater than the next one we swop them + if Arrival(I)>Arrival(I+1) then + Temp := Arrival(I); -- there to store a value + Arrival(I) := Arrival(I+1); + Arrival(I+1) := Temp; + Temp := 0.0; --reset + end if; + end loop; + + + --here we check for if it's sorted (if not we give it another go) + Sorted := True; --it starts true + for I in 1 .. NB_Swimmer-1 loop + if Arrival(I)>Arrival(I+1) then -- if a value is greater than the next one (as it's not supposed to be) + Sorted := False; -- we set the sorted value to false + end if; + end loop; end loop; - + for I in 1 .. NB_Swimmer loop - J := 0; - while (Arrival(I) /= TableTime(J,3)) loop - J := J+1; - end loop; - - Put_Line("Swimmer " & Integer'Image(J) & " arrived in place " & Integer'Image(I) & " with a time of " & Float'Image(Arrival(I)-TDepart)); + J := 0; + while (Arrival(I) /= TableTime(J,3)) loop + J := J+1; + end loop; + + Put_Line("Swimmer " & Integer'Image(J) & " arrived in place " & Integer'Image(I) & " with a time of " & Float'Image(Arrival(I)-TDepart)); end loop; end Course; @@ -243,3 +238,4 @@ begin end td; +