#ifndef __annale2014__client__ #define __annale2014__client__ //#include "agenceLocale.hpp" #include <iostream> class Client { public: Client(const std::string& nom, const std::string& adresse, const std::AgenceLocale& agence); AgenceLocale operator() const; void afficher(std::ostream& out) const; private: std::string _nom; std::string _adresse; const AgenceLocale& _agenceLocale; }; #endif /* defined(__annale2014__client__) */ //#include "client.hpp" Client::Client(const std::string& nom, const std::string& adresse, const AgenceLocale& al) : _nom(nom), _adresse(adresse), _agenceLocale(agence) { } AgenceLocale Client::operator() const { return _agenceLocale->nom; } void afficher(std::ostream& out) const { out << _nom << _adresse << *_agenceLocale; } #ifndef __annale2014__employe__ #define __annale2014__employe__ //#include "agenceLocale.hpp" #include <iostream> #include <string> class Employe { public: Employe(const std::string& nom, int id, const Agencelocale* agl); virtual ~Employe(); virtual void afficher(std::ostream& out) const; virtual double calculerSalaire() const = 0; protected: std::string _nom; int _id; const AgenceLocale* _agl; }; #endif /* defined(__annale2014__employe__) */ //#include "employe.hpp" Employe::Employe(const std::string& nom, int i) : _nom(nom), _id(id), _agl(agl) { } virtual void Employe::afficher(std::ostream& out) const { out << _nom << _id << *_agl; } #ifndef __annale2014__commercial__ #define __annale2014__commercial__ #include <iostream> class Commercial : public Employe { public: Commercial(const std::string& nom, int id, double pourcentage, double fixe); virtual void calculerSalaire(); protected: double _pourcentage; double _fixe; } #endif /* defined(__annale2014__commercial__) */* //#include "commercial.h" Commercial::Commercial(const std::string& nom, int id, double pourcentage, double fixe) : Employer(nom, id), _pourcentage(pourcentage), _fixe(fixe) { } double calculerSalaire() const { } #ifndef __annale2014__agenceLocale__ #define __annale2014__agenceLocale__ // #include "region.h" // #include "employe.h" // #include "client.h" // #include "vente.h" #include <iostream> #include <vector> class AgenceLocale { public: AgenceLocale(const std::string& nom, const Region& region); AgenceLocale(const AgenceLocale& agence); void addEmploye(Employe* employe); Vente operator[](int i); void affiche(std::ostream& out); double calculerSalaire() const; double calculerSalaireCommerciaux() const; private: std::string _nom; Region _region; int _nbEmp; std::vector<Client> _clients; std::vector<Vente> _ventes; std::vector<Employe*> _employes; }; #endif /* defined(__annale2014__agenceLocale__) */ std::ostream& operator<<(std::ostream& out, const Client& c); //#include "agenceLocale.h" AgenceLocale::AgenceLocale(const std::string& nom, const Region& region, int nb) : _nom(nom), _region(region) { } AgenceLocale::AgenceLocale(const AgenceLocale& agence) { _nom = agence._nom; _region = agence._region; _clients = agence._clients; _employes = agence._employes; } void AgenceLocale::addEmploye(Employe* employe) { _employes.push_back(employe); } Vente AgenceLocale::operator[](int i) const { return v[i]; } void AgenceLocale::affiche(std::ostream& out) const { for (std::vector<Client>::const_iterator it = _clients.begin(); it != _clients.endl(); ++it) { out << it->_nom << std::endl; } } std::ostream& operator<<(ostream& out, const Client& client) { client.affiche(out); return out; } double AgenceLocale::calculerSalaire() const { double somme = 0.0; for (std::vector<Employe*>::const_iterator it = _employes.begin(); it != _employes.endl(); ++it) { somme += (*it)->calculerSalaire(); } return somme; } double AgenceLocale::calculerSalaireCommerciaux() const { double somme = 0.0; for (std::vector<Employe*>::const_iterator it = _employes.begin(); it != _employes.endl(); ++it) { if (dynamic_cast<Commercial*>(*it) != 0) // Est un commercial somme += (*it)->calculerSalaire(); } return somme; }
Améliorez votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature
-Quand il y a un pointeur, vecteur ou liste dans une classe, comment ça se passe au niveau du constructeur?
class Toto { public: Toto() : _s(), _i(), _p() // utilise la valeur par défaut du type, soit: _s(""), _i(0), _p(0) (ou _p(nullptr) si tu utilises le C++11) { } private: std::string _s; int _i; int* _p; };
std::string // std::string et non AgenceLocale, encore une petite faute de ma part Client::operator() const { return _agenceLocale->nom; }
Améliorez votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature
class Toto { public: Toto(const std::string& s, int& i) // Ok ! : _s(s), _i(i) { } Toto(const std::string& s, int& i) { _s = s; // Erreur _i = i; // Erreur } private: const std::string _s; int& _i; };
Améliorez votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionAgenceLocale(const std::string& nom, const Region& region, int nbEmp, std::vector<Client> clients, std::vector<Vente> ventes, std::vector<Employe*> employes); AgenceLocale(const AgenceLocale& agence);
AgenceLocale::AgenceLocale(const std::string& nom, const Region& region, int nbEmp, std::vector<Client> clients, std::vector<Vente> ventes, std::vector<Employe*> employes) : _nom(nom), _region(region), _nbEmp(nbEmp), _clients(clients), _ventes(ventes), _employes(employes) { } AgenceLocale::AgenceLocale(const AgenceLocale& agence) { _nom = agence._nom; _region = agence._region; _nbEmp = agence._nbEmp; _clients = agence._clients; _employes = agence._employes; _ventes = agence._ventes; }
J'ai réalisé ceci pour les constructeurs d'agence locale:
_nbEmp
J'ai également entendu parler de liste d'initialisation, est-ce que c'est applicable ici?
Par contre quand tu parles de design horrible, tu parles du code ou de la présentation du sujet dans l'annale?
Améliorez votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature
AgenceLocale::AgenceLocale(const std::string& nom, const Region& region) : _nom(nom), _region(region), _clients(), _ventes(), _employes() { } AgenceLocale::AgenceLocale(const AgenceLocale& agence) : _nom(agence._nom), _region(agence._region), _clients(agence._clients), _ventes(agence._ventes), _employes(agence._employes) { }
Améliorez votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature
AgenceLocale(const std::string& nom, const Region& region); AgenceLocale(const AgenceLocale& agence);
AgenceLocale::AgenceLocale(const std::string& nom, const Region& region) : _nom(nom), _region(region), _clients(clients), _ventes(ventes), _employes(employes) { } AgenceLocale::AgenceLocale(const AgenceLocale& agence) { _nom = agence._nom; _region = agence._region; _clients = agence._clients; _employes = agence._employes; _ventes = agence._ventes; }
Améliorez votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature
Concernant le constructeur par copie de AgenceLocale, ne faudrait-il pas faire 3 boucles pour copier tous les employés, ventes et clients?
Améliorez votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature