C/C++: Ajout des objets utilisateurs dans un vecteur

Author:

classe, vecteur, iterator
Download

#include 
#include 
#include 
#include 

using namespace std;

class Etudiant {
  string nom;
  unsigned matricule;
public:

 //Constructeur de la classe Etudiant
  Etudiant(unsigned mat, string _nom)
  {
    nom = _nom;
    matricule = mat;
  }
  string get_nom()
  {
	  return nom;
  }
  unsigned get_matricule()
  {
	  return matricule;
  }
};

void afficher_vecteur(vector vect)
{
  vector::iterator itr;

  for(itr=vect.begin(); itr != vect.end(); ++itr)
    cout << itr->get_matricule() << " " << itr->get_nom() << endl;;

}
int main()
{
  vector obj;

  //Ajout des objet dans le vecteur
  obj.push_back(Etudiant(900, "George"));
  obj.push_back(Etudiant(250, "Nicolas"));
  obj.push_back(Etudiant(420, "Bill"));

  //Appel de la fonction d'affichage
  afficher_vecteur(obj);

  return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *