Advertisement
JosepRivaille

X36914: Cerca en una llista d'estudiants

Oct 16th, 2015
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include "Estudiant.hh"
  2. #include <vector>
  3. #include <list>
  4. using namespace std;
  5.  
  6. void llegir_llista_est(list<Estudiant>& l){
  7.   list<Estudiant>::iterator it = l.begin();
  8.   Estudiant est;
  9.   est.llegir();
  10.   while (est.consultar_DNI() != 0 && (est.te_nota() && est.consultar_nota() != 0)) {
  11.     l.insert(it, est);
  12.     est.llegir();
  13.   }
  14. }
  15.  
  16. int cerca_llista_est(const list<Estudiant>& l, int n) {
  17.   int count = 0;
  18.   if (not l.empty()) {
  19.     list<Estudiant>::const_iterator it;
  20.     for (it = l.begin(); it != l.end(); ++it){
  21.       Estudiant aux = *it;
  22.       if (aux.consultar_DNI() == n) ++count;
  23.     }
  24.   }
  25.   return count;
  26. }
  27.  
  28. int main() {
  29.   list<Estudiant> llista;
  30.   llegir_llista_est(llista);
  31.   int n;
  32.   cin >> n;
  33.   cout << n << " " << cerca_llista_est(llista, n) << endl;
  34. }
  35.  
  36. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement