1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Auteur{
string nom;
bool prime;
public: Auteur(){
}
public: Auteur (string n, bool p=false){
nom=n;
prime=p;
}
public: string getNom(){
return nom;
}
public:bool getPrix(){
return prime;
}
};
class Oeuvre{
public:string titre;
Auteur a;
string langue;
public: Oeuvre(){
}
public: Oeuvre(string tit, Auteur & aut, string lang){
titre=tit;
a=aut;
langue=lang;}
public: string getTitre(){
return titre;}
public: const Auteur getAuteur(){
return a;}
public: string getLangue(){
return langue;}
public: void affiche(){
cout<<titre<<", "<<a.getNom()<<", en "<<langue<<endl;}
public:~Oeuvre(){
cout<<"L'oeuvre "<<titre<<", "<<a.getNom()<<", en "<<langue<<" n'est plus disponible."<<endl;}
};
class Exemplaire{
public: Oeuvre o;
public: Exemplaire()
{}
Exemplaire(Oeuvre & o){
cout<<"Nouvel exemplaire de : "<<o.titre<<", "<<o.a.getNom()<<", en "<<o.langue<<endl;
}
Exemplaire( Exemplaire & e){
cout<<"Copie d'un exemplaire de : "<<e.o.titre<<", "<<e.o.a.getNom()<<", en "<<o.langue;}
public:~Exemplaire(){
cout<<"Un exemplaire de "<<o.titre<<", "<<o.a.getNom()<<", en "<<o.langue<<" a été jeté !"<<endl;
}
public: const Oeuvre getOeuvre(){
return o;}
public: void affiche(){
cout<<"Exemplaire de : "<<o.titre<<", "<<o.a.getNom()<<", en "<<o.langue<<endl;
}
};
class Bibliotheque{
public: string nom;
public:vector<Exemplaire *> exps;
public:Bibliotheque(string n){
nom=n;
cout<<"La bibliothèque "<<nom<<" est ouverte !"<<endl;
}
public: string getNom(){
return nom;}
public: void stocker(Oeuvre &oo, int n=1){
int count=1;
while (count<=n)
{exps.push_back(new Exemplaire( oo));
count++;}
}
public: void lister_exemplaires(string langue=""){
int taille=exps.size();
if(langue.empty()==true)
{
for (auto & ex : exps) {
(*ex).affiche();}
for(int i(0);i<taille;i++)
{
Exemplaire e=(*(exps[i]));
Oeuvre o=e.getOeuvre();
cout<<endl;
}
}
else {
for(int i(0);i<taille;i++)
{if(exps[i]->o.langue==langue){
exps[i]->affiche();
cout<<endl;
cout<<"empty False"<<endl;}
}
}
}
};
int main()
{
Auteur a1("Victor Hugo"),
a2("Alexandre Dumas"),
a3("Raymond Queneau", true);
Oeuvre o1("Les Misérables" , a1, "français" ),
o2("L'Homme qui rit" , a1, "français" ),
o3("Le Comte de Monte-Cristo" , a2, "français" ),
o4("Zazie dans le métro" , a3, "français" ),
o5("The Count of Monte-Cristo", a2, "anglais" );
Bibliotheque biblio("municipale");
biblio.stocker(o1, 2);
biblio.stocker(o2);
biblio.stocker(o3, 3);
biblio.stocker(o4);
biblio.stocker(o5);
cout << "La bibliothèque " << biblio.getNom()
<< " offre les exemplaires suivants :" << endl;
biblio.lister_exemplaires();
return 0;
} |
Partager