Yossep
VIP   
Messages: 10
Inscrit(e) le: 31/05/2020
Déconnecté(e)
|
Publié le 04/06/2020 à 23:09 |
Librairie de Gestion de ressources ( MAKATABA )
Bonjour chers Ada Programmeurs.
Suite à une petite formation sur OpenClassroom, je suis sorti avec ce petit programme qui simule le fonctionnement d'un logiciel de gestion de
ressources.
Code:
Maktaba_Types.ads
quote:
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded, Ada.Directories, Ada.Sequential_IO;
use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded, Ada.Directories;
package Maktaba_Types is
-----------------
-- CONSTANTES ---
-----------------
TAILLE_TITRE : Constant := 33;
TAILLE_NOM_AUTEUR_DIVERS : Constant := 23;
--HOME_PATH : constant Unbounded_String := To_Unbounded_String(Current_Directory);
-------------------------------------
-- DECLARATION DES TYPES COMPOSITES--
-------------------------------------
type T_oeuvre;
type T_categorie;
type T_support;
type T_grade;
type T_categorie is (LIVRE, FILM, JEU, ALBUM, DEVICE, LAPTOP, DESKTOP, PRINTER, MOBILE);
type T_support is (PAPIER, CD, DVD, VHS, BLURAY, MACHINE);
type T_grade is (A, B, C);
type t_Morceaux is array(integer range 1..TAILLE_NOM_AUTEUR_DIVERS) of string(1..TAILLE_NOM_AUTEUR_DIVERS);
-- parametrage de l'oeuvre
--Polymorphisme de type avec un discrimant
type T_oeuvre(categorie : T_categorie := LIVRE) is
record
titre : string(1..TAILLE_TITRE);
--categorie etant défini par défaut pour un livre pas besoin d'une composante
grade : T_grade;
support : T_support := PAPIER;
--date : T_date;
case categorie is
when LIVRE =>
auteur : string(1..TAILLE_NOM_AUTEUR_DIVERS);
editeur : string(1..TAILLE_NOM_AUTEUR_DIVERS);
ISBN : string(1..TAILLE_NOM_AUTEUR_DIVERS);
when FILM =>
realisateur : string(1..TAILLE_NOM_AUTEUR_DIVERS);
si_VF : Boolean := True;
when JEU =>
console : String(1..TAILLE_NOM_AUTEUR_DIVERS);
status : Boolean := False;
when ALBUM =>
artiste_nom : string(1..TAILLE_NOM_AUTEUR_DIVERS);
--Morceaux : t_Morceaux;
-- parametrage d'un équipement
when LAPTOP | DESKTOP =>
taille_ecran : string(1..TAILLE_NOM_AUTEUR_DIVERS);
processeur : string(1..TAILLE_NOM_AUTEUR_DIVERS);
RAM : string(1..TAILLE_NOM_AUTEUR_DIVERS);
stockage : String(1..TAILLE_NOM_AUTEUR_DIVERS);
OS : String(1..TAILLE_NOM_AUTEUR_DIVERS);
when PRINTER =>
format : string(1..TAILLE_NOM_AUTEUR_DIVERS);
RAM_printer : string(1..TAILLE_NOM_AUTEUR_DIVERS);
resolution : string(1..TAILLE_NOM_AUTEUR_DIVERS);
vitesse : string(1..TAILLE_NOM_AUTEUR_DIVERS);
dimension : string(1..TAILLE_NOM_AUTEUR_DIVERS);
poids : string(1..TAILLE_NOM_AUTEUR_DIVERS);
when MOBILE =>
Modele : string(1..TAILLE_NOM_AUTEUR_DIVERS);
ecran : string(1..TAILLE_NOM_AUTEUR_DIVERS);
ram_mobile : string(1..TAILLE_NOM_AUTEUR_DIVERS);
connectivite : string(1..TAILLE_NOM_AUTEUR_DIVERS);
when others =>
null;
end case;
end record;
---------------------------------------------------------------------
--- Package enumerate pour visibilité sur les types composites ---
---------------------------------------------------------------------
package categorie_io is new Enumeration_IO(T_categorie);
package grade_io is new Enumeration_IO(T_grade);
package support_io is new Enumeration_IO(T_support);
package File_seq is new Ada.Sequential_IO(T_oeuvre);
-----------------------------------------
-- clause d'accès aux types composites --
------------------------------------------
use categorie_io;
use support_io;
use grade_io;
use File_seq;
---------------------------------------
-- Types Composites secondaires --
-- type de fichier à accès sequentiel -
---------------------------------------
type File_Oeuvre is new File_seq.File_Type;
end Maktaba_Types;
|
Maktaba_Functions.ads
quote:
with Maktaba_Types, Ada.Text_IO; use Maktaba_Types, Ada.Text_IO;
package Maktaba_functions is
---------------------
-- SPECIFICATIONS ---
---------------------
function Check_Oeuvre(O : T_oeuvre) return Boolean;
function Create_Oeuvre(categorie : T_categorie) return T_oeuvre;
function get_text(taille : natural) return string;
function Get_categorie return T_categorie;
procedure Affiche_Manuel;
-- procedure Lire(fichier : In File_type);
procedure Create_Manual(fichier : Out File_Type);
procedure Affiche_oeuvre(O : T_oeuvre);
Procedure MENU;
Procedure Main;
end Maktaba_functions;
|
Maktaba_Functions.adb
[quote]
---------------------------------------------
--- SOUS PROGRAMMES SAISIE DE DONNEES -------
---------------------------------------------
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded,Ada.Characters.Handling, Ada.Directories, Maktaba_Types, Maktaba_Functions_DB;
use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded,Ada.Characters.Handling, Ada.Directories, Maktaba_Types, Maktaba_Functions_DB;
package body Maktaba_functions is
--------------------------
-- FONCTIONS DE SAISIE ---
---------------------------
----------------------------------------------
-- FONCTION QUI PERMET DE SAISIR DU TEXTE ----
-- FOCNTION CLEE --
-----------------------------------------------
function get_text(taille : natural) return string is
long: Natural;
nom1 : string(1..taille) := (others => ' ');
tmp : Unbounded_String := Null_unbounded_string;
begin
put(" >");
tmp := To_Unbounded_string(get_line);new_line;
long := length(tmp);
if long > taille then
nom1 := To_string(tmp)(1..taille);
else
--- Au dela de la taille par défaut on affiche pas le reste
nom1(1..long) := To_string(tmp);
for i in long+1..taille loop
nom1(i) := ' ';
end loop;
end if;
return nom1;
end get_text;
----------------------------------------------
-- FONCTION QUI PERMET DE CREER UNE OEUVRE ----
-----------------------------------------------
function Create_Oeuvre(categorie : T_categorie) return T_oeuvre is
O : T_oeuvre(categorie);
choix : String(1..TAILLE_NOM_AUTEUR_DIVERS);
choix2 : Character;
note : Character;
begin
Set_Col(10);Put_Line(" ************** ENREGISTREMENT DE "&T_categorie'image(categorie)&"
****************** ");New_Line;
-- Enrégistrement du titre --------
put(" TITRE: ");O.titre := get_text(TAILLE_TITRE);
-- Enrégistrement de la note --------
Set_Col(10);Put_Line(" Quel note donneriez-vous ? ( A / B / C )");
loop
new_line;
Put(" >");Get_Immediate(note);skip_line;
note := To_Upper(note);
new_line;
case note is
when 'A' =>
O.grade := A; Exit;
when 'B' =>
O.grade := B; Exit;
when 'C' =>
O.grade := C; exit;
when others =>
Set_Col(10);Put_Line(" [Error] .......grade inconnu");Exit;
end case;
end loop;
-------- Enrégistrement du support ---------------------
Set_Col(10);Put_Line(" Sur quel support l'oeuvre est-elle enrégistrée ? ");
new_line;
for i in T_support'range loop
Set_Col(10);put(" | ");put(T_support'Image(T_support(i)));
end loop;
loop
new_line;New_Line;
choix := get_text(TAILLE_NOM_AUTEUR_DIVERS);
choix := To_Upper(choix);New_Line;
case choix(1) is
when 'P' =>
O.support := PAPIER;Exit;
when 'C' =>
O.support := CD;exit;
when 'D' =>
O.support := DVD;exit;
when 'V' =>
O.support := VHS;exit;
when 'B' =>
O.support := BLURAY;exit;
when 'M' =>
O.support := MACHINE;exit;
when others =>
Set_Col(10);Put_Line(" [Error] ........Support inconnu ");
end case;
New_Line;
end loop;
--- POLYMORPHISME DU TYPE OEUVRE --------
case Categorie is
when LIVRE =>
Put(" AUTEUR: ");O.auteur := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" EDITEUR: ");O.editeur := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" ISBN: ");O.ISBN := get_text(TAILLE_NOM_AUTEUR_DIVERS);
when FILM =>
Put(" REALISATEUR: ");
O.realisateur := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Set_Col(10);Put_Line(" Le film est-il en Version francaise ? (O:Oui / N:Non)");
loop
new_line;
Put(">");Get_Immediate(choix2);skip_line;
choix2 := To_Upper(choix2);
case choix2 is
when 'O' =>
O.si_VF := true; Exit;
when 'N' =>
O.si_VF := False; Exit;
when others =>
O.si_VF := False;Exit;
end case;
end loop;
when JEU =>
Put(" CONSOLE: ");O.console := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Set_Col(10);Put_Line(" Avez-vous fini le jeu ? (O:Oui / N:Non)");
loop
new_line;
Put(">");Get_Immediate(choix2);skip_line;
choix2 := To_Upper(choix2);
case choix2 is
when 'O' =>
O.status := true; Exit;
when 'N' =>
O.status := False; Exit;
when others =>
O.status := False;Exit;
end case;
end loop;
when ALBUM =>
Put(" ARTISTE: ");O.artiste_nom := get_text(TAILLE_NOM_AUTEUR_DIVERS);
--Morceaux : t_Morceaux;
when DEVICE =>
null;
when LAPTOP | DESKTOP =>
Put(" TAILLE ECRAN: "); O.taille_ecran := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" PROCESSEUR: "); O.processeur := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" RAM: ");O.RAM := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" STOCKAGE: ");O.stockage := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" OS: ");O.OS := get_text(TAILLE_NOM_AUTEUR_DIVERS);
when PRINTER =>
Put(" FORMAT: ");O.format := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" RAM PRINTER: ");O.RAM_printer := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" RESOLUTION: ");O.resolution := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" VITESSE: ");O.vitesse := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" Lxl ");O.dimension := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" POIDS(kg) : ");O.poids := get_text(TAILLE_NOM_AUTEUR_DIVERS);
when MOBILE =>
Put(" MODELE: ");O.Modele := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" TAILLE ECRAN: "); O.ecran := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" RAM MOBILE: ");O.ram_mobile := get_text(TAILLE_NOM_AUTEUR_DIVERS);
Put(" CONNECTIVITE: ");O.connectivite := get_text(TAILLE_NOM_AUTEUR_DIVERS);
when others =>
Set_Col(10);Put_Line(" [Error] .......Categorie inconnue");
end case;
new_line;
return O;
end Create_Oeuvre;
-------------------
--- PROCEDURES ----
-------------------
procedure Create_Manual(fichier : Out File_Type) is
begin
Put_Line(fichier, " ************************************************************");
Put_line(fichier, "| Auteur : BINYOUM BAYEMI JOSEPH
|");
Put_Line(fichier, "| Description: Logiciel de gestion de ressources diverses |");
Put_Line(fichier, "| Licence: Ouvert à tous . |");
Put_Line(fichier, "|
|");
Put_Line(fichier, " ************************************************************");
Put_Line(fichier, " ");Put_Line(fichier, " ");Put_Line(fichier, "");
Put_Line(fichier, " Commandes de base: ");
Put_Line(fichier, "");
Put_Line(fichier, " Manual | Pour lire le manuel");
Put_Line(fichier, " Print | Pour afficher une base de donnée ");
Put_Line(fichier, " New | Pour créer une nouvelle ressource");
Put_Line(fichier, " Delete | Pour supprimer ");
Put_Line(fichier, " ");Put_Line(fichier, " ");Put_Line(fichier, "");
Put_Line(fichier, " ");Put_Line(fichier, " ");Put_Line(fichier, "");
Put_Line(fichier, " ");Put_Line(fichier, " ");Put_Line(fichier, "");
Put_Line(fichier, " **************************");
Put_Line(fichier, " Enjoy the experience (:0)");
Put_Line(fichier, " ");Put_Line(fichier, "");
end Create_Manual;
procedure Affiche_Manuel is
fichier : File_type;
Home : Unbounded_String := Null_Unbounded_String;
begin
home := To_Unbounded_String(Current_Directory);
If Exists("DATA") then
Set_Directory(To_String(Home)&"/"&"DATA");
if Exists("MANUEL.txt") then
Open(fichier, In_File, "MANUEL.txt");
while not End_Of_File(fichier) loop
put_Line(get_line(fichier));
end loop;
Close(fichier);
else
Set_Col(10);
Put_Line(" Le manuel d'utilisation n'existe pas..");
Set_Col(10);
Put_Line(" Creation d'un nouveau fichier MANUEL ...");
Create(fichier, Out_File, "MANUEL.txt");
Create_Manual(fichier);
close(fichier);
-- Affichage du manuel apres création ---
New_Line;New_Line;New_Line;New_Line;
Open(fichier, In_File, "MANUEL.txt");
while not End_Of_File(fichier) loop
put_Line(get_line(fichier));
end loop;
Close(fichier);
end if;
else
Set_Col(10);
Put_Line(" Le dossier de sauvegarde n'existe pas encore.");
Set_Col(10);
Put_Line(" Creation d'un nouveau dossier 'DATA' ");
Create_Directory("DATA");
Set_Directory(To_String(Home)&"/"&"DATA");
--Ensuite d'un nouveau fichier manuel
Set_Col(10);
Put_Line(" Creation d'un nouveau fichier MANUEL ...");
Create(fichier, Out_File, "MANUEL.txt");
Create_Manual(fichier);
close(fichier);
Set_Col(10);Put_Line(" MANUEL cree avec succes .....");
end if;
Set_Directory(To_String(home));
New_Line;New_Line;New_Line;New_Line;
end Affiche_Manuel;
------------------------------------------------------------------------
--- affiche toutes les categories d'oeuvre qu'il est possible de créer ---
-- ensuite l'utilisateur fait un choix ---------------------------------
-------------------------------------------------------------------------
procedure Affiche_oeuvre(O : T_oeu |
|