Beispiel #1
0
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;
}
Beispiel #2
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;
}