27 Avril
This commit is contained in:
parent
bfcbd64735
commit
93c00d1ed0
BIN
ControleMachine2/Adrian_Pourchot.tar
Normal file
BIN
ControleMachine2/Adrian_Pourchot.tar
Normal file
Binary file not shown.
39
ControleMachine2/Exercice1.c
Normal file
39
ControleMachine2/Exercice1.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char* suppNonLettres(char* s){
|
||||
int i;
|
||||
for (i=0;i<255;i++){
|
||||
if (s[i]<'A'){
|
||||
s[i]='\a';
|
||||
} if (s[i]>'Z'&& s[i]<'a'){
|
||||
s[i]='\a';
|
||||
} if (s[i]>'z'){
|
||||
s[i]='\a';
|
||||
}
|
||||
} return(s);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char* s=calloc(256,sizeof(char));
|
||||
char c=-128;
|
||||
int i;
|
||||
int t;
|
||||
|
||||
s[0]=c;
|
||||
for (i=0;i<255;i++){
|
||||
c++;
|
||||
s[i]=c;
|
||||
} suppNonLettres(s);
|
||||
printf("%s\n",s);
|
||||
t=strlen(s);
|
||||
for (i=t;i>=0;i--){
|
||||
if (s[i]=='\a'){
|
||||
t--;
|
||||
}
|
||||
}
|
||||
printf("Cette chaine est de taille %d.\n",t);
|
||||
return 0;
|
||||
}
|
65
ControleMachine2/Exercice2.c
Normal file
65
ControleMachine2/Exercice2.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void afficheTab(float tab[],int taille){
|
||||
if(taille==0){
|
||||
return;
|
||||
} afficheTab(tab, taille-1);
|
||||
printf("%.2f ",tab[taille-1]);
|
||||
}
|
||||
|
||||
int indicePlusPetit(float tab[10]){
|
||||
int taille=10;
|
||||
int i;
|
||||
int indice=0;
|
||||
int min=tab[0];
|
||||
|
||||
for(i=1;i<taille;i++){
|
||||
if (tab[i]<min){
|
||||
min=tab[i];
|
||||
indice=i;
|
||||
}
|
||||
} return indice;
|
||||
}
|
||||
|
||||
int indicePlusPetitApresI(float tab[10],int indice){
|
||||
int taille=10;
|
||||
int i;
|
||||
int indice2=indice;
|
||||
int min=tab[indice];
|
||||
|
||||
for(i=indice;i<taille;i++){
|
||||
if (tab[i]<min){
|
||||
min=tab[i];
|
||||
indice2=i;
|
||||
}
|
||||
} return indice2;
|
||||
}
|
||||
|
||||
void echange2cases(float tab[10],int indice1,int indice2){
|
||||
float temp;
|
||||
temp=tab[indice1];
|
||||
tab[indice1]=tab[indice2];
|
||||
tab[indice2]=temp;
|
||||
}
|
||||
|
||||
void triParSelection(float tab[10]){
|
||||
int taille=10;
|
||||
int i;
|
||||
echange2cases(tab,indicePlusPetit(tab),0);
|
||||
for (i=1;i<taille;i++){
|
||||
echange2cases(tab,indicePlusPetitApresI(tab,i),i);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
float tab[10]={43.8,17.0,212.12,251.7,891.18,78.0,182.0,526.19,98.1,290.0};
|
||||
|
||||
afficheTab(tab,10);
|
||||
putchar('\n');
|
||||
triParSelection(tab);
|
||||
afficheTab(tab,10);
|
||||
putchar('\n');
|
||||
return 0;
|
||||
}
|
52
ControleMachine2/Exercice4.c
Normal file
52
ControleMachine2/Exercice4.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct maillon {
|
||||
int valeur;
|
||||
struct maillon* suiv;
|
||||
};
|
||||
|
||||
typedef struct maillon maillon;
|
||||
|
||||
maillon* ajouteDebut(maillon *chaine, int entier){
|
||||
maillon *nouveauMaillon=malloc(sizeof(maillon));
|
||||
nouveauMaillon->valeur=entier;
|
||||
nouveauMaillon->suiv=chaine;
|
||||
return nouveauMaillon;
|
||||
}
|
||||
|
||||
void afficheListe(maillon *chaine){
|
||||
maillon *affichage=malloc(sizeof(maillon));
|
||||
affichage=chaine;
|
||||
while(affichage->suiv!=NULL){
|
||||
printf("%hu ",affichage->valeur);
|
||||
affichage=affichage->suiv;
|
||||
} printf("\n\n");
|
||||
free(affichage);
|
||||
}
|
||||
|
||||
maillon* fusionImperative(maillon *chaine1, maillon *chaine2){
|
||||
int i;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
maillon *liste1=malloc(sizeof(maillon));
|
||||
maillon *liste2=malloc(sizeof(maillon));
|
||||
int i;
|
||||
|
||||
for(i=30;i>=0;i--){
|
||||
if (i%2==1){
|
||||
if (i<=24 && i%9==0){
|
||||
liste1=ajouteDebut(liste1,i);
|
||||
} else{
|
||||
liste2=ajouteDebut (liste2,i);
|
||||
}
|
||||
}else{
|
||||
liste1=ajouteDebut (liste1,i);
|
||||
}
|
||||
} afficheListe(liste1);
|
||||
afficheListe(liste2);
|
||||
return 0;
|
||||
}
|
BIN
ControleMachineJava/Exercice1/MainExo1.class
Normal file
BIN
ControleMachineJava/Exercice1/MainExo1.class
Normal file
Binary file not shown.
35
ControleMachineJava/Exercice1/MainExo1.java
Normal file
35
ControleMachineJava/Exercice1/MainExo1.java
Normal file
@ -0,0 +1,35 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class MainExo1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
for(int j=0; j<args.length; j++){
|
||||
if (args.length==0 || Integer.parseInt(args[j])<=0){
|
||||
System.out.println("Donner un entier strictement positif en argument.");
|
||||
}else{
|
||||
int x = Integer.parseInt(args[j]);
|
||||
int[] diviseur = new int[1];
|
||||
boolean estPremier = true;
|
||||
int indice=0;
|
||||
for (int i=2; i<x; i++){
|
||||
if(x % i == 0){
|
||||
estPremier = false;
|
||||
diviseur=Arrays.copyOf(diviseur,indice+1);
|
||||
diviseur[indice]=i;
|
||||
indice++;
|
||||
}
|
||||
} if (estPremier==true){
|
||||
System.out.println("L'entier "+x+" est premier.");
|
||||
}else{
|
||||
System.out.println("L'entier "+x+" n'est pas premier.");
|
||||
System.out.println("Les diviseurs de "+x+" sont 1 et lui-meme ainsi que:");
|
||||
for (int i=0; i<diviseur.length; i++) {
|
||||
System.out.println(diviseur[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
ControleMachineJava/Exercice2/Entiexte.java
Normal file
13
ControleMachineJava/Exercice2/Entiexte.java
Normal file
@ -0,0 +1,13 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.lang.*;
|
||||
|
||||
public class Entiexte {
|
||||
private String entier;
|
||||
public Entiexte(String nombre) {
|
||||
this.entier=nombre;
|
||||
}
|
||||
|
||||
public Entiexte(int x) {
|
||||
this.entier=x;
|
||||
}
|
0
ControleMachineJava/Exercice2/MainExo2.java
Normal file
0
ControleMachineJava/Exercice2/MainExo2.java
Normal file
BIN
ControleMachineJava/Exercice3/MainExo3.class
Normal file
BIN
ControleMachineJava/Exercice3/MainExo3.class
Normal file
Binary file not shown.
52
ControleMachineJava/Exercice3/MainExo3.java
Normal file
52
ControleMachineJava/Exercice3/MainExo3.java
Normal file
@ -0,0 +1,52 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class MainExo3 {
|
||||
|
||||
public static ObjetAleatoire genererOA(){
|
||||
ObjetAleatoire p;
|
||||
Random r = new Random();
|
||||
if((r.nextInt()%2)==0){
|
||||
p = new Piece();
|
||||
}else{
|
||||
p = new PiecePipee();
|
||||
} return p;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ObjetAleatoire o;
|
||||
int f;
|
||||
int nbrf=0;
|
||||
int nbrp=0;
|
||||
int truquer=0;
|
||||
o=genererOA();
|
||||
o.lancer();
|
||||
f=o.lire();
|
||||
if(f==1||f==-1){
|
||||
System.out.println("Vous avez fait face.");
|
||||
}else{
|
||||
System.out.println("Vous avez fait pile.");
|
||||
} for(int j=0; j<10 ;j++){
|
||||
nbrf=0;
|
||||
nbrp=0;
|
||||
for(int i=0;i<100;i++){
|
||||
o.lancer();
|
||||
f=o.lire();
|
||||
if(f==1||f==-1){
|
||||
nbrf++;
|
||||
}else{
|
||||
nbrp++;
|
||||
}
|
||||
} if (nbrp<=nbrf){
|
||||
truquer++;
|
||||
}else{
|
||||
truquer--;
|
||||
}
|
||||
} if (truquer>=-7){
|
||||
System.out.println("Piece non truquer");
|
||||
}else{
|
||||
System.out.println("Piece truquer");
|
||||
}
|
||||
}
|
||||
}
|
BIN
ControleMachineJava/Exercice3/ObjetAleatoire.class
Normal file
BIN
ControleMachineJava/Exercice3/ObjetAleatoire.class
Normal file
Binary file not shown.
4
ControleMachineJava/Exercice3/ObjetAleatoire.java
Normal file
4
ControleMachineJava/Exercice3/ObjetAleatoire.java
Normal file
@ -0,0 +1,4 @@
|
||||
public interface ObjetAleatoire{
|
||||
void lancer();
|
||||
int lire();
|
||||
}
|
BIN
ControleMachineJava/Exercice3/Piece.class
Normal file
BIN
ControleMachineJava/Exercice3/Piece.class
Normal file
Binary file not shown.
21
ControleMachineJava/Exercice3/Piece.java
Normal file
21
ControleMachineJava/Exercice3/Piece.java
Normal file
@ -0,0 +1,21 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Piece implements ObjetAleatoire {
|
||||
|
||||
private int faceVisible; // 0 = pile; 1 = face.
|
||||
|
||||
public Piece(){
|
||||
this.faceVisible=faceVisible;
|
||||
}
|
||||
|
||||
public void lancer(){
|
||||
Random r = new Random();
|
||||
this.faceVisible=(r.nextInt()%2);
|
||||
}
|
||||
|
||||
public int lire(){
|
||||
return faceVisible;
|
||||
}
|
||||
}
|
BIN
ControleMachineJava/Exercice3/PiecePipee.class
Normal file
BIN
ControleMachineJava/Exercice3/PiecePipee.class
Normal file
Binary file not shown.
25
ControleMachineJava/Exercice3/PiecePipee.java
Normal file
25
ControleMachineJava/Exercice3/PiecePipee.java
Normal file
@ -0,0 +1,25 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class PiecePipee implements ObjetAleatoire {
|
||||
|
||||
private int faceVisible; // 0 = pile; 1 = face.
|
||||
|
||||
public PiecePipee(){
|
||||
this.faceVisible=faceVisible;
|
||||
}
|
||||
|
||||
public void lancer(){
|
||||
Random r = new Random();
|
||||
if(r.nextInt()%10<7&&r.nextInt()%10>-7){
|
||||
this.faceVisible=0;
|
||||
}else{
|
||||
this.faceVisible=1;
|
||||
}
|
||||
}
|
||||
|
||||
public int lire(){
|
||||
return faceVisible;
|
||||
}
|
||||
}
|
BIN
ControleMachineJava/reponses.tar
Normal file
BIN
ControleMachineJava/reponses.tar
Normal file
Binary file not shown.
BIN
DEV2.1/TP8:Tests/MonInt.class
Normal file
BIN
DEV2.1/TP8:Tests/MonInt.class
Normal file
Binary file not shown.
114
DEV2.1/TP8:Tests/MonInt.java
Normal file
114
DEV2.1/TP8:Tests/MonInt.java
Normal file
@ -0,0 +1,114 @@
|
||||
// notez le s apres Object. Permet entre autre de stipuler qu'un objet o n'est pas null avec la methode Objects.requireNonNull(o, "message d'erreur detaille");
|
||||
import java.util.Objects;
|
||||
|
||||
/*
|
||||
* Sorte de Int du pauvre a laquelle on ajoute un nom sous forme textuelle.
|
||||
*
|
||||
* Classe donnee a titre d'exemple pour illustrer les ingredients techniques de la prog defensive.
|
||||
* et les assertions java
|
||||
*/
|
||||
public class MonInt {
|
||||
|
||||
// un entier
|
||||
private int valeur ;
|
||||
// son nom sous forme textuelle
|
||||
private String nom ;
|
||||
|
||||
public MonInt(int n, String s){
|
||||
this.valeur = n;
|
||||
this.nom = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* division du pauvre.
|
||||
*
|
||||
*
|
||||
* @param c le diviseur par lequel on souhaite diviser this
|
||||
*/
|
||||
public void divise (MonInt c){
|
||||
Objects.requireNonNull(c, "la classe denominateur ne peut pas etre null");
|
||||
|
||||
int avant = this.valeur;
|
||||
|
||||
this.valeur = this.valeur / c.getValeur();
|
||||
this.nom = "(" + this.nom + " divise par " + c.getNom() +")";
|
||||
|
||||
assert(this.valeur*c.getValeur() == avant); // NB. un assert qui ne marche pas tout le temps.
|
||||
}
|
||||
|
||||
/**
|
||||
* Un getter superstitieux.
|
||||
* retourne une exception si la valeur vaut 13.
|
||||
*/
|
||||
public int getValeur(){
|
||||
if (valeur == 13) throw new IllegalStateException("Comme disait Sacha Guitry, je ne suis pas superstitieux mais on ne sait jamais.");
|
||||
return valeur;
|
||||
}
|
||||
|
||||
public String getNom(){
|
||||
return nom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String representant l'entier.
|
||||
*/
|
||||
public String toString(){
|
||||
return this.getValeur() + " " + this.getNom();
|
||||
}
|
||||
|
||||
/**
|
||||
* C'est un peu moche mais on peut pour simplifier mettre des tests manuels dans un main dans chaque classe.
|
||||
* C'est plutot mieux que de mettre des print dans chaque methode car vous etes plus sur de la stabilite de vos tests
|
||||
* (vous pouvez rejouer les tests plus tard).
|
||||
*
|
||||
* Idealement on utilise un outil dedie comme JUnit qui favorise au maximum cette automatisation.
|
||||
*
|
||||
* @param args pas de parametre en ligne de commande prevu.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MonInt c3 = new MonInt(3,"trois");
|
||||
MonInt c4 = new MonInt(4,"quatre");
|
||||
MonInt c9 = new MonInt(9,"neuf");
|
||||
MonInt c13 = new MonInt(13,"treize");
|
||||
System.out.println(c3.toString());
|
||||
System.out.println(c4.toString());
|
||||
System.out.println(c9.toString());
|
||||
|
||||
|
||||
c9.divise(c3);
|
||||
// 3
|
||||
System.out.println(c9.toString());
|
||||
|
||||
c3.divise(c4);
|
||||
// 0
|
||||
System.out.println(c3.toString());
|
||||
|
||||
// tester des exceptions pas pratique
|
||||
// Si on veut tester plusieurs exceptions
|
||||
// il faut attraper et verifier que c'est le bon type d'exception.
|
||||
// ici manuellement en regardant le message.
|
||||
try {
|
||||
System.out.println(c13.toString()); // toucher au nbre 13 avec getValeur()
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
try{
|
||||
c9.divise(c3); //division par 0
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
try{
|
||||
c9.divise(null); //division par null
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
BIN
DEV2.1/TP9:FluxOctets/Imag.class
Normal file
BIN
DEV2.1/TP9:FluxOctets/Imag.class
Normal file
Binary file not shown.
41
DEV2.1/TP9:FluxOctets/Imag.java
Normal file
41
DEV2.1/TP9:FluxOctets/Imag.java
Normal file
@ -0,0 +1,41 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Imag extends JComponent{
|
||||
private Image image;
|
||||
|
||||
public Imag(int width, int height, String path) throws IOException {
|
||||
image = readFromFile(width, height, path);
|
||||
setPreferredSize(new Dimension(width, height));
|
||||
}
|
||||
|
||||
private Image readFromFile(int width, int height, String path) throws IOException {
|
||||
FileInputStream input = new FileInputStream(path);
|
||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
|
||||
for (int i = 0; i < height; i++){
|
||||
for (int j = 0; j < width; j++){
|
||||
int r = input.read();
|
||||
int g = input.read();
|
||||
int b = input.read();
|
||||
int rgb = (r << 16 | (g << 8) | (b));
|
||||
img.setRGB(j, i, rgb);
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
// obligatoire : on cree un nouveau pinceau pour pouvoir le modifier plus tard
|
||||
Graphics pinceau2 = pinceau.create();
|
||||
if (this.isOpaque()) {
|
||||
// obligatoire : on repeint toute la surface avec la couleur de fond
|
||||
pinceau2.setColor(this.getBackground());
|
||||
pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
pinceau2.drawImage(this.image, 768, 1024, this);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP9:FluxOctets/MainImage.class
Normal file
BIN
DEV2.1/TP9:FluxOctets/MainImage.class
Normal file
Binary file not shown.
22
DEV2.1/TP9:FluxOctets/MainImage.java
Normal file
22
DEV2.1/TP9:FluxOctets/MainImage.java
Normal file
@ -0,0 +1,22 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
|
||||
public class MainImage{
|
||||
|
||||
public static void main(String[] args) {
|
||||
try{
|
||||
FileInputStream file = new FileInputStream("image.bin");
|
||||
try {
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(1024, 768);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.add(new Imag(1024, 768, "image.bin"));
|
||||
fenetre.setVisible(true);
|
||||
fenetre.pack();
|
||||
file.close();
|
||||
} catch(IOException e){}
|
||||
}catch(FileNotFoundException e){}
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP9:FluxOctets/image.bin
Normal file
BIN
DEV2.1/TP9:FluxOctets/image.bin
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user