TP-programmation-imperative/tp06/stocks_materiel.adb

113 lines
2.7 KiB
Ada
Raw Normal View History

2023-06-10 19:03:54 +00:00
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
-- Auteur:
-- Gérer un stock de matériel informatique.
--
package body Stocks_Materiel is
procedure Creer (Stock : out T_Stock) is
begin
null;
end Creer;
function Nb_Materiels (Stock: in T_Stock) return Integer is
begin
return Stock.taille;
end Nb_Materiels;
function Nb_Materiels_DEAD (Stock: in T_Stock) return Integer is
n : Natural := 0;
begin
for i in 1..Stock.Taille loop
if not Stock.Elements(i).Etat then
n := n + 1;
end if;
end loop;
return n;
end Nb_Materiels_DEAD;
procedure change_state (Stock: in out T_Stock; state: in Boolean; identifiant: in Integer) is
begin
for i in 1..Stock.Taille loop
if Stock.Elements(i).ID = identifiant then
Stock.Elements(i).Etat := state;
-- exit; ?
end if;
end loop;
end change_state;
procedure supprimer_materiel (Stock: in out T_Stock; identifiant: in Integer) is
begin
for i in 1..Stock.Taille loop
if Stock.Elements(i).ID = identifiant then
Stock.Elements(i..CAPACITE-1) := Stock.Elements(i+1..CAPACITE);
Stock.Taille := Stock.Taille - 1;
exit;
end if;
end loop;
end supprimer_materiel;
procedure supprimer_all_dead (stock: in out T_Stock) is
i :integer := 1;
begin
loop
if not Stock.Elements(i).Etat then
Stock.Elements(i..CAPACITE-1) := Stock.Elements(i+1..CAPACITE);
Stock.Taille := Stock.Taille - 1;
else
i := i + 1;
end if;
exit when Stock.Elements(i).ID = -1;
end loop;
end supprimer_all_dead;
procedure Enregistrer (
Stock : in out T_Stock;
Numero_Serie : in Integer;
Nature : in T_Nature;
Annee_Achat : in Integer
) is
begin
Stock.Elements(Stock.Taille+1).ID := Numero_Serie;
Stock.Elements(Stock.Taille+1).Nature := Nature;
Stock.Elements(Stock.Taille+1).Annee := Annee_Achat;
Stock.Elements(Stock.Taille+1).Etat := True;
Stock.taille := Stock.Taille + 1;
end Enregistrer;
end Stocks_Materiel;