parent
abe3449c16
commit
8464e5b181
Binary file not shown.
@ -0,0 +1,10 @@
|
|||||||
|
#include "tp8f.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
char tab[27][15];
|
||||||
|
|
||||||
|
charger(tab[15]);
|
||||||
|
afficher(tab[15]);
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,134 @@
|
|||||||
|
#include "tp8f.h"
|
||||||
|
|
||||||
|
int moyenne(void)
|
||||||
|
{
|
||||||
|
float note, moy=0, nb=0;
|
||||||
|
char in[27], nom[27], mat[27];
|
||||||
|
|
||||||
|
FILE *flot;
|
||||||
|
flot = fopen("fichierNotes.txt", "r");
|
||||||
|
if (flot == NULL)
|
||||||
|
{
|
||||||
|
printf("Problème lors de l'ouverture du fichier.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Tapez le code de la matière à traiter : ");
|
||||||
|
scanf("%s", in);
|
||||||
|
/*in[strlen(in)-1] = '\0';*/
|
||||||
|
printf("Notes données en %s :\nETUDIANTS\tNOTES\n", in);
|
||||||
|
|
||||||
|
fscanf(flot, "%s%s%f", nom, mat, ¬e);
|
||||||
|
while(!feof(flot))
|
||||||
|
{
|
||||||
|
if (strcmp(in, mat) == 0)
|
||||||
|
{
|
||||||
|
nb = nb+1;
|
||||||
|
moy = moy+note;
|
||||||
|
printf("%s\t\t%.2f\n", nom, note);
|
||||||
|
}
|
||||||
|
fscanf(flot, "%s%s%f", nom, mat, ¬e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nb == 0)
|
||||||
|
printf("aucune note pour cette matière\n");
|
||||||
|
else
|
||||||
|
printf("\nMOYENNE :\t%.2f\n", moy/nb);
|
||||||
|
|
||||||
|
fclose(flot);
|
||||||
|
return moy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void initialiser(char mot[], int n)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
*(mot +i) = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
void placer(char mot1[], char c, char mot2[])
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strlen(mot1); ++i)
|
||||||
|
if (*(mot1+i) == c)
|
||||||
|
*(mot2+i) = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jeuPendu(void)
|
||||||
|
{
|
||||||
|
int etapes = 4;
|
||||||
|
char mot1[27], mot2[27], mot3[27], c;
|
||||||
|
|
||||||
|
printf("Joueur 1, proposez un mot à deviner : ");
|
||||||
|
system("stty -echo");
|
||||||
|
scanf("%s%*c", mot1);
|
||||||
|
system("stty echo");
|
||||||
|
initialiser(mot2, strlen(mot1));
|
||||||
|
printf("\nMot de %d lettres à trouver en %d étapes\n%s\n\n", strlen(mot1), etapes, mot2);
|
||||||
|
|
||||||
|
for (int i = 0; i < etapes; ++i)
|
||||||
|
{
|
||||||
|
printf("proposez une lettre : ");
|
||||||
|
scanf("%c%*c", &c);
|
||||||
|
placer(mot1, c, mot2);
|
||||||
|
printf("%s\navez vous reconnu le mot (o/n) ?", mot2);
|
||||||
|
scanf("%c%*c", &c);
|
||||||
|
|
||||||
|
if (c == 'o')
|
||||||
|
{
|
||||||
|
printf("\nmot ? ");
|
||||||
|
scanf("%s%*c", mot3);
|
||||||
|
if (strcmp(mot1, mot3) == 0)
|
||||||
|
{
|
||||||
|
printf("Bravo vous avez gagné !!!\nmot trouvé en %d étapes\n", i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("Désolé ...\n");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
printf("\nmot ? ");
|
||||||
|
scanf("%s%*c", mot3);
|
||||||
|
if (strcmp(mot1, mot3) == 0)
|
||||||
|
{
|
||||||
|
printf("Bravo vous avez gagné !!!\nmot trouvé en %d étapes\n", etapes+1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("Désolé ... Vous avez perdu.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void charger(char *tab[2])
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
char mot[27];
|
||||||
|
|
||||||
|
FILE *flot;
|
||||||
|
flot = fopen("fichierMots.txt", "r");
|
||||||
|
if (flot == NULL)
|
||||||
|
{
|
||||||
|
printf("Problème lors de l'ouverture du fichier.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fscanf(flot, "%s", mot);
|
||||||
|
while(!feof(flot))
|
||||||
|
{
|
||||||
|
for (int j = 0; j < strlen(mot); ++j)
|
||||||
|
tab[j][i] = mot[j];
|
||||||
|
i = i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficher(char *tab[2])
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 15; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 27; ++j)
|
||||||
|
{
|
||||||
|
printf("%c", tab[i][j]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int moyenne(void);
|
||||||
|
|
||||||
|
void initialiser(char mot[], int n);
|
||||||
|
void placer(char mot1[], char c, char mot2[]);
|
||||||
|
void jeuPendu(void);
|
||||||
|
|
||||||
|
void charger(char *tab[2]);
|
||||||
|
void afficher(char *tab[2]);
|
@ -0,0 +1,72 @@
|
|||||||
|
\! clear;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Medecin, Patient, Consultation, Medicament, Laboratoire ,Posologie ,Fournir;
|
||||||
|
|
||||||
|
CREATE TABLE Medecin (
|
||||||
|
id_medecin numeric PRIMARY KEY,
|
||||||
|
nom varchar NOT NULL,
|
||||||
|
prenom varchar NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Patient (
|
||||||
|
num_pat numeric PRIMARY KEY,
|
||||||
|
nom varchar NOT NULL,
|
||||||
|
prenom varchar NOT NULL,
|
||||||
|
age numeric CHECK (age is NULL OR age > 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Consultation (
|
||||||
|
num_cons varchar PRIMARY KEY CHECK (num_cons LIKE 'C%'),
|
||||||
|
date date,
|
||||||
|
heure time,
|
||||||
|
id_medecin numeric,
|
||||||
|
num_pat numeric,
|
||||||
|
FOREIGN KEY (id_medecin) REFERENCES Medecin,
|
||||||
|
FOREIGN KEY (num_pat) REFERENCES Patient
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE Medicament (
|
||||||
|
num_med numeric PRIMARY KEY,
|
||||||
|
nom varchar NOT NULL UNIQUE,
|
||||||
|
prix numeric CHECK (prix > 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Posologie (
|
||||||
|
matin numeric CHECK (matin is NULL or matin > 0),
|
||||||
|
midi numeric CHECK (midi is NULL or midi > 0),
|
||||||
|
soir numeric CHECK (soir is NULL or soir > 0),
|
||||||
|
num_cons varchar,
|
||||||
|
num_med numeric,
|
||||||
|
PRIMARY KEY(num_cons, num_med),
|
||||||
|
FOREIGN KEY (num_med) REFERENCES Medicament,
|
||||||
|
FOREIGN KEY (num_cons) REFERENCES Consultation
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Laboratoire (
|
||||||
|
num_lab numeric PRIMARY KEY,
|
||||||
|
nom varchar NOT NULL UNIQUE,
|
||||||
|
rue numeric,
|
||||||
|
code_postal numeric(5) CHECK ((code_postal IS NOT NULL) = (pays = 'France')), /*<=> (code_post IS NOT NULL AND pays IS 'France') OR (code_postal IS NULL AND Pays IS NOT 'France')*/
|
||||||
|
ville varchar,
|
||||||
|
pays varchar DEFAULT ('France')
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Fournir (
|
||||||
|
num_lab numeric,
|
||||||
|
num_med numeric,
|
||||||
|
PRIMARY KEY (num_lab, num_med),
|
||||||
|
FOREIGN KEY (num_lab) REFERENCES Laboratoire,
|
||||||
|
FOREIGN KEY (num_med) REFERENCES Medicament
|
||||||
|
);
|
||||||
|
|
||||||
|
SELECT * FROM Medecin ORDER BY nom, prenom ASC;
|
||||||
|
|
||||||
|
SELECT * FROM Patient WHERE age < 18 ORDER BY nom, prenom DESC;
|
||||||
|
|
||||||
|
SELECT Consultation.* FROM Consultation JOIN Posologie ON Consultation.num_cons = Posologie.num_cons WHERE soir IS NOT NULL;
|
||||||
|
|
||||||
|
SELECT Consultation.* FROM Consultation JOIN Posologie ON Consultation.num_cons = Posologie.num_cons WHERE matin > (midi + soir);
|
||||||
|
|
||||||
|
SELECT Laboratoire FROM
|
||||||
|
|
@ -0,0 +1,187 @@
|
|||||||
|
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', 'T01');
|
||||||
|
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 ('09/09/2021', 6, 'D0009', 'P0004');
|
||||||
|
INSERT INTO REPAS VALUES ('10/09/2021', 1, 'D0009', 'P0006');
|
||||||
|
INSERT INTO REPAS VALUES ('11/09/2021', 2, 'D0009', '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'; */
|
||||||
|
|
||||||
|
|
||||||
|
\d
|
Loading…
Reference in new issue