From 64df900239280e2e4bccff27185131e6778db170 Mon Sep 17 00:00:00 2001 From: rlacroix Date: Sun, 31 May 2020 21:38:19 +0200 Subject: [PATCH] first code commit --- TD_R_LACROIX_ENG_06-01-2020.adb | 245 ++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 TD_R_LACROIX_ENG_06-01-2020.adb diff --git a/TD_R_LACROIX_ENG_06-01-2020.adb b/TD_R_LACROIX_ENG_06-01-2020.adb new file mode 100644 index 0000000..6924638 --- /dev/null +++ b/TD_R_LACROIX_ENG_06-01-2020.adb @@ -0,0 +1,245 @@ +with Fiche_Plongee, Capteurs, Gada.Text_IO; +use Fiche_Plongee, Capteurs, Gada.Text_IO; + +procedure td is + + -- TD 2 + + function Effectif_Palanquee(Table: T_Palanq) return integer is + I : integer := 1; -- to go through the table + Counter : Integer := 0; -- the final value + begin + + for I in 1 .. Max_Plongeurs loop + if Table.Plongeurs(I).Present then + Counter := Counter+1; + end if; + end loop; + + return Counter; + end Effectif_Palanquee; + + + function Effectif_Fiche(Table: T_Fiche_Secu) return integer is + I : Integer := 0; -- to go through the table + J : Integer := 0; -- to go through the table + Counter : Integer := 0; -- the final value + begin + + for I in 1 .. Table.NB_Palanquees loop -- welook at all the palanquees + for J in 1 .. Max_Plongeurs loop -- then we look at all the plongeurs in the palanquee + if Table.Tab_Palanquees(I).Plongeurs(J).Present then -- if they are present + Counter := Counter+1; -- we increment the counter + end if; + end loop; + end loop; + + return Counter; + end Effectif_Fiche; + + function Est_Plongee_Technique(Palanq : T_Palanq) return Boolean is + I : Integer := 1; -- to go through the table + Teacher : Integer := 0; -- to store the number of teachers + Student : Integer := 0; -- to store the number of students + Other : Integer := 0; -- to store the number of plongeurs that are neither student nor teachers + begin + for I in 0 .. Max_Plongeurs loop -- we go through the palanquee + if Palanq.Plongeurs(I).Present then -- we check if the plongeur is present + if Palanq.Plongeurs(I).Role = Ens then -- if he is present and is a teacher we increment teacher + Teacher := Teacher + 1; + elsif Palanq.Plongeurs(I).Role = Eleve then -- if he is present and is a student we increment student + Student := Student + 1; + else -- if he is present and is neither a teacher nor a student we increment other + Other := Other +1; + end if; + end if; + end loop; + return (Teacher = 1 and Other = 0 and (Student > 0 and Student <5)); -- we return the value taken by the condition + end Est_Plongee_Technique; + + + function Numero_Premiere_Technique(Fiche : T_Fiche_Secu) return Integer is + I : Integer := 1; -- to go through the table + Tech : Boolean := Est_Plongee_Technique(Fiche.Tab_Palanquees(I)); -- we initialize this as the very first entry of the table + + begin + + while (not Tech) loop -- while our plongee is not technique we keep on looking at the next entry + I := I+1; -- I miss the i++ so bad + Tech := Est_Plongee_Technique(Fiche.Tab_Palanquees(I)); -- we take the value of whether the Ith plongee is technique + end loop; + return I; + end Numero_Premiere_Technique; + + function Durees_Fiche_OK(Fiche: T_Fiche_Secu) return Boolean is + I : Integer := 1; -- to go through the table + 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; + end if; + end loop; + return Good; + end Durees_Fiche_OK; + + + 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 + + + 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 + Max := Table.Plongeurs(I).Profondeur_Max_Autorisee; + end if; + end loop; + return I; + + end Profondeur_Max; + + function Profondeur_Fiche_OK(Fiche: T_Fiche_Secu) return Boolean is + I : Integer := 1; + Good : Boolean := True; + 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; + end loop; + return Good; + end Profondeur_Fiche_OK; + + + + + -- TD 3 + -- Q1: exmample of events: + -- (Signal_Feu:32400.0) + -- (Plot,2,32400.8) + -- (Plot,3,32400.9) + -- (Plot,1,32401.2) + + -- (Sud,3,32420.8) + -- (Sud,2,32421.8) + -- (Sud,2,32421.85) + -- (Sud,2,32421.90) + -- (Sud,1,32423.8) + + -- (Nord,3,32440.8) + -- (Nord,2,32441.8) + -- (Nord,1,32443.8) + + -- (Sud,3,32460.8) + -- (Sud,2,32461.8) + -- (Sud,1,32463.8) + + -- (Nord,3,32480.8) + -- (Bouton_Fin,32480.9) + -- (Nord,2,32481.8) + -- (Nord,1,32483.8) + + + procedure Course is + Temp: Float := 0.0; + Rank: Integer := 0; + Sorted: Boolean := False; + J : Integer := 0; + I : Integer := 0; + NB_Swimmer: Integer :=8; -- could be more; + Running : Boolean:= True; + Event : T_Evenement; + TDepart : Float := 0.0; + 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 + + TableTime: T_TableTime := (others => (others => 0.0)); + TableNum : T_TableNum :=(others => 0); + Arrival : T_TableArr :=(others => 0.0); + 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; + End loop; + + 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; + 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)); + end loop; + + end Course; + + + + + +begin + Put_Line("42"); + + + + + + +end td;