ajout du tp de BDD et d'algo

master
antoine.perederii 2 years ago
parent b188765fab
commit 1c6d76ffac

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,6 @@
acsi1 4 analyse et conception
algo1 4 algorithme périodique 1
algo2 4 algorithme périodique 2
based 4 base de données
maths 2 mathématiques
organ 2 organisation

@ -0,0 +1,21 @@
#include "tp12.h"
void testCharge(void)
{
Mat *tab[50];
int nb;
char nomFich[20];
printf("Donnez le nom du fichier :\n");
scanf("%s", nomFich);
nb = chargeFmatieres(nomFich, tab, 50);
if(nb < 0)
return;
afficheTmat(tab, nb);
}
int main(void)
{
//testCharge();
global();
return 0;
}

@ -0,0 +1,146 @@
#include "tp12.h"
int chargeFmatieres(char *nomFich, Mat **tmat, int tmax)
{
int i = 0;
Mat m;
FILE *flot;
printf("%d\n", i);
flot = fopen(nomFich, "r");
if(flot == NULL)
{
printf("Pb d'ouverture du fichier %s.\n", nomFich);
return -1;
}
m = lireMat(flot);
while(!feof(flot))
{
if(i == tmax)
{
printf("tbl plein !!!\n");
fclose(flot);
return -2;
}
tmat[i] = (Mat *)malloc(sizeof(Mat));
if(tmat[i] == NULL)
{
printf("Pb du tableau !\n");
fclose(flot);
return -3;
}
*tmat[i] = m;
i = i +1;
m = lireMat(flot);
}
fclose(flot);
return i;
}
Mat lireMat(FILE *flot)
{
Mat m;
fscanf(flot, "%s%d", m.code, &m.coef);
fgets(m.design, 30, flot);
m.design[strlen(m.design)-1] = '\0';
return m;
}
void afficheMat(Mat m)
{
printf("%s\t%d\t%s\n", m.code, m.coef, m.design);
}
void afficheTmat(Mat **tMat, int nbmat)
{
int i;
for(i = 0; i < nbmat; i++)
afficheMat(*tMat[i]);
printf("\n");
}
void libereEspaceA(Mat *tmat[], int nb)
{
int i;
for(i = 0; i < nb; i++)
free(tmat[i]);
}
void sauvTbin(Mat *tab[], int nb)
{
int i;
FILE *flot;
flot = fopen("matieres.bin", "wb");
if(flot == NULL)
{
printf("Pb d'ouverture du fichier matieres.bin");
return;
}
fprintf(flot, "%d\n", &nb);
for(i = 0; i < nb; i++)
fwrite(tab[i], sizeof(Mat), 1, flot);
fclose(flot);
}
int rechdich(char *code, Mat **tmat, int nbmat, int *trouve)
{
int inf, sup, m;
inf = 0;
sup = nbmat -1;
while(inf <= sup)
{
m = (inf + sup)/2;
if(strcmp(code, tmat[m]->code) == 0)
{
*trouve = 1;
return m;
}
if(strcmp(code, tmat[m]->code) < 0)
sup = m - 1;
else inf = m+ 1;
}
*trouve = 0;
return inf;
}
int supprime(Mat **tMat, int nbmat)
{
char code[6], rep;
int pas, trouve, i;
printf("Donnez le code de la matière à supprimer :\n");
scanf("%s%*c", code);
pas = rechdich(code, tMat, nbmat, &trouve);
if(trouve == 0)
printf("Aucune matière n'as été trouvé\n");
else{
afficheMat(*tMat[pas]);
printf("Vouez vous vraiment supprimer ? :\n");
scanf("%c", &rep);
if(rep == 'o')
{
free(tMat[pas]);
for(i = pas; i < nbmat-1; i++)
tMat[i] = tMat[i + 1];
nbmat = nbmat - 1;
}
}
return nbmat;
}
void global(void)
{
Mat *tab[50];
int nb;
char nomFich[20];
printf("Donnez le nom du fichier :\n");
scanf("%s", nomFich);
nb = chargeFmatieres(nomFich, tab, 50);
if(nb < 0)
return;
afficheTmat(tab, nb);
nb = supprime(tab, nb);
afficheTmat(tab, nb);
nb = supprime(tab, nb);
afficheTmat(tab, nb);
sauvTbin(tab, nb);
libereEspaceA(tab, nb);
}

@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char code[6];
int coef;
char design[32];
} Mat;
int chargeFmatieres(char *nomFich, Mat **tmat, int tmax);
void global(void);
Mat lireMat(FILE *flot);
void afficheMat(Mat m);
void afficheTmat(Mat **tMat, int nbmat);
void libereEspaceA(Mat *tmat[], int nb);
void sauvTbin(Mat *tab[], int nb);
int rechdich(char *code, Mat **tmat, int nbmat, int *trouve);
int supprime(Mat **tMat, int nbmat);
void testCharge(void);

@ -1,3 +1,4 @@
bai
baie
bail
bailler

@ -250,7 +250,7 @@ void chercher(char tab[][27], int nb, char mot[])
if (tab[i][j] == mot[k] && num[k] == 0)
{
num[k] = 1;
pass=1;
pass = 1;
break;
}
}

Binary file not shown.

@ -107,10 +107,9 @@ int compterLettres(char mot[])
/* Exercice 3 */
void chargement(int tMot[][nbMots])
void chargement(int tMot[], int nbMots)
{
int i = 0, j;
FILE *flot;
flot = fopen("mots.don", "r");
if (flot == NULL)

@ -7,4 +7,4 @@ void initialiser(char mot[], int n);
void placer(char mot1[], char c, char mot2[]);
void jeuPendu(void);
int compterLettres(char mot[]);
void chargement(int tMot);
//void chargement(int tMot, int nbMots);

@ -3,3 +3,4 @@ maths 2 mathématiques
maths 4
maths 5
math 5 sdjlkgf sdkjgf 55dsf
algo1 8 algorithme

@ -222,13 +222,13 @@ UPDATE DRAGON SET num_terr = 'T03' WHERE numD = 'D0008';
/* SELECT NOURRITURE.nom FROM NOURRITURE JOIN REPAS ON NOURRITURE.numn = REPAS.numn JOIN DRAGON ON REPAS.numd = DRAGON.numd JOIN AMOUR ON DRAGON.numD = AMOUR.numDragon1 WHERE DRAGON.longeur>200 AND AMOUR.force = 'un peu'; */
/* Question 12 */
/* SELECT DRAGON.nom FROM DRAGON JOIN AMOUR ON DRAGON.numD = AMOUR.numDragon1 */
/* SELECT aimant.nom, aime.nom FROM DRAGON aimant JOIN AMOUR ON aimant.numD = AMOUR.numDragon1 JOIN DRAGON AS aime ON AMOUR.numDragon2 = aime.numD; */
/* Question 13 */
/* SELECT DISTINCT DRAGON.nom FROM DRAGON JOIN REPAS ON DRAGON.numD = REPAS.numD JOIN NOURRITURE ON REPAS.numN = NOURRITURE.numN WHERE NOURRITURE.nom = 'Oeuf' AND DRAGON.numD NOT IN (SELECT DRAGON.numD FROM DRAGON JOIN REPAS ON DRAGON.numD = REPAS.numD JOIN NOURRITURE ON REPAS.numN = NOURRITURE.numN WHERE NOURRITURE.nom = 'Orange'); */
/* Question 14 */
/*
/* */

Loading…
Cancel
Save