Académique Documents
Professionnel Documents
Culture Documents
Paix-Travail-Patrie Peace-Work-FATHER-LAND
******* *******
******* *******
Rédigé par :
Le nom de l’étudiant
Le département
Le numéro
Les notes du semestre
Et le nouvel enregistrement va écraser le précédent. Si l’enregistrement
précédent n’existe pas alors on nous affichera : « erreur enregistrement non
trouvé »
II. CODE SOURCE DU PROGRAMME
19 char pass[25];
20 };
23 char name[100];
24 char dept[50];
25 int roll;
26 float sgpa[25];
27 float cgpa;
28 }Student;
29
30 int main()
31 {
32 struct pass pa;
33 int ch,i,id;
34 int k=0;
35 char c,pas[50];
36 FILE *tp; // création dun pointeur//
37 FILE *fp;
38 Student s;
39 int option;
40 char another;
41 SetConsoleTitle("GESTION DES ETUDIANTS | IAI CAMEROUN");
42 if((fp=fopen("db.txt","rb+"))==NULL)
43 {
44 if((fp=fopen("db.txt","wb+"))==NULL)
45 {
46 printf("impossible de creer d'ouvrir la base de bonnées.");
47 return 0;
48 }
49 }
50 system("color 9f");
51 gotoxy(42,8);
52 printf("CONNEXION(si vous vous connectez pour la premiere fois appuyez sur ENTRER");
53 gotoxy(42,10);
54 printf("______________________________________");
55 gotoxy(42,11);
56 printf("|\tEntrer le mot de passe: |");
57 gotoxy(42,12);
58 printf("|_____________________________________|");
59 //printf("\n\t\t\t\t\t");
60 gotoxy(65,11);
61 while(k<10)
62 {
63 pas[k]=getch();
64 char s=pas[k];
65 if(s==13)
66 break;
67 else printf("*");
68 k++;
69 }
70 pas[k]='\0';
71 tp=fopen("C:/Password.txt","r+");
72 fgets(pa.pass,25,tp);
73 if(strcmp(pas,pa.pass)==0)
74 {
75 system("cls");
76 gotoxy(10,3);
77 printf("<<<<veillez patientez pendant le chargement>>>>");
78 for(i=0;i<5;i++)
79 {
80 printf("\t(*_*)");
81 Sleep(500);
82 }
83 printf("\n\n\n\n\n\t\t\t\t\t * * * * * * * *");
84 printf("\n\n\t\t\t\t\t * *");
85 printf("\n\n\t\t\t\t\t * Bienvenue *");
86 printf("\n\n\t\t\t\t\t ********");
87 printf("\n\n\\n\n\n\t\t\t\t\t Appuyer sur n importe qu elle touche pour continuer.....");
88 getch();
89
90 char title();
91 printf("\n\n\t\t\t IAI CAMEROUN 2021");
92 printf("\n\n\t\t\t LA CLASSE DE L1_");
93 printf("\n\n\t\t\t Le centre d excellence\n\t\t\t");
94 char Affichercaractere();
95 printf("\n\n\n\t\t\t Appuyer sur n importe qu elle touche pour entrer");
96 getch();
97
98
99
100
101 printf("\n\t");
102
103 printf("\n\n\t\t\t\t1. Ajouter un Etudiant");
104 printf("\n\n\t\t\t\t2. Modifier un Etudiant");
105 printf("\n\n\t\t\t\t3. Afficher tous les Etudiants");
106 printf("\n\n\t\t\t\t4. Affichage individuel");
107 printf("\n\n\t\t\t\t5. Supprimer un Etudiant");
108 printf("\n\n\t\t\t\t6. Modifier Mot de Passe");
109 printf("\n\n\t\t\t\t7. Deconnexion\n\t");
110 char AfficherCatactere();
111 printf("\n\n\t\t\t\tEntrer votre choix : ");
112
113 }
114 else
115 {
116 printf("Mauvais mot de passe . Sortie");
117 getch();
118 }
119 return 1;
120 }
121
122 //Etape 5 :
123 //Nous voulons rendre ce programme fonctionnel. Car il fait appel à certaines procédures
qui vont permettre
124 //d’atteindre l’objectif fixé au départ de cet exercice.
125 //Commençons par la procédure MotDePasse()
126
127 void MotDePasse() // creation de la procedure MotDepasse//
128 {
129 int c;
130 struct pass pa;
131 FILE *tp;
132 printf("\n Entrer nouveau mot de passe : ");
133 fflush(stdin);
134 gets(pa.pass);
135 printf("\nSauvegarder Mot de Passe (y/n) :");
136 fflush(stdin);
137 scanf("%c",&c);
138 if(c=='y'||c=='Y')
139 {
140 tp=fopen("C:/Password.txt","w+");
141
142 fwrite(&pa,sizeof(pa),1,tp);
143 fclose(tp);
144 printf("\n\tMot de passe enregistré\n");
145 }
146 else
147 {
148 printf("Mot de passe non enregistré :\n");
149 printf("Appuyez sur une touche pour continuer >>>");
150 getch();
151 }
152 }
153
154 void AfficherCaractere(char ch,int n)// creation de la procedure AfficherCaractere//
155 {
156 while(n)
157 {
158 putchar(ch);
159 }
160 }
161
162 void Titre()// creation de la procedure Titre//
163 {
164 system("cls");
165 system("COLOR 03");
166 printf("\n\n\t");
167 printf(" GESTION DES ETUDIANTS ");
168 printf("\n");
169 }
170
171 //Insérer à la fin
172
173 void Ajouter(FILE * fp)// creation de la procedure Ajouter
174 {
175 Titre();
176 char another='y';
177 Student s;
178 int i;
179 float cgpa;
180 fseek(fp,0,SEEK_END);
181 while(another=='y'||another=='Y')
182 {
183 printf("\n\n\t\t Entrer le nom complet: ");
184 fflush(stdin);
185 fgets(s.name,100,stdin);
186 s.name[strlen(s.name)-1]='\0';
187 printf("\n\n\t\tEnter Nom département: ");
188 fflush(stdin);
189 fgets(s.dept,50,stdin);
190 s.dept[strlen(s.dept)-1]='\0';
191 printf("\n\n\t\tEntrer le numéro: ");
192 scanf("%d",&s.roll);
193 printf("\n\n\tEntrer les 12 notes pour le semestre\n");
194 for(i=0,cgpa=0; i<12; i++)
195 {
196 scanf("%f",&s.sgpa[i]);
197 cgpa=s.sgpa[i];
198 }
199
200 cgpa=12.0;
201 s.cgpa=cgpa;
202 fwrite(&s,sizeof(s),1,fp);
203 printf("\n\n\t\tAjouter un nouvel étudiant?(Y/N)?");
204 fflush(stdin);
205 another=getchar();
206 }
207 }
208 FILE * Supprimer(FILE * fp)
209 {
210 char title();
211 Student s;
212 int flag=0,tempRoll,siz=sizeof(s);
213 FILE *ft;
214 if((ft=fopen("temp.txt","wb+"))==NULL)
215 {
216 printf("\n\n\t\t\t\\t!!! ERREUR !!!\n\t\t");
217 system("pause");
218 return fp;
219 }
220 printf("\n\n\tEntrer le numéro d'étudiant à supprimer");
221 printf("\n\n\t\t\tRoll No. : ");
222 scanf("%d",&tempRoll);
223 rewind(fp);
224 while((fread(&s,siz,1,fp))==1)
225 {
226 if(s.roll==tempRoll)
227 {
228 flag=1;
229 printf("\n\tEnregistrement supprimé");
230 printf("\n\n\t\t%s\n\n\t\t%s\n\n\t\t%d\n\t",s.name,s.dept,s.roll);
231 continue;
232 }
233 fwrite(&s,siz,1,ft);
234 }
235 fclose(fp);
236 fclose(ft);
237 remove("db.txt");
238 rename("temp.txt","db.txt");
239 if((fp=fopen("db.txt","rb+"))==NULL)
240 {
241 printf("ERREUR");
242 return NULL;
243 }
244 if(flag==0)
245 printf("\n\n\t\tAUCUNE INFORMATION ETUDIANT TROUVEE\n\t");
246 printf("\n\t");
247 system("pause");
248 return fp;
249 }
250
251 void Modifier(FILE * fp)
252 {
253 char title();
254 Student s;
255 int i,flag=0,tempRoll,siz=sizeof(s);
256 float cgpa;
257 printf("\n\n\tEntrer le numéro étudiant à modifier : ");
258 scanf("%d",&tempRoll);
259 rewind(fp);
260 while((fread(&s,siz,1,fp))==1)
261 {
262 if(s.roll==tempRoll)
263 {
264 flag=1;
265 break;
266 }
267 }
268 if(flag==1)
269 {
270 fseek(fp,-siz,SEEK_CUR);
271 printf("\n\n\t\t\t\tEnregistrement trouvé\n\t\t\t");
272 printf("\n\n\t\t\tNom Etudiant: %s",s.name);
273 printf("\n\n\t\t\tNuméro étudiant: %d\n\t\t\t",s.roll);
274 printf("\n\n\t\t\tEntrer les nouvelles données");
275 printf("\n\n\t\t\tEntrer le nom complet: ");
276 fflush(stdin);
277 fgets(s.name,100,stdin);
278 s.name[strlen(s.name)-1]='\0';
279 printf("\n\n\t\t\tEntrer Département: ");
280 fflush(stdin);
281 fgets(s.dept,50,stdin);
282 s.dept[strlen(s.dept)-1]='\0';
283 printf("\n\n\t\t\tEntrer le numéro: ");
284 scanf("%d",&s.roll);
285 printf("\n\n\t\tEntrer les 12 notes pour le semestre (SGPA)\n");
286 for(i=0,cgpa=0; i<12; i++)
287 {
288 scanf("%f",&s.sgpa[i]);
289 cgpa+=s.sgpa[i];
290 }
291 cgpa=cgpa/8.0;
292 fwrite(&s,sizeof(s),1,fp);
293 }
294 else
295 printf("\n\n\t!!!! ERREUR !!!! ENREGISTREMENT NON TROUVE");
296 printf("\n\n\t");
297 system("pause");
298 }
299
300 void Afficher(FILE * fp)
301 {
302 char title();
303 Student s;
304 int i,siz=sizeof(s);
305 rewind(fp);
306 while((fread(&s,siz,1,fp))==1)
307 {
308 printf("\n\t\tNOM : %s",s.name);
309 printf("\n\n\t\tDépartement : %s",s.dept);
310 printf("\n\n\t\tNuméro : %d",s.roll);
311 printf("\n\n\tSGPA: ");
312 for(i=0; i<12; i++)
313 printf("| %.2f |",s.sgpa[i]);
314 printf("\n\n\t\tCGPA : %.2f\n\t",s.cgpa);
315 }
316 printf("\n\n\n\t");
317 printf("\n\n\t");
318 system("pause");
319 }
320
321
322 void AffichageSpecifique(FILE *fp)
323 {
324 char title();
325 int tempRoll,flag,siz,i;
326 Student s;
327 char another='y';
328 siz=sizeof(s);
329 while(another=='y'||another=='Y')
330 {
331 printf("\n\n\tEntrer numéro étudiant: ");
332 scanf("%d",&tempRoll);
333 rewind(fp);
334 while((fread(&s,siz,1,fp))==1)
335 {
336 if(s.roll==tempRoll)
337 {
338 flag=1;
339 break;
340 }
341 }
342 if(flag==1)
343 {
344 printf("\n\t\tNOM : %s",s.name);
345 printf("\n\n\t\tDépartement : %s",s.dept);
346 printf("\n\n\t\tNuméro : %d",s.roll);
347 printf("\n\n\tSGPA: ");
348 for(i=0; i<12; i++)
349 printf("| %.2f |",s.sgpa[i]);
350 printf("\n\n\t\tCGPA : %.2f\n\t",s.cgpa);
351
352
353 }
354 else
355 printf("\n\n\t\t!!!! ERREUR ENREGISTREMENT NON TROUVE !!!!");
356 printf("\n\n\t\tAfficher d'autres informations étudiants? (Y/N)?");
357 fflush(stdin);
358 another=getchar();
359 }
360 }