parent
e9dcf7e9c5
commit
95e84afc99
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -0,0 +1,6 @@
|
||||
asci1 4 analyse et conception
|
||||
algo1 4 algoruthmique période 1
|
||||
algo2 4 algorithmique période 2
|
||||
based 4 base de données
|
||||
maths 2 mathématiques
|
||||
organ 2 organisation
|
@ -0,0 +1,6 @@
|
||||
algo 6 algo
|
||||
algo1 4 algoruthmique période 1
|
||||
asci1 4 analyse et conception
|
||||
based 4 base de données
|
||||
maths 2 mathématiques
|
||||
organ 2 organisation
|
@ -0,0 +1,7 @@
|
||||
#include "tp14.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
global();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,227 @@
|
||||
#include "tp14.h"
|
||||
|
||||
Mat lireMat(FILE *flot)
|
||||
{
|
||||
Mat x;
|
||||
fscanf(flot, "%s\t%d\t", x.code, &x.coef);
|
||||
fgets(x.design, 32, flot);
|
||||
x.design[strlen(x.design)-1] = '\0';
|
||||
return x;
|
||||
}
|
||||
|
||||
void afficherMat(Mat x)
|
||||
{
|
||||
printf("%s\t%d\t%s\n", x.code, x.coef, x.design);
|
||||
}
|
||||
|
||||
Liste listenouv(void)
|
||||
{
|
||||
Liste l = NULL;
|
||||
return l;
|
||||
}
|
||||
|
||||
Liste insererEnTete(Liste l, Mat x)
|
||||
{
|
||||
Maillon *m;
|
||||
m = (Maillon *)malloc(sizeof(Maillon));
|
||||
if(m == NULL)
|
||||
{
|
||||
printf("Erreur d'allocation mémoire");
|
||||
exit(1);
|
||||
}
|
||||
strcpy(m->v.code, x.code);
|
||||
m->v.coef = x.coef;
|
||||
strcpy(m->v.design, x.design);
|
||||
m->suiv = l;
|
||||
return m;
|
||||
}
|
||||
|
||||
Liste inserer(Liste l, Mat x)
|
||||
{
|
||||
if(l == NULL)
|
||||
return insererEnTete(l, x);
|
||||
if(strcmp(l->v.code, x.code) > 0)
|
||||
return insererEnTete(l, x);
|
||||
if(strcmp(x.code, l->v.code) == 0)
|
||||
return l;
|
||||
l->suiv = inserer(l->suiv, x);
|
||||
return l;
|
||||
}
|
||||
|
||||
Liste supprimerEnTete(Liste l)
|
||||
{
|
||||
Maillon *aux;
|
||||
if(l == NULL)
|
||||
{
|
||||
printf("Opération interdite !!!\n");
|
||||
exit(1);
|
||||
}
|
||||
aux = l;
|
||||
l = l->suiv;
|
||||
free(aux);
|
||||
return l;
|
||||
}
|
||||
|
||||
Liste supprimer(Liste l, Mat x)
|
||||
{
|
||||
if(l == NULL)
|
||||
return l;
|
||||
if(strcmp(l->v.code, x.code) > 0)
|
||||
return l;
|
||||
if(strcmp(x.code, l->v.code) == 0)
|
||||
return supprimerEnTete(l);
|
||||
l->suiv = supprimer(l->suiv, x);
|
||||
return l;
|
||||
}
|
||||
|
||||
Mat Tete(Liste l)
|
||||
{
|
||||
if(l == NULL)
|
||||
{
|
||||
printf("Opération à ne pas faire si la liste est vide !!!\n");
|
||||
exit(1);
|
||||
}
|
||||
return l->v;
|
||||
}
|
||||
|
||||
bool vide(Liste l)
|
||||
{
|
||||
return l == NULL;
|
||||
}
|
||||
|
||||
void afficher(Liste l)
|
||||
{
|
||||
printf("\n");
|
||||
while(! vide(l))
|
||||
{
|
||||
afficherMat(Tete(l));
|
||||
l = l->suiv;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
bool rechercher(Liste l, Mat x)
|
||||
{
|
||||
if(vide(l))
|
||||
return false;
|
||||
if(strcmp(l->v.code, x.code) > 0)
|
||||
return false;
|
||||
if(strcmp(x.code,l->v.code) == 0)
|
||||
return true;
|
||||
return rechercher(l->suiv, x);
|
||||
}
|
||||
|
||||
int longueur(Liste l)
|
||||
{
|
||||
int cpt = 0;
|
||||
while(! vide(l))
|
||||
{
|
||||
cpt++;
|
||||
l = l->suiv;
|
||||
}
|
||||
return cpt;
|
||||
}
|
||||
|
||||
Liste charger(char *nomFichier)
|
||||
{
|
||||
FILE *flot;
|
||||
Mat x;
|
||||
Liste l = listenouv();
|
||||
flot = fopen(nomFichier, "r");
|
||||
if(flot == NULL)
|
||||
{
|
||||
printf("Erreur d'ouverture du fichier !!!\n");
|
||||
exit(1);
|
||||
}
|
||||
x = lireMat(flot);
|
||||
while(!feof(flot))
|
||||
{
|
||||
l = inserer(l, x);
|
||||
x = lireMat(flot);
|
||||
}
|
||||
fclose(flot);
|
||||
return l;
|
||||
}
|
||||
|
||||
void sauv(Liste l, char *nomFichier)
|
||||
{
|
||||
FILE *flot;
|
||||
flot = fopen(nomFichier, "w");
|
||||
if(flot == NULL)
|
||||
{
|
||||
printf("Erreur d'ouverture du fichier !!!\n");
|
||||
exit(1);
|
||||
}
|
||||
while(! vide(l))
|
||||
{
|
||||
fprintf(flot, "%s\t%d\t%s\n", l->v.code, l->v.coef, l->v.design);
|
||||
l = l->suiv;
|
||||
}
|
||||
fclose(flot);
|
||||
}
|
||||
|
||||
int menu(void)
|
||||
{
|
||||
int choix;
|
||||
printf("1. Inserer un élément dans la liste\n");
|
||||
printf("2. Supprimer un élément de la liste\n");
|
||||
printf("3. Afficher la liste\n");
|
||||
printf("4. Rechercher un élément dans la liste\n");
|
||||
printf("5. Afficher la longueur de la liste\n");
|
||||
printf("6. Quitter\n");
|
||||
printf("Votre choix : ");
|
||||
scanf("%d", &choix);
|
||||
return choix;
|
||||
}
|
||||
|
||||
void global(void)
|
||||
{
|
||||
Liste l;
|
||||
Mat x;
|
||||
char code[6], design[32];
|
||||
int choix, coef;
|
||||
char nomFichier[32];
|
||||
|
||||
l = charger("matieres.don");
|
||||
choix = menu();
|
||||
while (choix != 6)
|
||||
{
|
||||
if(choix == 1)
|
||||
{
|
||||
printf("\nEntrer le code de la matière : ");
|
||||
scanf("%s", &code);
|
||||
printf("Entrer le coefficient de la matière : ");
|
||||
scanf("%d", &coef);
|
||||
printf("Entrer la désignation de la matière : ");
|
||||
scanf("%s", &design);
|
||||
printf("\n");
|
||||
strcpy(x.code, code);
|
||||
x.coef = coef;
|
||||
strcpy(x.design, design);
|
||||
l = inserer(l, x);
|
||||
}
|
||||
if(choix == 2)
|
||||
{
|
||||
printf("\nEntrer le code de la matière à supprimer : ");
|
||||
scanf("%s", &code);
|
||||
strcpy(x.code, code);
|
||||
l = supprimer(l, x);
|
||||
}
|
||||
if(choix == 3)
|
||||
afficher(l);
|
||||
if(choix == 4)
|
||||
{
|
||||
printf("\nEntrer le code de la matière à rechercher : ");
|
||||
scanf("%s", &code);
|
||||
strcpy(x.code, code);
|
||||
if(rechercher(l, x) == true)
|
||||
printf("La matière est dans la liste\n\n");
|
||||
else
|
||||
printf("La matière n'est pas dans la liste\n\n");
|
||||
}
|
||||
if(choix == 5)
|
||||
printf("\nLa longueur de la liste est : %d\n\n", longueur(l));
|
||||
choix = menu();
|
||||
}
|
||||
sauv(l, "matieres.txt");
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
char code [6];
|
||||
int coef;
|
||||
char design[32];
|
||||
} Mat;
|
||||
|
||||
typedef struct maillon {
|
||||
Mat v;
|
||||
struct maillon *suiv;
|
||||
} Maillon, *Liste;
|
||||
|
||||
Liste listenouv(void);
|
||||
Liste insererEnTete(Liste l, Mat x);
|
||||
Liste inserer(Liste l, Mat x);
|
||||
Liste supprimerEnTete(Liste l);
|
||||
Liste supprimer(Liste l, Mat x);
|
||||
void afficher(Liste l);
|
||||
Mat Tete(Liste l);
|
||||
bool vide(Liste l);
|
||||
bool rechercher(Liste l, Mat x);
|
||||
int longueur(Liste l);
|
||||
Liste charger(char *nomFichier);
|
||||
void sauv(Liste l, char *nomFichier);
|
||||
int menu(void);
|
||||
void global(void);
|
Loading…
Reference in new issue