diff --git a/TD3/correction/club.py b/TD3/correction/club.py new file mode 100644 index 0000000000000000000000000000000000000000..0baa2eb0d887674e13929d463087f561fe34b430 --- /dev/null +++ b/TD3/correction/club.py @@ -0,0 +1,86 @@ +class Personne: + def __init__(self,nom): + self.__nom = nom + + def get_nom(self): + return self.__nom + +class Adherent(Personne): + def __init__(self,nom,num): + Personne.__init__(self,nom) + self.__numero = num + + def get_numero(self): + return self.__numero + +class Activite: + def __init__(self,n): + self.__nom = n + self.__adherents = [] + + def get_nom(self): + return self.__nom + + def ajout_adherent(self,a): + self.__adherents.append(a) + + def affiche_adherents(self): + print('Liste des adherents:') + for a in self.__adherents: + print('Nom : {} - Numero : {}'.format(a.get_nom(), a.get_numero())) + +class Club: + def __init__(self,n): + self.__nom = n + self.__adherents = [] + self.__activites = [] + + def ajout_adherent(self,nom,num): + self.__adherents.append(Adherent(nom,num)) + + def ajout_activite(self,n): + self.__activites.append(Activite(n)) + + def associe(self,numAdherent,nomActivite): + ac = None + for a in self.__activites: + if a.get_nom() == nomActivite: + ac = a + break + + ad = None + for a in self.__adherents: + if a.get_numero() == numAdherent: + ad = a + break + + if ac != None and ad != None : + ac.ajout_adherent(ad) + + def affiche_activites(self): + print('Liste des activites:') + for a in self.__activites: + print('- Nom :',a.get_nom()) + a.affiche_adherents() + +if __name__ == '__main__': + c = Club('Ecully') + c.ajout_adherent('Paul',1) + c.ajout_adherent('Marc',2) + c.ajout_adherent('Marie',3) + + c.ajout_activite('Escalade') + c.ajout_activite('Theatre') + c.ajout_activite('Football') + + c.associe(1,'Theatre') + c.associe(2,'Theatre') + c.associe(3,'Theatre') + + c.associe(2,'Escalade') + c.associe(3,'Escalade') + + c.affiche_activites() + + + diff --git a/TD3/correction/diagramme_classes_hotel.png b/TD3/correction/diagramme_classes_hotel.png new file mode 100755 index 0000000000000000000000000000000000000000..55754a58d7453fb83b5b8d8757e35aa2d6010666 Binary files /dev/null and b/TD3/correction/diagramme_classes_hotel.png differ diff --git a/TD3/correction/diagramme_classes_restaurant.png b/TD3/correction/diagramme_classes_restaurant.png new file mode 100644 index 0000000000000000000000000000000000000000..928f41b8b42ac938de4b6953aa43dd48eda72aea Binary files /dev/null and b/TD3/correction/diagramme_classes_restaurant.png differ diff --git a/TD3/correction/diagramme_classes_theatre.png b/TD3/correction/diagramme_classes_theatre.png new file mode 100755 index 0000000000000000000000000000000000000000..2c01778ced1a314c99bc9937378da86ab935e494 Binary files /dev/null and b/TD3/correction/diagramme_classes_theatre.png differ diff --git a/TD3/correction/hotel.py b/TD3/correction/hotel.py new file mode 100644 index 0000000000000000000000000000000000000000..41ab2c1adeccba46235de06e278f0894ccc570f9 --- /dev/null +++ b/TD3/correction/hotel.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Sep 20 14:05:14 2022 + +@author: dellandrea +""" + +class Personne: + def __init__(self,nom): + self.nom = nom + + def __str__(self): + return f"Classe Personne - nom : {self.nom}" + + +class Client(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.hotels = [] + self.chambres = [] + + def __str__(self): + return f"Classe Client - nom : {self.nom}" + +class Directeur(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.hotels = [] + + def __str__(self): + return f"Classe Directeur - nom : {self.nom}" + +class Television: + def __init__(self,nom): + self.nom = nom + self.chambre = None + + def __str__(self): + return f"Classe Television - nom : {self.nom}" + +class Lit: + def __init__(self,nom): + self.nom = nom + self.chambre = None + + def __str__(self): + return f"Classe Lit - nom : {self.nom}" + +class Salle_de_bain: + def __init__(self,nom): + self.nom = nom + self.chambre = None + + def __str__(self): + return f"Classe Salle_de_bain - nom : {self.nom}" + +class Chambre: + def __init__(self,nom,hotel,nom_tele,nom_lit,nom_sdb): + self.nom = nom + self.hotel = hotel + self.clients = [] + self.television = Television(nom_tele) + self.lit = Lit(nom_lit) + self.salle_de_bain = Salle_de_bain(nom_sdb) + + def __str__(self): + return f"Classe Chambre - nom : {self.nom}" + + +class Hotel: + def __init__(self,nom): + self.nom = nom + self.directeur = None + self.clients = [] + self.chambres = [] + + def __str__(self): + return f"Classe Hotel - nom : {self.nom}" + +if __name__ == '__main__': + + p = Personne("Marie") + print(p) + + cl = Client("Charles") + print(cl) + + d = Directeur("Maxime") + print(d) + + h = Hotel("L'Europeen") + print(h) + + sdb = Salle_de_bain("Ocean") + print(sdb) + + t = Television("Tashibo") + print(t) + + l = Lit("Confort") + print(l) + + ch = Chambre("101",h,"Samsing","Relax","Plage") + print(ch) \ No newline at end of file diff --git a/TD3/correction/restaurant.py b/TD3/correction/restaurant.py new file mode 100644 index 0000000000000000000000000000000000000000..b35062bf366e52131328675b3ffa7e0f715e0483 --- /dev/null +++ b/TD3/correction/restaurant.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Sep 20 14:05:14 2022 + +@author: dellandrea +""" + +class Personne: + def __init__(self,nom): + self.nom = nom + + def __str__(self): + return f"Classe Personne - nom : {self.nom}" + + +class Client(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.restaurants = [] + self.plats = [] + + def __str__(self): + return f"Classe Client - nom : {self.nom}" + +class Serveur(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.restaurant = None + self.plats = [] + + def __str__(self): + return f"Classe Serveur - nom : {self.nom}" + +class Directeur(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.restaurants = [] + + def __str__(self): + return f"Classe Directeur - nom : {self.nom}" + +class Cuisinier(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.restaurant = None + self.plats = [] + + def __str__(self): + return f"Classe Cuisinier - nom : {self.nom}" + + +class Plat: + def __init__(self,nom): + self.nom = nom + self.restaurants = [] + self.cuisiniers = [] + self.serveurs = [] + self.clients = [] + + def __str__(self): + return f"Classe Plat - nom : {self.nom}" + +class Restaurant: + def __init__(self,nom): + self.nom = nom + self.directeur = None + self.cuisiniers = [] + self.serveurs = [] + self.clients = [] + self.plats = [] + + def __str__(self): + return f"Classe Restaurant - nom : {self.nom}" + +if __name__ == '__main__': + + p = Personne("Marie") + print(p) + + cl = Client("Charles") + print(cl) + + s = Serveur("Paul") + print(s) + + d = Directeur("Maxime") + print(d) + + cu = Cuisinier("Sabine") + print(cu) + + p = Plat("Lasagnes") + print(p) + + r = Restaurant("Chez Lulu") + print(r) \ No newline at end of file diff --git a/TD3/correction/theatre.py b/TD3/correction/theatre.py new file mode 100644 index 0000000000000000000000000000000000000000..c8112242527a5e827c4444f8a0fc29720c49d053 --- /dev/null +++ b/TD3/correction/theatre.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Sep 20 14:05:14 2022 + +@author: dellandrea +""" + +class Personne: + def __init__(self,nom): + self.nom = nom + + def __str__(self): + return f"Classe Personne - nom : {self.nom}" + + +class Acteur(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.theatres = [] + self.costumes = [] + self.pieces_de_theatre = [] + + def __str__(self): + return f"Classe Acteur - nom : {self.nom}" + +class Costumier(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.theatre = None + self.costumes = [] + + def __str__(self): + return f"Classe Costumier - nom : {self.nom}" + +class Metteur_en_scene(Personne): + def __init__(self,nom): + Personne.__init__(self, nom) + self.theatres = [] + self.pieces_de_theatre = [] + + def __str__(self): + return f"Classe Metteur_en_scene - nom : {self.nom}" + +class Piece_de_theatre: + def __init__(self,nom): + self.nom = nom + self.theatres = [] + self.acteurs = [] + self.metteur_en_scene = None + + def __str__(self): + return f"Classe Piece_de_theatre - nom : {self.nom}" + +class Costume: + def __init__(self,nom): + self.nom = nom + self.theatre = None + self.acteurs = [] + self.costumiers = [] + + def __str__(self): + return f"Classe Costume - nom : {self.nom}" + +class Theatre: + def __init__(self,nom): + self.nom = nom + self.metteurs_en_scene = [] + self.pieces_de_theatre = [] + self.acteurs = [] + self.costumiers = [] + self.costumes = [] + + def __str__(self): + return f"Classe Theatre - nom : {self.nom}" + +if __name__ == '__main__': + + p = Personne("Marie") + print(p) + + a = Acteur("Charles") + print(a) + + c = Costumier("Paul") + print(c) + + m = Metteur_en_scene("Delphine") + print(m) + + pi = Piece_de_theatre("Hamlet") + print(pi) + + co = Costume("Chique") + print(co) + + t = Theatre("La Comédie Française") + print(t) \ No newline at end of file diff --git a/TD4/correction/code/application_dessin.py b/TD4/correction/code/application_dessin.py new file mode 100644 index 0000000000000000000000000000000000000000..cadc000b5fd9d6ac82f27b49922aa5dadda18b75 --- /dev/null +++ b/TD4/correction/code/application_dessin.py @@ -0,0 +1,73 @@ +from tkinter import * +from tkinter import colorchooser # doit être importé manuellement +from formes import * + +class ZoneAffichage(Canvas): + def __init__(self, master, largeur, hauteur): + Canvas.__init__(self, master, width=largeur, height=hauteur) + self.__formes = [] + self.__type_forme = 'rectangle' + self.__couleur = 'brown' + + def selection_rectangle(self): + self.__type_forme = 'rectangle' + + def selection_ellipse(self): + self.__type_forme = 'ellipse' + + def selection_couleur(self): + self.__couleur = colorchooser.askcolor()[1] + + def ajout_forme(self, x, y): + # Notez qu'on aurait aussi pu ajouter ce code en méthodes de Rectangle/Ellipse. + if self.__type_forme == 'rectangle': + f = Rectangle(self, x-5, y-10, 10, 20, self.__couleur) + elif self.__type_forme == 'ellipse': + f = Ellipse(self, x, y, 5, 10, self.__couleur) + self.__formes.append(f) + + def suppression_forme(self, x, y): + for f in self.__formes[::-1]: + if f.contient_point(x, y): + self.__formes.remove(f) + f.effacer() + break + + +class FenPrincipale(Tk): + def __init__(self): + Tk.__init__(self) + + # disposition des composants de l'interface + self.configure(bg="grey") + barreOutils = Frame(self) + barreOutils.pack(side=TOP) + boutonRectangle = Button(barreOutils, text="Rectangle") + boutonRectangle.pack(side=LEFT, padx=5, pady=5) + boutonEllipse = Button(barreOutils, text="Ellipse") + boutonEllipse.pack(side=LEFT, padx=5, pady=5) + boutonCouleur = Button(barreOutils, text="Couleur") + boutonCouleur.pack(side=LEFT, padx=5, pady=5) + boutonQuitter = Button(barreOutils, text="Quitter") + boutonQuitter.pack(side=LEFT, padx=5, pady=5) + self.__canevas = ZoneAffichage(self, 600, 400) + self.__canevas.pack(side=TOP, padx=10, pady=10) + + # commandes + boutonRectangle.config(command=self.__canevas.selection_rectangle) + boutonEllipse.config(command=self.__canevas.selection_ellipse) + boutonCouleur.config(command=self.__canevas.selection_couleur) + boutonQuitter.config(command=self.destroy) + self.__canevas.bind("<Control-ButtonRelease-1>", self.control_clic_canevas) + self.__canevas.bind("<ButtonRelease-1>", self.release_canevas) + + def control_clic_canevas(self, event): + self.__canevas.suppression_forme(event.x, event.y) + + def release_canevas(self, event): + self.__canevas.ajout_forme(event.x, event.y) + + +if __name__ == '__main__': + fen = FenPrincipale() + fen.mainloop() diff --git a/TD4/correction/code/formes.py b/TD4/correction/code/formes.py new file mode 100644 index 0000000000000000000000000000000000000000..ac8029a36a88c8455df315ea864426afb04ec479 --- /dev/null +++ b/TD4/correction/code/formes.py @@ -0,0 +1,88 @@ +class Forme: + def __init__(self, canevas, x, y): + self.__canevas = canevas + self.__item = None + self.x = x + self.y = y + + def effacer(self): + self.__canevas.delete(self.__item) + + def deplacement(self, dx, dy): + self.__canevas.move(self.__item, dx, dy) + self.x += dx + self.y += dy + + def get_cavenas(self): + return self.__canevas + + def set_item(self,item): + self.__item = item + + def get_item(self): + return self.__item + +class Rectangle(Forme): + def __init__(self, canevas, x, y, l, h, couleur): + Forme.__init__(self, canevas, x, y) + item = canevas.create_rectangle(x, y, x+l, y+h, fill=couleur) + self.set_item(item) + self.__l = l + self.__h = h + + def __str__(self): + return f"Rectangle d'origine {self.x},{self.y} et de dimensions {self.__l}x{self.__h}" + + def get_dim(self): + return self.__l, self.__h + + def set_dim(self, l, h): + self.__l = l + self.__h = h + + def contient_point(self, x, y): + return self.x <= x <= self.x + self.__l and \ + self.y <= y <= self.y + self.__h + + def redimension_par_points(self, x0, y0, x1, y1): + self.x = min(x0, x1) + self.y = min(y0, y1) + self.__l = abs(x0 - x1) + self.__h = abs(y0 - y1) + + def update_coord_shape(self): + can = self.get_cavenas() + can.coords(self.get_item(), self.x, self.y, self.x+self.__l, self.y+self.__h) + + +class Ellipse(Forme): + def __init__(self, canevas, x, y, rx, ry, couleur): + Forme.__init__(self, canevas, x, y) + item = canevas.create_oval(x-rx, y-ry, x+rx, y+ry, fill=couleur) + self.set_item(item) + self.__rx = rx + self.__ry = ry + + def __str__(self): + return f"Ellipse de centre {self.x},{self.y} et de rayons {self.__rx}x{self.__ry}" + + def get_dim(self): + return self.__rx, self.__ry + + def set_dim(self, rx, ry): + self.__rx = rx + self.__ry = ry + + def contient_point(self, x, y): + return ((x - self.x) / self.__rx) ** 2 + ((y - self.y) / self.__ry) ** 2 <= 1 + + def redimension_par_points(self, x0, y0, x1, y1): + self.x = (x0 + x1) // 2 + self.y = (y0 + y1) // 2 + self.__rx = abs(x0 - x1) / 2 + self.__ry = abs(y0 - y1) / 2 + + def update_coord_shape(self): + can = self.get_cavenas() + can.coords(self.get_item(), self.x-self.__rx, self.y-self.__ry, self.x+self.__rx, self.y+self.__ry) +