Merge branch 'master' of https://codefirst.iut.uca.fr/git/antoine.perederii/IUT
commit
5610a51a9d
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);
|
Binary file not shown.
@ -0,0 +1,235 @@
|
||||
DROP TABLE REPAS;
|
||||
DROP TABLE AMOUR;
|
||||
DROP TABLE DRAGON;
|
||||
DROP TABLE NOURRITURE;
|
||||
DROP TABLE TERRITOIRE;
|
||||
|
||||
\! clear
|
||||
|
||||
CREATE TABLE TERRITOIRE(
|
||||
num_terr char(3) PRIMARY KEY,
|
||||
nom varchar(30) UNIQUE,
|
||||
longitude numeric NOT NULL CHECK (longitude <= 180 AND longitude >= -180),
|
||||
latitude1 numeric NOT NULL CHECK (latitude1 <= 90),
|
||||
latitude2 char(1) NOT NULL CHECK (latitude2 ='S' OR latitude2 ='N')
|
||||
);
|
||||
CREATE TABLE DRAGON(
|
||||
numD char(5) PRIMARY KEY,
|
||||
nom varchar(30) UNIQUE,
|
||||
longeur numeric NOT NULL CHECK (longeur > 0),
|
||||
sexe char(1) NOT NULL CHECK (sexe ='F' OR sexe ='M'),
|
||||
nb_ecailles numeric CHECK (nb_ecailles > 0),
|
||||
date_naissance date,
|
||||
en_amour varchar(20) NOT NULL CHECK (en_amour ='macho' AND sexe='M' OR en_amour='timide' OR en_amour='sincere' OR en_amour='volage'),
|
||||
crache_feu char(1) CHECK (crache_feu ='O' OR crache_feu ='N'),
|
||||
num_terr char(4) REFERENCES TERRITOIRE
|
||||
);
|
||||
|
||||
CREATE TABLE NOURRITURE(
|
||||
numN char(5)PRIMARY KEY,
|
||||
nom varchar(30) UNIQUE,
|
||||
calories numeric NOT NULL CHECK (calories >0)
|
||||
|
||||
);
|
||||
CREATE TABLE AMOUR (
|
||||
force varchar(20) CHECK (force='un peu' OR force='beaucoup' OR force='passionnement' OR force='a la folie'),
|
||||
numDragon1 char(5) REFERENCES DRAGON,
|
||||
numDragon2 char(5) REFERENCES DRAGON,
|
||||
PRIMARY KEY (numDragon1,numDragon2)
|
||||
);
|
||||
|
||||
CREATE TABLE REPAS(
|
||||
date_repas date,
|
||||
qte numeric NOT NULL CHECK (qte >0),
|
||||
numD char(5) REFERENCES DRAGON,
|
||||
numN char(5) REFERENCES NOURRITURE,
|
||||
PRIMARY KEY (numD,numN)
|
||||
);
|
||||
|
||||
INSERT INTO TERRITOIRE VALUES('T01', 'terre brûlées', 92, 40, 'S');
|
||||
INSERT INTO TERRITOIRE VALUES ('T02', 'Terre de fleurs', 98, 48, 'S');
|
||||
INSERT INTO TERRITOIRE VALUES ('T03', 'Fleur de naiges', 100, 8, 'N');
|
||||
|
||||
INSERT INTO DRAGON VALUES('D0001', 'Smeagol', 152, 'M', 1857,'14/06/1985', 'macho', 'O', 'T02');
|
||||
INSERT INTO DRAGON VALUES ('D0002', 'Birduth', 258, 'M', 4787, '05/05/1989', 'timide', 'N', 'T01');
|
||||
INSERT INTO DRAGON VALUES ('D0003', 'Negueth', 128,'F',1582,'08/08/1992', 'sincere', 'O', 'T02');
|
||||
INSERT INTO DRAGON VALUES ('D0004', 'Miss Toc', 183,'F',2781,'04/07/2020', 'volage', NULL, 'T01');
|
||||
INSERT INTO DRAGON VALUES ('D0005', 'Bolong', 213,'M',754,'06/05/2010', 'macho', 'N', 'T01');
|
||||
INSERT INTO DRAGON VALUES ('D0006', 'Miloch', 83,'M',718,'29/04/2015', 'timide', 'O', 'T02');
|
||||
INSERT INTO DRAGON VALUES ('D0007', 'Nessie', 168,'M',1721,'12/12/2005', 'macho', 'O', 'T02');
|
||||
INSERT INTO DRAGON VALUES ('D0008', 'Tarak', 123,'F',851,'15/04/2009', 'timide', 'N', 'T03');
|
||||
INSERT INTO DRAGON VALUES ('D0009', 'Solong', 173,'M',1481,'04/08/2021', 'timide', NULL, 'T01');
|
||||
|
||||
INSERT INTO NOURRITURE VALUES ('P0001', 'Pomme', '7');
|
||||
INSERT INTO NOURRITURE VALUES ('P0002', 'Cacahuète', '10');
|
||||
INSERT INTO NOURRITURE VALUES ('P0003', 'Orange', '25');
|
||||
INSERT INTO NOURRITURE VALUES ('P0004', 'Oeuf', '15');
|
||||
INSERT INTO NOURRITURE VALUES ('P0005', 'Ver', '3');
|
||||
INSERT INTO NOURRITURE VALUES ('P0006', 'Poisson', '35');
|
||||
|
||||
INSERT INTO AMOUR VALUES ('passionnement', 'D0001', 'D0008');
|
||||
INSERT INTO AMOUR VALUES ('beaucoup', 'D0002', 'D0003');
|
||||
INSERT INTO AMOUR VALUES ('a la folie', 'D0003', 'D0006');
|
||||
INSERT INTO AMOUR VALUES ('a la folie', 'D0006', 'D0003');
|
||||
INSERT INTO AMOUR VALUES ('un peu', 'D0008', 'D0005');
|
||||
INSERT INTO AMOUR VALUES ('beaucoup', 'D0005', 'D0008');
|
||||
INSERT INTO AMOUR VALUES ('un peu', 'D0007', 'D0008');
|
||||
|
||||
INSERT INTO REPAS VALUES ('10/09/2021', 1000, 'D0001', 'P0002');
|
||||
INSERT INTO REPAS VALUES ('10/09/2021', 16, 'D0001', 'P0001');
|
||||
INSERT INTO REPAS VALUES ('11/09/2021', 4, 'D0005', 'P0004');
|
||||
INSERT INTO REPAS VALUES ('10/09/2021', 6, 'D0003', 'P0003');
|
||||
INSERT INTO REPAS VALUES ('11/09/2021', 1, 'D0003', 'P0004');
|
||||
INSERT INTO REPAS VALUES ('10/09/2021', 53, 'D0006', 'P0005');
|
||||
INSERT INTO REPAS VALUES ('11/09/2021', 100, 'D0006', 'P0002');
|
||||
INSERT INTO REPAS VALUES ('10/09/2021', 20, 'D0007', 'P0006');
|
||||
INSERT INTO REPAS VALUES ('10/09/2021', 10, 'D0008', 'P0001');
|
||||
INSERT INTO REPAS VALUES ('11/09/2021', 10, 'D0008', 'P0003');
|
||||
INSERT INTO REPAS VALUES ('10/09/2021', 1, 'D0009', 'P0006');
|
||||
INSERT INTO REPAS VALUES ('11/09/2021', 2, 'D0009', 'P0003');
|
||||
INSERT INTO REPAS VALUES ('12/09/2021', 8, 'D0009', 'P0004');
|
||||
INSERT INTO REPAS VALUES ('25/09/2021', 20, 'D0006', 'P0003');
|
||||
|
||||
SELECT * FROM TERRITOIRE;
|
||||
SELECT * FROM DRAGON;
|
||||
SELECT * FROM NOURRITURE;
|
||||
SELECT * FROM AMOUR;
|
||||
SELECT * FROM REPAS;
|
||||
|
||||
/* TP5 a mettre dans le terminale */
|
||||
|
||||
/* Question 1 */
|
||||
/* SELECT nom FROM DRAGON WHERE crache_feu = 'O'; */
|
||||
|
||||
/* Question 2 */
|
||||
/* SELECT nom FROM DRAGON WHERE crache_feu = 'O' AND en_amour = 'timide'; */
|
||||
|
||||
/* Question 3 */
|
||||
/* SELECT * FROM DRAGON WHERE sexe = 'F' ORDER BY longeur DESC; */
|
||||
|
||||
/* Question 4 */
|
||||
/* SELECT longeur/nb_ecailles FROM DRAGON; */
|
||||
|
||||
/* Question 5 */
|
||||
/* SELECT DISTINCT numDragon1 FROM AMOUR; */
|
||||
|
||||
/* Question 6 */
|
||||
/* SELECT numDragon1 FROM AMOUR WHERE numDragon2 = 'D0003'; */
|
||||
|
||||
/* Question 7 */
|
||||
/* SELECT numDragon2 FROM AMOUR WHERE numDragon1 = 'D0005'; */
|
||||
|
||||
/* Question 8 */
|
||||
/* SELECT numDragon1 FROM AMOUR WHERE force = 'un peu'; */
|
||||
|
||||
/* Question 9 */
|
||||
/* SELECT numDragon1, force, numDragon2 FROM AMOUR WHERE force = 'passionnement'; */
|
||||
|
||||
/* Question 10 */
|
||||
/* SELECT * FROM NOURRITURE WHERE calories < 10; */
|
||||
|
||||
/* Question 11 */
|
||||
/* SELECT * FROM REPAS JOIN NOURRITURE ON REPAS.numN = NOURRITURE.numN WHERE NOURRITURE.nom = 'Oeuf'; */
|
||||
|
||||
/* Question 12 */
|
||||
/* SELECT distinct(numD) FROM REPAS; */
|
||||
|
||||
/* Question 13 */
|
||||
/* SELECT * FROM DRAGON WHERE num_terr = 'T01'; */
|
||||
|
||||
/* Question 14 */
|
||||
/* SELECT * FROM TERRITOIRE WHERE latitude2 = 'S'; */
|
||||
|
||||
|
||||
|
||||
/* TP7*/
|
||||
|
||||
/* Question 1 */
|
||||
/* SELECT * FROM DRAGON WHERE nom LIKE 'S%'; */
|
||||
|
||||
/* Question 2 */
|
||||
/* SELECT numDragon1 || ' aime ' || numDragon2 || ' de manière : ' || force FROM Amour; */
|
||||
|
||||
/* Question 3 */
|
||||
/* SELECT nom, char_length(nom) FROM TERRITOIRE; */
|
||||
|
||||
/* Question 4 */
|
||||
/* SELECT lower(nom) FROM NOURRITURE; */
|
||||
|
||||
/* Question 5 */
|
||||
/* SELECT substr(nom, 1, 3) FROM DRAGON; */
|
||||
|
||||
/* Question 6 */
|
||||
/* SELECT to_char(current_date, 'YYYY-MM-DD'); */
|
||||
|
||||
/* Question 7 */
|
||||
/* SELECT current_date -10 as "date il y a 10 jours"; */
|
||||
|
||||
/* Question 8 */
|
||||
/* SELECT (CURRENT_DATE - '2004-01-12'::date) / 365 as age, round((current_date - '2004-01-12'::date) / 365::numeric, 3) as age_reel; */
|
||||
|
||||
/* Question 9 */
|
||||
/* SELECT ceil((current_date-'2004-01-12'::date)/365::numeric); */
|
||||
|
||||
/* Question 10 */
|
||||
/* SELECT trunc((current_date-'2004-01-12'::date)/365::numeric,1);
|
||||
SELECT floor((current_date-'2004-01-12'::date)/365::numeric);*/
|
||||
|
||||
/* Question 11 */
|
||||
/* SELECT round((current_date-date_naissance::date)/365::numeric,3) FROM DRAGON; */
|
||||
|
||||
/* Question 12 */
|
||||
/* SELECT * FROM DRAGON WHERE round((current_date-date_naissance::date)/365::numeric,3)<3;*/
|
||||
|
||||
/* Question 13 */
|
||||
/* SELECT * FROM REPAS WHERE to_char(date_repas, 'MON') = 'SEP'; */
|
||||
|
||||
/* TP8*/
|
||||
|
||||
UPDATE DRAGON SET num_terr = 'T03' WHERE numD = 'D0008';
|
||||
|
||||
/* Question 1 */
|
||||
/* SELECT DRAGON.nom FROM DRAGON JOIN TERRITOIRE ON DRAGON.num_terr = TERRITOIRE.num_terr WHERE TERRITOIRE.latitude2 = 'S'; */
|
||||
|
||||
/* Question 2 */
|
||||
/* SELECT DRAGON.nom FROM DRAGON JOIN AMOUR ON DRAGON.numD = AMOUR.numDragon1 WHERE AMOUR.force = 'un peu'; */
|
||||
|
||||
/* Question 3 */
|
||||
/* SELECT DRAGON.nom FROM DRAGON JOIN REPAS ON DRAGON.numD = REPAS.numD JOIN NOURRITURE ON REPAS.numN = NOURRITURE.numN WHERE NOURRITURE.nom = 'Oeuf'; */
|
||||
|
||||
/* Question 4 */
|
||||
/* SELECT TERRITOIRE.NOM, TERRITOIRE.longitude, TERRITOIRE.latitude1 FROM TERRITOIRE JOIN DRAGON ON TERRITOIRE.num_terr = DRAGON.num_terr JOIN REPAS ON DRAGON.numD = REPAS.numD JOIN NOURRITURE ON REPAS.numN = NOURRITURE.numN WHERE NOURRITURE.nom = 'Orange'; */
|
||||
|
||||
/* Question 5 */
|
||||
/* SELECT REPAS.date_repas, REPAS.qte, NOURRITURE.nom, NOURRITURE.calories FROM REPAS JOIN NOURRITURE ON REPAS.numN = NOURRITURE.numN WHERE REPAS.numD = 'D0008' ORDER BY REPAS.date_repas; */
|
||||
|
||||
/* Question 6 */
|
||||
/* SELECT NOURRITURE.numn, NOURRITURE.nom, TERRITOIRE.num_terr FROM NOURRITURE JOIN REPAS ON NOURRITURE.numn = REPAS.numn JOIN DRAGON ON REPAS.numd = DRAGON.numd JOIN TERRITOIRE ON DRAGON.num_terr = TERRITOIRE.num_terr ORDER BY TERRITOIRE.num_terr; */
|
||||
|
||||
/* Question 7 */
|
||||
/* SELECT DRAGON.nom FROM DRAGON JOIN TERRITOIRE ON DRAGON.num_terr = TERRITOIRE.num_terr JOIN REPAS ON DRAGON.numD = REPAS.numD JOIN NOURRITURE ON REPAS.numN = NOURRITURE.numN WHERE DRAGON.crache_feu = 'O' AND TERRITOIRE.num_terr = 'T02' AND NOURRITURE.nom = 'Oeuf' OR NOURRITURE.nom = 'Orange' ; */
|
||||
|
||||
/* Question 8 */
|
||||
/* SELECT AMOUR.force, DRAGON.nom FROM DRAGON JOIN AMOUR ON DRAGON.numD = AMOUR.numDragon1; */
|
||||
|
||||
/* Question 9 */
|
||||
/* SELECT DRAGON.nom FROM DRAGON JOIN AMOUR ON DRAGON.numD = AMOUR.numDragon1 JOIN TERRITOIRE ON TERRITOIRE.num_terr = DRAGON.num_terr WHERE DRAGON.crache_feu='O' AND 85<TERRITOIRE.longitude AND TERRITOIRE.longitude<95; */
|
||||
|
||||
/* Question 10 */
|
||||
/* SELECT DRAGON.nom FROM DRAGON JOIN AMOUR ON DRAGON.numD = AMOUR.numDragon1 WHERE AMOUR.force = 'passionement' AND DRAGON.en_amour='macho'; */
|
||||
|
||||
/* Question 11 */
|
||||
/* 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 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 */
|
||||
/* */
|
||||
|
||||
|
||||
|
||||
\d
|
Binary file not shown.
@ -0,0 +1,82 @@
|
||||
### Exercice : tableaux en Numpy (introduction)
|
||||
###############################################
|
||||
|
||||
import numpy as np
|
||||
|
||||
# Tous les passages indiqués "TODO()" sont à remplacer par vos soins
|
||||
def TODO():
|
||||
print("à vous!")
|
||||
exit()
|
||||
|
||||
### DÉFINITION D'UN ARRAY NUMPY
|
||||
|
||||
print("Définition d'un array Numpy à partir d'une list :")
|
||||
A = np.array([ -4, -32, 25, -15, -12, -23, 4, -3, -17])
|
||||
print("A=",A)
|
||||
print("len(A)=",len(A))
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("Définition d'un array Numpy avec la fonction arange:")
|
||||
# np.arange(DEBUT,FIN,PAS)
|
||||
# Fonctionne comme 'range', mais on peut utiliser des nombres non entiers
|
||||
B = np.arange(0,1,0.05) #entre 0 et 1, par pas de 0.05
|
||||
print("B=",B)
|
||||
print("len(B)=",len(B)) #longueur du tableau
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("Définition d'un array Numpy avec la fonction linspace:")
|
||||
# np.linspace(DEBUT,FIN,NOMBRE_DE_POINTS)
|
||||
C = np.linspace(0,np.pi,20)
|
||||
print("C=",C)
|
||||
print("len(C)=",len(C))
|
||||
# Remarque: linspace est généralement le choix le plus pertinent pour les graphiques (voir plus loin)
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
|
||||
### MANIPULATIONS DE BASE : À VOUS !
|
||||
|
||||
print("Affichez un tableau contenant la somme de B et C (élément par élément):")
|
||||
Z = np.array([B+C])
|
||||
print(Z)
|
||||
|
||||
# Remarque : notez bien la différence de fonctionnement comparé aux listes Python!
|
||||
# Dans le cadre de Numpy, l'opérateur '+' reprend un sens mathématique d'addition.
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("Définissez un tableau D de 100 nombres (exactement) répartis uniformément de 1 (inclus) à 10 (inclus).")
|
||||
D = np.linspace(1,10,100)
|
||||
print("D=",D)
|
||||
print("len(D)=",len(D))
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("Définissez un tableau E de 100 nombres, contenant le LOGARITHME DÉCIMAL de chaque valeur contenue dans D.")
|
||||
E = np.log10(D) # a exactement le meme nombre de valeurs que D
|
||||
print("E=",E)
|
||||
print("len(E)=",len(E))
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("Définissez un tableau F de 100 nombres, contenant la formule \"cos(x)+2*sin(x)\" appliquée à chaque élément du tableau D.")
|
||||
F = np.cos(D)+2*np.sin(D) # a exactement le meme nombre de valeurs que D
|
||||
print("F=",F)
|
||||
print("len(F)=",len(F))
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("Trouvez la plus grande valeur contenue dans le tableau F:")
|
||||
print("max(F)=",max(F))
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("Créez un tableau contenant la concaténation des tableaux A et B, sur une seule ligne:")
|
||||
print("A=",A)
|
||||
print("B=",B)
|
||||
G = np.concatenate((A,B))
|
||||
print("G=",G)
|
||||
# (internet autorisé, attention aux parenthèses!)
|
||||
|
@ -0,0 +1,122 @@
|
||||
### Exercice : indexation des tableaux en Numpy
|
||||
###############################################
|
||||
|
||||
import numpy as np
|
||||
|
||||
# Tous les passages indiqués "TODO()" sont à remplacer par vos soins
|
||||
def TODO():
|
||||
print("à vous!")
|
||||
exit()
|
||||
|
||||
# Définition d'un array Numpy
|
||||
A = np.array([ -4, -32, 25, -15, -12, -23, 4, -3, -17, 47, -40, 20, 11,
|
||||
-6, 44, -47, 42, 26, -5, 46, 47, 34, 28, 47, 38, -42,
|
||||
5, -39, -28, 29])
|
||||
print("A=",A)
|
||||
print("len(A)=",len(A))
|
||||
|
||||
#B = np.array([ 4, 6, 8, 9, 2, 1, 19, 101, 115, 12, 112, 2059, 500, 13,
|
||||
# 15, 805, 6077, 6070, 303, 200, 80, 70, 60, 50, 40, 30, 25, 76, 77, 78])
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
### SLICING
|
||||
|
||||
# Le slicing permet d'accéder à une sous-partie d'une liste ou d'un tuple
|
||||
# (objets Python standards) ou d'un array (objet Numpy).
|
||||
# Il prend la forme générale
|
||||
# DEBUT:FIN:PAS
|
||||
# qui signifie : tous les éléments depuis l'indice DEBUT (inclus) jusqu'à
|
||||
# l'indice FIN (exclus) en prenant un élément tous les PAS.
|
||||
|
||||
print("======= Exemple de slicing : A[3:14:2] ")
|
||||
print(A[3:14:2])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
# Si PAS est omis, il vaut 1 (on prend les éléments de 1 en 1)
|
||||
print("Affichez tous les éléments de l'index 3 (inclus) à 14 (exclus).")
|
||||
print(A[3:14])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
# Si DEBUT est omis, il vaut 0 (on part depuis le début du tableau)
|
||||
print("Affichez 1 élément sur 2, depuis le début et jusqu'à l'index 12 INCLUS")
|
||||
print(A[:13:2])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
# Si FIN est omis, on va jusqu'au bout du tableau
|
||||
print("Affichez 1 élément sur 3, depuis l'index 4 (inclus) jusqu'à la fin.")
|
||||
print(A[4::3])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
# Si DEBUT et/ou FIN sont négatifs, ils indiquent une position en partant
|
||||
# de la fin du tableau (-1 est le dernier élément, -2 l'avant-dernier, etc.)
|
||||
print("Affichez les 10 derniers éléments de A.")
|
||||
print(A[-10::])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("\nAffichez 1 élément sur 3, en partant du début, et en vous arrêtant 10 éléments avant la fin du tableau.")
|
||||
print(A[:-9:3])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
# Si PAS est négatif, on lit les éléments dans le sens inverse.
|
||||
print("\nAffichez le tableau A à l'envers, depuis son dernier élément jusqu'au premier.")
|
||||
print(A[::-1])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("\nAffichez les 10 derniers éléments de A, à l'envers.")
|
||||
print(A[:-10:-1])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
|
||||
### INDEXATION PAR UNE LISTE D'INDICES (uniquement en Numpy)
|
||||
|
||||
# En Numpy, on peut utiliser une LISTE (ou un autre ARRAY) de nombres entiers positifs
|
||||
# indiquant tous les emplacements qu'on souhaite lire dans le tableau.
|
||||
|
||||
print("\n======= Exemple d'indexation par une liste :")
|
||||
print("A=",A)
|
||||
print("len(A)=",len(A))
|
||||
indices = [1,3,4,5,10]
|
||||
print(indices)
|
||||
print(A[indices])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("\nExtrayez le sous-tableau de A donné par les indices qui sont un nombre au carré (0,1,4,9, etc.) :")
|
||||
carree = [0,1,4,9,16,25]
|
||||
print(carree)
|
||||
print(A[carree])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
|
||||
### INDEXATION PAR UN MASQUE BINAIRE (uniquement en Numpy)
|
||||
|
||||
# En Numpy, on peut indexer des éléments de A à l'aide d'un autre array, de la même
|
||||
# taille que A, mais contenant des booléens indiquant si chaque index doit être
|
||||
# conservé (True) ou écarté (False)
|
||||
|
||||
print("\n======= Exemple d'indexation par masque binaire:")
|
||||
print("A=",A)
|
||||
print("len(A)=",len(A))
|
||||
test = A>0
|
||||
print(test)
|
||||
print(A[test])
|
||||
|
||||
# exit() # -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("\nCréez un tableau B, de la même taille que A, dans lequel les nombres pairs sont conservés, mais les nombres impairs sont remplacés par des 0 :")
|
||||
B = A.copy()
|
||||
test1 = B%2==0
|
||||
test2 = abs(B)%2!=0
|
||||
B[test2] = 0
|
||||
print(B)
|
||||
# Indice : utilisez la fonction np.mod
|
||||
|
@ -0,0 +1,8 @@
|
||||
import matplotlib.pyplot as plt
|
||||
plt.figure()
|
||||
X=[0,3,2,1]
|
||||
Y=[0,0,1,-1]
|
||||
plt.plot(X,Y,color='blue')
|
||||
plt.axis('equal')
|
||||
plt.title('Ma première figure')
|
||||
plt.show()
|
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
val='a'
|
||||
|
||||
until [ "$val" = "q" ] ; do
|
||||
echo -n "Donnez une commande (<q> pour quitter) : "
|
||||
read "val"
|
||||
if [ "$val" = "q" ]; then
|
||||
exit 0
|
||||
fi
|
||||
echo "$($val)"
|
||||
done
|
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
val=0
|
||||
|
||||
while [ "$val" -ne "9" ] ; do
|
||||
if [ "$val" = "1" ] ; then
|
||||
echo ""
|
||||
echo "$(date)"
|
||||
elif [ "$val" = "2" ] ; then
|
||||
echo ""
|
||||
echo "Il y a $(who -a | wc -l) personnes connéctées sur ta session."
|
||||
elif [ "$val" = "3" ] ; then #les "" et = permettent d'eviter les pb si l'utilisateur tape une chaine de carac
|
||||
echo ""
|
||||
echo "$(ps -elf)"
|
||||
elif [ "$val" != "9" ]; then
|
||||
echo "C'est quoi ce chiffre ??!! Je ne connais pas !!" >&2
|
||||
fi
|
||||
|
||||
echo""
|
||||
echo "Menu général"
|
||||
echo "******************************"
|
||||
echo ""
|
||||
echo "<1> Afficher la date (date)"
|
||||
echo "<2> Afficher le nombre de personnes connéctées (who)"
|
||||
echo "<3> Afficher la liste des processus (ps)"
|
||||
echo "<9> Quitter"
|
||||
echo ""
|
||||
read val
|
||||
done
|
@ -0,0 +1,70 @@
|
||||
# TP 7 - Scripts
|
||||
|
||||
Pas de compte rendu dédié aux TP sur les scripts shell. Vos programmes
|
||||
feront foi !
|
||||
|
||||
<note tip>
|
||||
|
||||
Quelques règles simples pour éviter les erreurs de syntaxe :
|
||||
|
||||
* jamais d'espace autour d'une affectation (exemple : `a=3`)
|
||||
* des espaces partout ailleurs (exemple `if` `test` `$a`
|
||||
`=` `4;` `then...` ou `if` `[` `$a` `=`
|
||||
`4` `]` `;` `then...`
|
||||
|
||||
Pour observer les commandes exécutées, passez en mode trace en plaçant
|
||||
la commande `set -x` en début de programme.
|
||||
|
||||
</note>
|
||||
|
||||
#### 6 - La commande menu1
|
||||
|
||||
En utilisant la structure `while`, écrire un script qui :
|
||||
|
||||
Tant que l'utilisateur n'a pas tapé 9
|
||||
|
||||
* affiche un menu
|
||||
* demande à l'utilisateur de saisir une option du menu
|
||||
* affiche à l'utilisateur le résultat de sa commande
|
||||
|
||||
Exemple de ce qui doit s'afficher à l'écran :
|
||||
|
||||
```
|
||||
Menu général
|
||||
***************************************
|
||||
|
||||
<1> Afficher la date (date)
|
||||
|
||||
<2> Afficher le nombre de personnes connectées (who)
|
||||
|
||||
<3> Afficher la liste des processus (ps)
|
||||
|
||||
<9> Quitter
|
||||
```
|
||||
|
||||
#### 7 - La commande evaluateur
|
||||
|
||||
En utilisant la structure *until...do...done*, écrire un script qui :
|
||||
|
||||
* demande à un utilisateur de saisir une commande
|
||||
* exécute la commande ou affiche un message d'erreur si la commande ne s'est pas correctement exécutée.
|
||||
* répète cette opération tant que l'utilisateur le désire
|
||||
|
||||
Indication : si vous disposez d'une variable contenant une ligne de
|
||||
commandes il est possible de l'exécuter via la fonction interne au shell
|
||||
`eval`. Le code de retour retourné par eval est le code de retour
|
||||
retourné par la commande. Exemple : `c="ls -l | wc -l"` `eval $c`
|
||||
|
||||
Voici un exemple de ce que votre programme doit afficher à l'écran :
|
||||
|
||||
```
|
||||
Saisissez une commande, commande <q> pour quitter.
|
||||
> date
|
||||
mar sep 30 21:20:45 CEST 2008
|
||||
Saisissez une commande, commande <q> pour quitter.
|
||||
> cd /toto
|
||||
bash: cd: /toto: Aucun fichier ou répertoire de ce type
|
||||
cette commande a généré une erreur !!!!
|
||||
Saisissez une commande, commande <q> pour quitter.
|
||||
> q
|
||||
```
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
while [ $# -ne 0 ]; do
|
||||
case "$1" in
|
||||
'-v')
|
||||
echo 'Mode verbose'
|
||||
shift
|
||||
;;
|
||||
'-m'|'-M')
|
||||
machine="$2"
|
||||
shift 2 || sortie "Manque valeur"
|
||||
;;
|
||||
*) sortie "Argument $1 inconnu"
|
||||
;;
|
||||
esac
|
||||
done
|
@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
L=
|
||||
while [ $# -ne 0 ]; do
|
||||
case "$1" in
|
||||
'-lang')
|
||||
if [ "$2" = "fr" ]; then
|
||||
date +%d/%m/%y
|
||||
elif [ "$2" = "en" ] ; then
|
||||
date +%m/%d/%y
|
||||
|
||||
date ++dd/mm/yy
|
||||
shift
|
||||
;;
|
||||
'-fullYear')
|
||||
date +Y
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Argument $1 inconnu"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
Loading…
Reference in new issue