This commit is contained in:
Alexis WAMSTER 2023-10-23 13:07:05 +02:00
parent 4f9ed8483e
commit 667dae6f1a
26 changed files with 469 additions and 45 deletions

BIN
Anglish/16102023.docx Executable file

Binary file not shown.

View File

@ -2,23 +2,29 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.Polygon; import java.awt.Polygon;
import java.lang.Math;
public class Q5Main{ public class Q5Main{
public static void main(String[] args) { public static void main(String[] args) {
int l = 1000;
int m = 40;
int detail = Integer.parseInt(args[0]);
JFrame fenetre = new JFrame("Q1 Galerie"); JFrame fenetre = new JFrame("Q1 Galerie");
fenetre.setSize(300, 200); fenetre.setSize(l+2*m, l+2*m);
fenetre.setLocation(700, 300); fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Polygon etoile = new Polygon(); Polygon etoile = new Polygon();
etoile.addPoint(50,50); Q5Polygon dessinEtoile = new Q5Polygon(etoile);
etoile.addPoint(300,140); Q5Recursivite modele = new Q5Recursivite(etoile, fenetre);
etoile.addPoint(230,80); fenetre.add(dessinEtoile);
etoile.addPoint(10,330);
fenetre.setVisible(true); fenetre.setVisible(true);
Q5Polygon dessinEtoile = new Q5Polygon(etoile); Q5Point g = new Q5Point(m+l/2, m);
fenetre.add(dessinEtoile); Q5Point c = new Q5Point(m+l-((int)(l*Math.sqrt(3))/2), m+(3*l)/4);
Q5Point a = new Q5Point(2*m+((int)(l*Math.sqrt(3))/2), m+(3*l)/4);
modele.nextStep(detail, a,c,g);
modele.nextStep(detail, c,g,a);
modele.nextStep(detail, g,a,c);
} }
} }

Binary file not shown.

View File

@ -0,0 +1,33 @@
public class Q5Point{
public int x;
public int y;
public Q5Point(int x, int y) {
this.x = x;
this.y = y;
}
public Q5Point() {
this.x = 0;
this.y = 0;
}
public static Q5Point tiers(Q5Point a, Q5Point b){
Q5Point resultat = new Q5Point();
resultat.x = (int) a.x + (b.x - a.x)/3;
resultat.y = (int) a.y + (b.y - a.y)/3;
return resultat;
}
public static Q5Point millieu(Q5Point a, Q5Point b){
Q5Point resultat = new Q5Point();
resultat.x = (int) a.x + (b.x - a.x)/2;
resultat.y = (int) a.y + (b.y - a.y)/2;
return resultat;
}
public static Q5Point pointe(Q5Point a, Q5Point b, Q5Point p){
Q5Point i = Q5Point.millieu(a,b);
Q5Point resultat = new Q5Point();
resultat.x = (int) i.x - (p.x - i.x)/3;
resultat.y = (int) i.y - (p.y - i.y)/3;
return resultat;
}
}

View File

@ -11,6 +11,6 @@ public class Q5Polygon extends JComponent {
@Override @Override
protected void paintComponent(Graphics pinceau) { protected void paintComponent(Graphics pinceau) {
pinceau.setColor(Color.BLUE); pinceau.setColor(Color.BLUE);
pinceau.fillPolygon(this.etoile); pinceau.drawPolygon(this.etoile);
} }
} }

Binary file not shown.

View File

@ -0,0 +1,32 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Polygon;
public class Q5Recursivite{
public Polygon etoile;
public JFrame fenetre;
public Q5Recursivite(Polygon etoile, JFrame fenetre) {
this.etoile = etoile;
this.fenetre = fenetre;
}
public void nextStep(int i, Q5Point c, Q5Point g, Q5Point a){
if (i<=0){
this.etoile.addPoint(c.x,c.y);
this.fenetre.repaint();
}
else{
Q5Point b = Q5Point.tiers(c,a);
Q5Point d = Q5Point.tiers(c,g);
Q5Point e = Q5Point.pointe(c,g,a);
Q5Point f = Q5Point.tiers(g,c);
Q5Point h = Q5Point.tiers(g,a);
this.nextStep(i-1, c, d, b);
this.nextStep(i-1, d, e, f);
this.nextStep(i-1, e, f, d);
this.nextStep(i-1, f, g, h);
}
}
}

Binary file not shown.

View File

@ -0,0 +1,34 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Action implements MouseListener{
public java.util.List<Parallelogramme> listeParallelogramme;
public Action(java.util.List<Parallelogramme> listeParallelogramme){
this.listeParallelogramme = listeParallelogramme;
}
@Override
public void mouseClicked(MouseEvent e){
for (Parallelogramme parallelogramme : this.listeParallelogramme){
if (parallelogramme.forme.contains(e.getPoint())){
System.out.println("clic");
}
}
}
@Override
public void mouseEntered(MouseEvent e){
}
@Override
public void mouseExited(MouseEvent e){
}
@Override
public void mousePressed(MouseEvent e){
}
@Override
public void mouseReleased(MouseEvent e){
}
}

Binary file not shown.

View File

@ -0,0 +1,27 @@
import javax.swing.JComponent;
import java.awt.*;
import java.util.*;
public class Dessin extends JComponent {
public java.util.List<Parallelogramme> listeParallelogramme;
public Dessin(java.util.List<Parallelogramme> listeParallelogramme){
this.listeParallelogramme = listeParallelogramme;
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
if (this.isOpaque()) {
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
for (Parallelogramme parallelogramme : this.listeParallelogramme){
secondPinceau.setColor(parallelogramme.couleur);
secondPinceau.fillPolygon(parallelogramme.forme);
secondPinceau.setColor(Color.BLACK);
secondPinceau.drawPolygon(parallelogramme.forme);
}
}
}

Binary file not shown.

View File

@ -0,0 +1,28 @@
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class Main{
public static void main(String[] args){
JFrame fenetre = new JFrame();
fenetre.setSize(700, 300);
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
java.util.List<Parallelogramme> listeParallelogramme = new ArrayList<>();
int i;
Parallelogramme suivant = new Parallelogramme();
for (i=0; i<10; i++){
listeParallelogramme.add(suivant);
suivant = new Parallelogramme(suivant);
}
Action action = new Action(listeParallelogramme);
fenetre.addMouseListener(action);
Dessin lesDessins = new Dessin(listeParallelogramme);
fenetre.add(lesDessins);
fenetre.setVisible(true);
}
}

Binary file not shown.

View File

@ -0,0 +1,28 @@
import java.awt.*;
import java.util.*;
public class Parallelogramme{
public static int hauteur=100;
public static int largeur=50;
public static int marge=5;
public static int inclinaison=40;
public static Random aleatoire = new Random();
public Polygon forme;
public Color couleur;
public Parallelogramme(){
this(0,Parallelogramme.marge);
}
public Parallelogramme(Parallelogramme ancien){
this(ancien.forme.xpoints[1],ancien.forme.ypoints[2]);
}
public Parallelogramme(int gauche, int haut){
this.forme = new Polygon();
this.couleur = new Color(Parallelogramme.aleatoire.nextInt(255), Parallelogramme.aleatoire.nextInt(255), Parallelogramme.aleatoire.nextInt(255));
this.forme.addPoint(gauche+Parallelogramme.marge, haut+Parallelogramme.hauteur);
this.forme.addPoint(gauche+Parallelogramme.marge+Parallelogramme.largeur, haut+Parallelogramme.hauteur);
this.forme.addPoint(gauche+Parallelogramme.marge+Parallelogramme.largeur+Parallelogramme.inclinaison, haut);
this.forme.addPoint(gauche+Parallelogramme.marge+Parallelogramme.inclinaison, haut);
}
}

View File

@ -0,0 +1,16 @@
1.
employee
2.
employee
3.
gerer la bibliotheque (gerer les adherants, gerer les oeuvres)
gerer les contentieux
s'authentifier
lancer des poursuites judiciaires
4.
5.

Binary file not shown.

20
SCR/TP05/ex1.1.c Normal file
View File

@ -0,0 +1,20 @@
#define _GNU_SOURCE
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
int main(int argc, char *argv[])
{
int t[2];
int size;
assert(pipe(t) == 0);
size = fcntl(t[0],F_GETPIPE_SZ);
printf("size = %d\n",size);
return 0;
}

24
SCR/TP05/ex1.2.c Normal file
View File

@ -0,0 +1,24 @@
#define _GNU_SOURCE
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
// ls -i -l /tmp >> log
//
int main(int argc, char *argv[])
{
int redirection = open("./log",O_WRONLY | O_APPEND | O_CREAT , 0644);
assert(redirection >= 0);
// dup2 ferme 1, et duplique redirection
dup2(redirection,1);
close(redirection);
execlp("ls","ls","-i","-l","/tmp",NULL);
assert(0);
return 0;
}

76
SCR/TP05/prime.c Normal file
View File

@ -0,0 +1,76 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void filter(int p)
{
while(1){
int n;
ssize_t nb_read = read(0,&n,sizeof(int));
if (nb_read <= 0)
break;
if ((n%p)!=0)
write(1,&n,sizeof(int));
}
}
void seq(int n)
{
for (int i = 2; i <=n; i++)
write(1,&i,sizeof(int));
}
void chef(void)
{
while(1){
int p;
pid_t f;
int t[2];
ssize_t nb_read = read(0,&p,sizeof(int));
if (nb_read <= 0)
break;
printf("new prime %d\n",p);
pipe(t);
f = fork();
if (f == 0){
close(t[0]);
dup2(t[1],1);
close(t[1]);
filter(p);
exit(0);
}
close(t[1]);
dup2(t[0],0);
close(t[0]);
}
}
int main(int argc, char *argv[])
{
pid_t p;
struct sigaction sa = {0};
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_NOCLDWAIT;
sigaction(SIGCHLD,&sa,NULL);
int t[2];
int N = strtol(argv[1],NULL,0);
pipe(t);
p = fork();
if (p == 0){
close(t[0]);
dup2(t[1],1);
close(t[1]);
seq(N);
exit(0);
}
close(t[1]);
dup2(t[0],0);
close(t[0]);
chef();
return 0;
}

View File

@ -2,62 +2,102 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
#include <assert.h> #include <assert.h>
#include <time.h>
#define ELIMINE -1
typedef struct duel{ typedef struct duel{
int participant1; int* liste;
int participant2; int debut;
int tailleGroupe;
} duel; } duel;
void *tournois(void *thread_id) { void affichage(int* liste, int capacite){
int id = *((int *) thread_id); int i;
printf("Hello from thread %d\n", id); for(i=0; i<capacite; i++){
if (liste[i] != ELIMINE){
printf("%d ",liste[i]);
}
}
printf("\n");
}
int* creerListe(int taille){
int* liste = (int*) malloc(taille*sizeof(int));
int i;
for (i=0; i<taille; i++){
liste[i] = (rand()%100);
}
return liste;
}
int plusPetit(int* liste, int debut, int nb){
int plusGrand = -1;
int i;
int participant1 =- 1;
int indiceParticipant1;
for (i=0; i<nb; i++){
if (liste[debut+i] != ELIMINE){
if (participant1 == -1){
participant1 = liste[debut+i];
indiceParticipant1 = i;
}
else{
if (liste[debut+i] > participant1){
return debut + indiceParticipant1;
}
else{
return debut + i;
}
}
}
}
return -1;
}
void *tournois(void *argument) {
duel duo = *((duel*) argument);
int i;
int perdant = plusPetit(duo.liste, duo.debut, duo.tailleGroupe);
duo.liste[perdant] = -1;
return NULL; return NULL;
} }
int puissance2(int n){ int puissance2(int n){
for (int p=1; p<n; p*=2){} int p;
for (p=1; p<n; p*=2){}
if (p==n){ if (p==n){
return 1; return 1;
} }
return 0; return 0;
} }
duel* Formercouple(participant*, nbParticipant){
int i;
int c;
duel couple[nbParticipant/2];
for (i=0; i<nbParticipant; i++){
if (participant[])
}
}
int main(int argc, char** argv[]) { int main(int argc, char** argv[]) {
int participant[argc]; int nbParticipant = argc-1;
int nbDuel = argc/2; int nbDuel = nbParticipant/2;
int nbParticipant = argc; int* listeParticipant;
assert(puissance2(nbParticipant)==1);
srand(time(NULL));
listeParticipant = creerListe(nbParticipant);
affichage(listeParticipant, nbParticipant);
while (nbDuel>=1){
pthread_t threads[nbDuel]; pthread_t threads[nbDuel];
duel argument[nbDuel];
assert(puissance2(argc)==1); int i;
for (i=0; i<nbDuel; i++){
for (int i = 0; i < argc; i++){ argument[i].liste = listeParticipant;
participant->nom = argv[i]; argument[i].debut = i*(nbParticipant/nbDuel);
participant->id = i; argument[i].tailleGroupe = nbParticipant/nbDuel;
} }
while (nbDuel > 1){ for (i=0; i<nbDuel; i++){
for (int i = 0; i < nbDuel; i++){ assert( pthread_create(&threads[i], NULL, tournois, &argument[i]) == 0);
duel[nbDuel] tabDuel;
participant participant2;
for (int x=0, y=0, )
participant duel[] = {participant[i], participant[i+1]};
assert( pthread_create(&threads[i], NULL, tournois, &participant[i]) == 0);
} }
for (int i = 0; i < NUM_THREADS; i++){ for (i=0; i<nbDuel; i++){
assert( pthread_join(threads[i], NULL) == 0); assert( pthread_join(threads[i], NULL) == 0);
} }
affichage(listeParticipant, nbParticipant);
nbParticipant /= 2;
nbDuel /= 2; nbDuel /= 2;
} }

60
SCR/TP06/ex3.c Normal file
View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>
#include <time.h>
typedef struct structure{
int debut;
int fin;
int saut;
int* resultat;
} structure;
static inline double tstamp(void)
{
struct timespec tv;
clock_gettime(CLOCK_REALTIME, &tv);
return tv.tv_sec + tv.tv_nsec * 1.0e-9;
}
void *somme(void *argument) {
structure data = *((structure *) argument);
for (; data.debut<=data.fin; data.debut += data.saut){
*data.resultat += data.debut;
}
return NULL;
}
int main(int argc, char* argv[]) {
assert(argc-1 == 2);
int limite = (int) strtol(argv[1], NULL, 0);
int nbThread = (int) strtol(argv[2], NULL, 0);
int sommeFinal = 0;
double startTime, endTime;
int resultatThread[nbThread];
pthread_t threads[nbThread];
structure argument[nbThread];
for (int i = 0; i < nbThread; i++){
argument[i].debut = i;
argument[i].fin = limite;
argument[i].saut = nbThread;
resultatThread[i] = 0;
argument[i].resultat = &resultatThread[i];
}
startTime = tstamp();
for (int i = 0; i < nbThread; i++){
assert( pthread_create(&threads[i], NULL, somme, &argument[i]) == 0);
}
for (int i = 0; i < nbThread; i++){
assert( pthread_join(threads[i], NULL) == 0);
sommeFinal += *argument[i].resultat;
}
endTime = tstamp();
printf("somme : %d\ntemps : %lf\n", sommeFinal, endTime-startTime);
return EXIT_SUCCESS;
}

BIN
SCR/TP06/exe Executable file

Binary file not shown.

0
test Normal file
View File