-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicro.c
More file actions
456 lines (411 loc) · 14.6 KB
/
Copy pathmicro.c
File metadata and controls
456 lines (411 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX_ETUDIANTS 100
#define MAX_MATIERES 50
#define MAX_NOTES 500
#define FICHIER_ETUDIANTS "etudiants.txt"
#define FICHIER_MATIERES "matieres.txt"
#define FICHIER_NOTES "notes.txt"
typedef struct {
char matricule[20];
char nom[50], prenom[50], classe[20];
} Etudiant;
typedef struct {
char code[10], libelle[50];
int coefficient;
} Matiere ;
typedef struct {
char matricule[20];
char codeMatiere[10];
float valeur;
char dateEval[11];
} Note;
Etudiant baseEtudiants[MAX_ETUDIANTS]; int nbEtudiants = 0;
Matiere baseMatieres[MAX_MATIERES]; int nbMatieres = 0;
Note baseNotes[MAX_NOTES]; int nbNotes = 0;
int saisirEntier() {
char buffer[100];
int valeur, i, valide;
do {
valide = 1;
scanf("%s", buffer);
// fgets();
for (i = 0; i < strlen(buffer); i++) {
if (!isdigit(buffer[i])) {
valide = 0;
break;
}
}
if (!valide) printf("Erreur : Veuillez saisir un nombre entier : ");
} while (!valide);
valeur = atoi(buffer);
return valeur;
}
float saisirFlottant() {
char buffer[100];
char *endptr;
float valeur;
while (1) {
scanf("%s", buffer);
valeur = strtof(buffer, &endptr);
if (*endptr == '\0')
return valeur;
printf("Erreur : Veuillez saisir un nombre : ");
}
}
void saisirTexte(char *dest, int taille) {
int valide, i;
getchar();
do {
valide = 1;
fgets(dest, taille, stdin);
dest[strcspn(dest, "\n")] = 0;
if (strlen(dest) == 0) { valide = 0; }
for (i = 0; i < strlen(dest); i++) {
if (isdigit(dest[i])) {
valide = 0;
break;
}
}
if (!valide) printf("Erreur : Veillez saisir des lettres. \n Reessaysez : ");
} while (!valide);
}
void saisirAlphanumerique(char *chaine, int taille) {
int valide;
do {
valide = 1;
fgets(chaine, taille, stdin);
chaine[strcspn(chaine, "\n")] = 0;
for (int i = 0; i < strlen(chaine); i++) {
if (!isalnum(chaine[i])) {
printf("Erreur : Utilisez uniquement des lettres et chiffres.\nReessayez : ");
valide = 0;
break;
}
}
} while (!valide);
}
void chargerTout();
void sauvegarderTout();
void menuEtudiants();
void ajouterEtudiant();
void modifierEtudiant();
void supprimerEtudiant();
void rechercherEtudiant();
void afficherEtudiants();
void menuMatieres();
void ajouterMatiere();
void afficherMatieres();
void supprimerMatiere();
void menuNotes();
void attribuerNote();
void afficherBulletin();
int main() {
chargerTout();
int choix;
do {
printf("\n=================================");
printf("\n LOGICIEL DE GESTION SCOLAIRE");
printf("\n=================================");
printf("\n1. Gestion des Etudiants");
printf("\n2. Gestion des Matieres");
printf("\n3. Gestion des Notes");
printf("\n4. Quitter");
printf("\nVotre choix : ");
choix = saisirEntier();
switch(choix) {
case 1: menuEtudiants(); break;
case 2: menuMatieres(); break;
case 3: menuNotes(); break;
} if (choix != 1, 2, 3, 4) {
printf("\nErreur : Choix invalide\n");
}
} while (choix != 4);
sauvegarderTout();
return 0;
}
void menuEtudiants() {
int choix;
do {
printf("\n--- GESTION DES ETUDIANTS ---");
printf("\n1. Ajouter un etudiant");
printf("\n2. Modifier un etudiant");
printf("\n3. Supprimer un etudiant");
printf("\n4. Rechercher un etudiant");
printf("\n5. Afficher la liste complete");
printf("\n6. Retour au menu principal");
printf("\nChoix : ");
choix = saisirEntier();
switch(choix) {
case 1: ajouterEtudiant(); break;
case 2: modifierEtudiant(); break;
case 3: supprimerEtudiant(); break;
case 4: rechercherEtudiant(); break;
case 5: afficherEtudiants(); break;
}
} while (choix != 6);
if(choix != 1, 2, 3, 4, 5, 6) {
printf("\nChoix invalide");
}
}
void ajouterEtudiant() {
printf("\n-- Ajouter etudiant --\n");
if (nbEtudiants >= MAX_ETUDIANTS)
return;
getchar();
printf("\nMatricule : "); saisirAlphanumerique(baseEtudiants[nbEtudiants].matricule, 20);
printf("Nom : "); saisirTexte(baseEtudiants[nbEtudiants].nom, 50);
printf("Prenom : "); saisirTexte(baseEtudiants[nbEtudiants].prenom, 50);
printf("Classe : "); fflush(stdin); saisirAlphanumerique(baseEtudiants[nbEtudiants].classe, 20);
nbEtudiants++;
sauvegarderTout();
printf("\nEtudiant ajoute avec succes !\n");
}
void modifierEtudiant() {
printf("\n-- Modifier etudiant --\n");
char id[20], trouve = 0;
fflush(stdin);
printf("\nMatricule de l'etudiant : ");
saisirAlphanumerique(id, 20);
for (int i = 0; i < nbEtudiants; i++) {
if (strcmp(baseEtudiants[i].matricule, id) == 0) {
trouve = 1;
int choixModif;
char s[50];
do {
printf("\nQue voulez-vous modifier ?");
printf("\n1. Le Nom");
printf("\n2. Le Prenom");
printf("\n3. La Classe");
printf("\n4. Terminer la modification");
printf("\nChoix : ");
choixModif = saisirEntier();
if (choixModif == 1) {
printf("Nouveau Nom : ");
saisirTexte(baseEtudiants[i].nom, 50);
} else if (choixModif == 2) {
printf("Nouveau Prenom : ");
saisirTexte(baseEtudiants[i].prenom, 50);
} else if (choixModif == 3) {
printf("Nouvelle Classe : ");
scanf("%s",s, baseEtudiants[i].classe);
}
} while (choixModif != 4);
break;
}
}
if (!trouve) {
printf("Etudiant non reconnu.\n");
} else {
sauvegarderTout();
printf("\nEtudiant modifie avec succes !\n");
}
}
void supprimerEtudiant() {
printf("\n-- Supprimer etudiant --\n");
char id[20], index = -1;
fflush(stdin);
printf("Matricule de l'etudiant : ");
saisirAlphanumerique(id, 20);
for (int i = 0; i < nbEtudiants; i++)
if (strcmp(baseEtudiants[i].matricule, id) == 0) {
index = i;
break;
}
if (index != -1) {
for (int i = index; i < nbEtudiants - 1; i++) baseEtudiants[i] = baseEtudiants[i + 1];
nbEtudiants--;
sauvegarderTout();
printf("\nEtudiant supprime avec succes !\n");
} else {
printf("Etudiant non reconnu.\n");
}
}
void rechercherEtudiant() {
printf("\n-- Rechercher etudiant --\n");
char id[20];
fflush(stdin);
printf("Matricule de l'etudiant : ");
saisirAlphanumerique(id, 20);
for (int i = 0; i < nbEtudiants; i++) if (strcmp(baseEtudiants[i].matricule, id) == 0) {
printf("\n--- RESULTAT ---");
printf("\nNom: %s | Prenom: %s | Classe: %s\n", baseEtudiants[i].nom, baseEtudiants[i].prenom, baseEtudiants[i].classe);
return;
}
printf("Etudiant non reconnu.\n");
}
void afficherEtudiants() {
if (nbEtudiants == 0) {
printf("\nAucun etudiant enregistre.\n");
return;
}
printf("\n--- LISTE DES ETUDIANTS ---");
for (int i = 0; i < nbEtudiants; i++) {
printf("\n----------------------------");
printf("\nMatricule : %s", baseEtudiants[i].matricule);
printf("\nNom : %s", baseEtudiants[i].nom);
printf("\nPrenom : %s", baseEtudiants[i].prenom);
printf("\nClasse : %s", baseEtudiants[i].classe);
}
printf("\n");
}
void menuMatieres() {
int c; do {
printf("\n--- GESTION DES MATIERES ---");
printf("\n1. Ajouter une matiere");
printf("\n2. Afficher toutes les matieres");
printf("\n3. Supprimer une matiere");
printf("\n4. Retour");
printf("\nChoix : ");
c = saisirEntier();
if(c==1) {
printf("\n-- Ajouter matiere --\n");
printf("Code : "); scanf("%s", baseMatieres[nbMatieres].code);
printf("Libelle : "); saisirTexte(baseMatieres[nbMatieres].libelle, 50);
printf("Coefficient : "); baseMatieres[nbMatieres].coefficient = saisirEntier();
nbMatieres++;
sauvegarderTout();
printf("\nMatiere ajoute avec succes !\n");
} else if (c == 2) {
if (nbMatieres == 0) {
printf("\nAucune matiere enregistree.\n");
} else {
printf("\n--- LISTE DES MATIERES ---");
for (int i = 0; i < nbMatieres; i++) {
printf("\n----------------------------");
printf("\nCode => %s", baseMatieres[i].code);
printf("\nLibelle => %s", baseMatieres[i].libelle);
printf("\nCoefficient => %d", baseMatieres[i].coefficient);
printf("\n----------------------------");
}
}
} else if (c == 3) {
char code[10];
int index = -1;
printf("Code de la matiere a supprimer : ");
scanf("%s", code);
for (int i = 0; i < nbMatieres; i++) {
if (strcmp(baseMatieres[i].code, code) == 0) {
index = i;
break;
}
}
if (index != -1) {
for (int i = index; i < nbMatieres - 1; i++) {
baseMatieres[i] = baseMatieres[i + 1];
}
nbMatieres--;
sauvegarderTout();
printf("\nMatiere supprimee avec succes !\n");
} else {
printf("\nCode non reconnu.\n");
}
}
} while (c != 4);
}
void menuNotes() {
int c;
do {
printf("\n--- GESTION DES NOTES ---");
printf("\n1. Attribuer une note");
printf("\n2. Voir bulletin d'un etudiant");
printf("\n3. Retour");
printf("\nChoix : ");
c = saisirEntier();
if (c == 1) {
char mat[20], trouve = 0;
printf("Matricule de l'etudiant : ");
getchar();
saisirAlphanumerique(mat, 20);
for (int i = 0; i < nbEtudiants; i++) {
if (strcmp(baseEtudiants[i].matricule, mat) == 0) {
trouve = 1;
break;
}
}
if (trouve) {
strcpy(baseNotes[nbNotes].matricule, mat);
printf("Code Matiere : ");
scanf("%s", baseNotes[nbNotes].codeMatiere);
printf("Note : ");
baseNotes[nbNotes].valeur = saisirFlottant();
printf("Date d'evaluation : ");
scanf("%s", baseNotes[nbNotes].dateEval);
nbNotes++;
sauvegarderTout();
printf("\nNote ajoutee avec succes !\n");
} else {
printf("\nEtudiant non reconnu.\n");
}
} else if (c == 2) {
char mat[20];
float s = 0;
int tc = 0;
int trouveEtudiant = 0;
printf("Matricule de l'etudiant : ");
fflush(stdin);
saisirAlphanumerique(mat, 20);
printf("\n============================================================");
printf("\n BULLETIN DE NOTES : %s", mat);
printf("\n============================================================");
printf("\n%-15s | %-10s | %-6s | %-12s", "MATIERE", "NOTE", "COEFF", "DATE");
printf("\n------------------------------------------------------------");
for (int i = 0; i < nbNotes; i++) {
if (strcmp(baseNotes[i].matricule, mat) == 0) {
trouveEtudiant = 1;
int k = 1;
for (int j = 0; j < nbMatieres; j++) {
if (strcmp(baseMatieres[j].libelle, baseNotes[i].codeMatiere) == 0) {
k = baseMatieres[j].coefficient;
break;
}
}
printf("\n%-15s | %-10.2f | %-6d | %-12s", baseNotes[i].codeMatiere, baseNotes[i].valeur, k, baseNotes[i].dateEval);
s += (baseNotes[i].valeur * k);
tc += k;
}
}
if (tc > 0) {
printf("\n------------------------------------------------------------");
printf("\nMOYENNE GENERALE : %.2f / 20", s / tc);
printf("\n============================================================\n");
} else if (trouveEtudiant == 0) {
printf("\n\nAucune note trouvee pour ce matricule.\n");
}
}
} while (c != 3);
}
void sauvegarderTout() {
FILE *f1 = fopen(FICHIER_ETUDIANTS, "w");
if(f1){ for(int i=0; i<nbEtudiants; i++) fprintf(f1, "%s;%s;%s;%s\n", baseEtudiants[i].matricule, baseEtudiants[i].nom, baseEtudiants[i].prenom, baseEtudiants[i].classe); fclose(f1); }
FILE *f2 = fopen(FICHIER_MATIERES, "w");
if(f2){ for(int i=0; i<nbMatieres; i++) fprintf(f2, "%s;%s;%d\n", baseMatieres[i].code, baseMatieres[i].libelle, baseMatieres[i].coefficient); fclose(f2); }
FILE *f3 = fopen(FICHIER_NOTES, "w");
if(f3){ for(int i=0; i<nbNotes; i++) fprintf(f3, "%s;%s;%.2f\n", baseNotes[i].matricule, baseNotes[i].codeMatiere, baseNotes[i].valeur); fclose(f3); }
}
void chargerTout() {
FILE *f1 = fopen(FICHIER_ETUDIANTS, "r");
if(f1){
while(fscanf(f1, " %19[^;];%49[^;];%49[^;];%19[^\n]\n",
baseEtudiants[nbEtudiants].matricule,
baseEtudiants[nbEtudiants].nom,
baseEtudiants[nbEtudiants].prenom,
baseEtudiants[nbEtudiants].classe) == 4)
{
nbEtudiants++;
}
fclose(f1);
}
FILE *f2 = fopen(FICHIER_MATIERES, "r"); if(f2){ while(fscanf(f2, "%9[^;];%49[^;];%d\n", baseMatieres[nbMatieres].code, baseMatieres[nbMatieres].libelle, &baseMatieres[nbMatieres].coefficient) == 3) nbMatieres++; fclose(f2); }
FILE *f3 = fopen(FICHIER_NOTES, "r");
if(f3){
while(fscanf(f3, "%19[^;];%9[^;];%f;%10[^\n]\n",
baseNotes[nbNotes].matricule,
baseNotes[nbNotes].codeMatiere,
&baseNotes[nbNotes].valeur,
baseNotes[nbNotes].dateEval) == 4) nbNotes++;
fclose(f3);
}
}