Exemple #1
0
/*
* 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++;
					}
				}
			}


			
		}
	}
}
Exemple #2
0
bool Bibliotheque::estEmpruntable(const string& matricule, const ObjetEmpruntable& objetEmpruntable) const
{
	Abonne* abonne = trouverAbonne(matricule);
	bool estEmprunte = false;

	for (unsigned int i = 0; i < emprunts_.size() && !estEmprunte; i++)
		if (emprunts_[i]->obtenirMatricule() == matricule && emprunts_[i]->obtenirObjetEmpruntable()->obtenirCote() == objetEmpruntable.obtenirCote())
			estEmprunte = true;

	return objetEmpruntable.obtenirNbDisponibles() > 0 && objetEmpruntable.obtenirAgeMinimal() < abonne->obtenirAge() &&
		!estEmprunte && abonne->obtenirNombreEmprunte() < abonne->obtenirEmpruntsLimite();
}
Exemple #3
0
/*
* 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;
}