Skip to content

Commit 4fd2ab6

Browse files
committed
[NEW] Exercice 36
1 parent d47b3f9 commit 4fd2ab6

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

Exercice_36/exercice36.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/****************************************** EXERCICE 36 *******************************************/
2+
3+
var readline = require("readline-sync");
4+
5+
var tabUtilisateurs = [
6+
["Tya", "test1", "admin"],
7+
["Milo", "test2", "User"],
8+
["Lili", "test3", "user"],
9+
];
10+
11+
var choix;
12+
do {
13+
afficherMenuPrincipal();
14+
choix = readline.questionInt("Quel est votre choix ? : ");
15+
16+
switch (choix) {
17+
case 1:
18+
afficherUtilisateurs(tabUtilisateurs);
19+
break;
20+
case 2:
21+
tabUtilisateurs[tabUtilisateurs.length] =
22+
creerUtilisateur(tabUtilisateurs);
23+
break;
24+
case 9:
25+
console.log("À +");
26+
break;
27+
28+
default:
29+
console.log("Cas non pris en compte, recommencez !");
30+
break;
31+
}
32+
} while (choix != 9);
33+
34+
function afficherMenuPrincipal() {
35+
var msg = "*************************************************\n";
36+
msg += "1/ Afficher les utilisateurs\n";
37+
msg += "2/ Créer un utilisateur\n";
38+
msg += "9/ Quitter";
39+
console.log(msg);
40+
}
41+
42+
function afficherUnUtilisateur(utilisateur) {
43+
console.log("*************************************************");
44+
console.log("*****************DÉBUT AFFICHAGE*****************");
45+
console.log("*************************************************");
46+
console.log("Identifiant de l'utilisateur : " + utilisateur[0]);
47+
console.log("Mot de passe de l'utilisateur : " + utilisateur[1]);
48+
console.log("Rôle de l'utilisateur : " + utilisateur[2]);
49+
}
50+
51+
function afficherUtilisateurs(tabUtilisateurs) {
52+
for (var cpt = 0; cpt < tabUtilisateurs.length; cpt++) {
53+
if (cpt === tabUtilisateurs.length - 1) {
54+
afficherUnUtilisateur(tabUtilisateurs[cpt]);
55+
console.log("-----------------------FIN-----------------------");
56+
} else {
57+
afficherUnUtilisateur(tabUtilisateurs[cpt]);
58+
}
59+
}
60+
}
61+
62+
function creerUtilisateur() {
63+
var tabUtilisateur = [];
64+
65+
tabUtilisateur[0] = readline.question("Saisir le login : ");
66+
tabUtilisateur[1] = readline.question("Saisir le mot de passe : ");
67+
68+
var role;
69+
do {
70+
role = readline.question("Saisir le rôle : admin / user / visiteur : ");
71+
if (role != "admin" && role != "user" && role != "visiteur") {
72+
console.log("Rôle invalide, recommencez !");
73+
}
74+
} while (role != "admin" && role != "user" && role != "visiteur");
75+
76+
tabUtilisateur[2] = role;
77+
78+
return tabUtilisateur;
79+
}

Exercice_36/exercice36.pseudoc

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/****************************************** EXERCICE 36 *******************************************/
2+
3+
FONCTION afficherMenuPrincipal()
4+
VARIABLE
5+
msg : CHAINE DE CARACTERE
6+
DÉBUT
7+
msg → "*************************************************\n"
8+
msg → msg + "1/ Afficher les utilisateurs\n"
9+
msg → msg + "2/ Créer un utilisateur\n"
10+
msg → msg + "9/ Quitter\n"
11+
AFFICHER msg
12+
FIN
13+
14+
FONCTION afficherUnUtilisateur(utilisateur)
15+
DÉBUT
16+
AFFICHER "*************************************************"
17+
AFFICHER "*****************DÉBUT AFFICHAGE*****************"
18+
AFFICHER "*************************************************"
19+
AFFICHER "Identifiant de l'utilisateur : ", utilisateur[0]
20+
AFFICHER "Mot de passe de l'utilisateur : ", utilisateur[1]
21+
AFFICHER "Rôle de l'utilisateur : ", utilisateur[2]
22+
AFFICHER "*************************************************"
23+
FIN
24+
25+
FONCTION afficherUtilisateurs(tabUtilisateurs)
26+
DÉBUT
27+
POUR cpt ALLANT de 0 À taille(tabUtilisateurs)-1 PAR PAS DE 1 FAIRE
28+
afficherUnUtilisateur(tabUtilisateurs[cpt])
29+
FINPOUR
30+
FIN
31+
32+
FONCTION creerUtilisateur()
33+
VARIABLES
34+
tabUtilisateur[c] : TABLEAU CHAINE DE CARACTERE
35+
role : CHAINE DE CARACTERE
36+
DÉBUT
37+
AFFICHER "Saisir le login : "
38+
SAISIR tabUtilisateur[0]
39+
40+
AFFICHER "Saisir le mot de passe : "
41+
SAISIR tabUtilisateur[1]
42+
43+
FAIRE
44+
AFFICHER "Saisir le rôle : admin / user / visiteur : "
45+
SAISIR role
46+
SI (role != "admin" ET role != "user" ET role != "visiteur") ALORS
47+
AFFICHER "Rôle invalide, recommencez !"
48+
FINSI
49+
TANT QUE (role != "admin" ET role != "user" ET role != "visiteur")
50+
51+
tabUtilisateur[2] → role
52+
53+
RETOURNER tabUtilisateur
54+
FIN
55+
56+
ALGORITHME main
57+
VARIABLES
58+
tabUtilisateurs[c][c] : TABLEAU CHAINE DE CARACTERE
59+
choix : ENTIER
60+
DÉBUT
61+
tabUtilisateurs → [["Tya", "test1", "admin"], ["Milo", "test2", "User"], ["Lili", "test3", "user"]]
62+
63+
FAIRE
64+
afficherMenuPrincipal()
65+
AFFICHER "Quel est votre choix ? : "
66+
SAISIR choix
67+
SELON choix
68+
CAS 1 : afficherUtilisateurs(tabUtilisateurs)
69+
CAS 2 : tabUtilisateurs[taille(tabUtilisateurs)] → creerUtilisateur(tabUtilisateurs)
70+
CAS 9 : AFFICHER "À +"
71+
AUTREMENT : AFFICHER "Cas non pris en compte, recommencez !"
72+
FINSELON
73+
TANT QUE (choix != 9)
74+
FIN

0 commit comments

Comments
 (0)