/* * Methode qui retire un abonne du vecteur avec sa matricule. * @param Un string matricule. * @return Aucun. */ void Bibliotheque::retirerAbonne(const string & matricule) { unsigned int z = 0; Abonne* abonne = trouverAbonne(matricule, z); if (abonne != nullptr) { if (abonne->obtenirNombreEmprunte() == 0) { vecAbonne_.erase(vecAbonne_.begin() + z); }else { for (unsigned int i = 0; i < abonne->obtenirNombreEmprunte(); i++) { bool trouver = false; unsigned int h = 0; while (!trouver && h < vecEmprunt_.size()) { if (*(vecEmprunt_[h]->obtenirLivre()) == *(abonne->obtenirEmprunt(i)->obtenirLivre())) { trouver = true; Livre* livre = vecEmprunt_[h]->obtenirLivre(); livre->modifierNbDisponibles(livre->obtenirNbDisponibles() + 1); vecEmprunt_.erase(vecEmprunt_.begin() + h); } else { h++; } } } } } }
Livre::Livre(const Livre & l):AbstractMedia(l) { m_auteur = l.auteur(); m_editeur = l.editeur(); m_cycle = l.cycle(); m_numeroTome = l.numeroTome(); }
/* * Methode qui vérifie s’il est possible que l'abonne emprunte un livre. * @param Un Abonne et un Livre. * @return Un bool. */ bool Bibliotheque::estEmpruntable(const Abonne & abonne, const Livre & livre) const { unsigned int k; bool retour = ( (livre.obtenirNbDisponibles() >= 1) && (abonne.obtenirAge() >= livre.obtenirAgeMinimal()) && (!(abonne.estEmprunte(livre, k)))); return retour; }
bool Livre::operator==(const Livre & livre) const { if (titre_ == livre.obtenirTitre() && cote_ == livre.obtenirCote()) { return true; } else { return false; } }
bool Bibliotheque::emprunter(const string& matricule, const string& cote, const unsigned int dateRetour) { Abonne* abonne = trouverAbonne(matricule); ObjetEmpruntable* objetEmpruntable = trouverObjetEmpruntable(cote); if (objetEmpruntable != nullptr) { if (estEmpruntable(matricule, *objetEmpruntable)) { if (obtenirClasseObjet(cote) == "Livre") { bool estTrouveLivre = false; Livre* livre = nullptr; for (unsigned int i = 0; i < livres_.size() && !estTrouveLivre; i++) if (livres_[i]->obtenirCote() == cote) { livre = livres_[i]; estTrouveLivre = true; } Emprunt* emprunt = new Emprunt(livre, *abonne, dateRetour); emprunts_.push_back(emprunt); livre->modifierNbDisponibles(livre->obtenirNbDisponibles() - 1); abonne->ajouterEmprunt(emprunt); return true; } else if (obtenirClasseObjet(cote) == "Dvd") { bool estTrouveDvd = false; Dvd* dvd = nullptr; for (unsigned int i = 0; i < livres_.size() && !estTrouveDvd; i++) if (dvds_[i]->obtenirCote() == cote) { dvd = dvds_[i]; estTrouveDvd = true; } Emprunt* emprunt = new Emprunt(dvd, *abonne, dateRetour); emprunts_.push_back(emprunt); dvd->modifierNbDisponibles(dvd->obtenirNbDisponibles() - 1); abonne->ajouterEmprunt(emprunt); return true; } } } return false; }
bool Bibliotheque::ajouterLivre(Livre& livre) { if (trouverObjetEmpruntable(livre.obtenirCote()) == nullptr) { livres_.push_back(&livre); return true; } return false; }
bool Bibliotheque::retourner(const string & matricule, const string & cote) { bool retour = false; Abonne* abonne = trouverAbonne(matricule); Livre* livre = trouverLivre(cote); if (abonne->retirerEmprunt(*livre)) { livre->modifierNbDisponibles(livre->obtenirNbDisponibles() + 1); for (unsigned int i = 0; i < vecEmprunt_.size(); i++) { if (*(vecEmprunt_[i]->obtenirLivre()) == *livre) { vecEmprunt_.erase(vecEmprunt_.begin() + i); retour = true; i = vecEmprunt_.size(); } } } return retour; }
/* * Methode qui vérifie si l'emprunt peut se faire en verifiant tout les conditions. * @param Un string matricule, cote et un int date. * @return Un bool. */ bool Bibliotheque::emprunter(const string & matricule, const string & cote, const int & date) { bool retour = false; unsigned int iAbonne = 0; unsigned int iLivre = 0; Livre * livre = trouverLivre(cote); Abonne * abonne = trouverAbonne(matricule, iAbonne); if (estEmpruntable(*abonne, *livre)) { if (abonne->obtenirNombreEmprunte() < 2) { Emprunt* emprunt = new Emprunt(abonne->obtenirMatricule(), livre, date); livre->modifierNbDisponibles(livre->obtenirNbDisponibles() - 1); abonne->ajouterEmprunt(emprunt); vecEmprunt_.push_back(emprunt); retour = true; } } return retour; }
void Livre::operator=(const Livre & livre) { titre_ = livre.obtenirTitre(); cote_ = livre.obtenirCote(); ageMinimal_ = livre.obtenirAgeMinimal(); annee_ = livre.obtenirAnnee(); nbDisponibles_ = livre.obtenirNbDisponibles(); nbExemplaires_ = livre.obtenirNbExemplaires(); }
void Bibliotheque::ajouterLivre(Livre & livre) { if (trouverLivre(livre.obtenirCote()) == nullptr) { vecLivre_.push_back(&livre); } }
bool operator==(const string & cote, const Livre & livre) { if (cote == livre.obtenirCote()) return true; else return false; }
bool Livre::operator<(const Livre & livre) const { if (titre_ < livre.obtenirTitre()) return true; else return false; }