Advertisement
danixan

Sessió 7: Cerca en una llista d'estudiants

Apr 10th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include "listIOEstudiant.hh"
  2.  
  3. bool pert_llista_est(const list<Estudiant>& l, int x, int& y, bool& s)
  4. /* Pre: cert */
  5. /* Post: El resultat indica si x hi es o no a l */
  6. {
  7.   bool b = false;
  8.   list<Estudiant>::const_iterator it = l.begin();
  9.   while (it != l.end() and not b){
  10.     if ((*it).consultar_DNI() == x) {
  11.         b= true;
  12.         if ((*it).te_nota()) {
  13.             y = (*it).consultar_nota();
  14.             s = true;
  15.         }
  16.     }
  17.     else ++it;
  18.   }
  19.   return b;
  20. }
  21.  
  22. int main(){
  23.  
  24.   list <Estudiant> l;
  25.   cout << "Entra llista d'estudiants (acabada per 0): " << endl;
  26.   llegir_llista_estudiants(l,0);
  27.  
  28.   cout << "DNI a cercar: ";
  29.   int x = readint();
  30.   int y;
  31.   bool s = false;
  32.   bool b = pert_llista_est(l,x,y,s);
  33.   if (b) {
  34.        cout << "l'estudiant " << x << " esta a la llista ";
  35.        if (s) cout << "i te nota " << y;
  36.        else cout << "pero no te nota";
  37.        cout << endl;
  38.    }
  39.   else cout << "l'estudiant no hi és" << endl;
  40.     escriure_llista_int(l);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement