ajout du tp14 et du tp13

master
antoine.perederii 2 years ago
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

@ -21,7 +21,7 @@ int chargeResults(Pays *tpays[], int nbmax)
Pays p;
int i=0;
FILE *flot;
flot=fopen("joresult.don","r");
flot=fopen("joresult1.don","r");
if(flot==NULL)
{
printf("Erreur d'ouverture du fichier");
@ -116,7 +116,7 @@ void fusion(Pays *R[], int n, Pays *S[], int m, Pays *tpays[])
int i = 0, j = 0, k = 0;
while(i < n && j < m)
{
if(strcmp(R[i]->pays, S[i]->pays) < 0)
if(strcmp(R[i]->pays, S[j]->pays) < 0)
{
tpays[k] = R[i];
i++;
@ -247,18 +247,22 @@ void sauvegarde(Pays *tpays[], int nb)
void global(void)
{
Pays *tpays[50];
int nb, trouve, pos;
Pays *tpays[130000];
int nb, trouve, pos,choix;
char pays[20], rep;
nb = chargeResults(tpays, 50);
nb = chargeResults(tpays, 130000);
if(nb < 0)
return;
afficheTab(tpays, nb);
//triEchange(tpays, nb);
triFusion(tpays, nb);
printf("1.tri echange \n2. trie dico \n");
printf("votre choix : ");
scanf("%d",&choix);
if(choix == 1)
triEchange(tpays, nb);
else triFusion(tpays, nb);
printf("\n--------- tableau après tri ---------\n");
afficheTab(tpays, nb);
printf("Voulez-vous modifier un pays ? (o/n) : ");
/*printf("Voulez-vous modifier un pays ? (o/n) : ");
scanf("%c", &rep);
while(rep == 'o' || rep == 'O')
{
@ -276,5 +280,5 @@ void global(void)
if(nb < 0)
return;
afficheTab(tpays, nb);
sauvegarde(tpays, nb);
sauvegarde(tpays, nb);*/
}

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…
Cancel
Save