#include <iostream>
#include <vector>
#include <string>
// Interface Gérable
Class Gerable {
Public :
Virtual void emprunter() = 0 ;
Virtual void retourner() = 0 ;
};
// Classe abstraite Document
Class Document : public Gerable {
Protected :
Std ::string titre ;
Bool estEmprunte ;
Public :
Document(const std ::string& titre) : titre(titre), estEmprunte(false) {}
Virtual ~Document() {}
Std ::string getTitre() const { return titre ; }
Virtual void emprunter() override {
If ( !estEmprunte) {
estEmprunte = true ;
std ::cout << « Le document \ » » << titre << « \ » a été
emprunté. » << std ::endl ;
} else {
Std ::cout << « Le document \ » » << titre << « \ » est déjà
emprunté. » << std ::endl ;
Virtual void retourner() override {
If (estEmprunte) {
estEmprunte = false ;
std ::cout << « Le document \ » » << titre << « \ » a été
retourné. » << std ::endl ;
} else {
Std ::cout << « Le document \ » » << titre << « \ » n’était pas
emprunté. » << std ::endl ;
};
// Classe Livre (sous-classe de Document)
Class Livre : public Document {
Private :
Std ::string auteur ;
Public :
Livre(const std ::string& titre, const std ::string& auteur) :
Document(titre), auteur(auteur) {}
Std ::string getAuteur() const { return auteur ; }
};
// Classe Magazine (sous-classe de Document)
Class Magazine : public Document {
Private :
Int numero ;
Public :
Magazine(const std ::string& titre, int numero) : Document(titre),
numero(numero) {}
Int getNumero() const { return numero ; }
};
// Classe Adherent
Class Adherent {
Private :
Std ::string nom ;
Std ::vector<Document*> emprunts ;
Public :
Adherent(const std ::string& nom) : nom(nom) {}
Void emprunterDocument(Document* doc) {
Doc->emprunter() ;
Emprunts.push_back(doc) ;
Void retournerDocument(Document* doc) {
Doc->retourner() ;
[Link](std ::remove([Link](), [Link](),
doc), [Link]()) ;
}
Std ::string getNom() const { return nom ; }
};
Int main() {
Livre livre1(« Le Petit Prince », « Antoine de Saint-Exupéry ») ;
Magazine magazine1(« National Geographic », 202) ;
Adherent adherent1(« Jean Dupont ») ;
[Link](&livre1) ;
[Link](&livre1) ;
[Link](&magazine1) ;
Return 0 ;