Advertisement
JosepRivaille

X90633: Control - Torn 1 (Primavera 2015)

Oct 8th, 2015
1,987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include "Cjt_estudiants.hh"
  2.  
  3. void Cjt_estudiants::afegir_estudiant(const Estudiant &est, bool& b) {
  4. /* Pre: el paràmetre implícit no està ple */
  5. /* Post: b = indica si el p.i. original conté un estudiant amb el dni d'est;
  6.    si b = fals, s'ha afegit l'estudiant est al paràmetre implícit */
  7.     b = false;
  8.  
  9.     int dni = est.consultar_DNI();    
  10.     int j = cerca_dicot(vest, 0, nest-1, dni);
  11.     if (vest[j].consultar_DNI() == dni) b = true;
  12.    
  13.     if (!b) {
  14.       ++nest;
  15.       int i = nest-1;
  16.       while (i > j) {
  17.     vest[i] = vest[i-1];
  18.     --i;
  19.       }
  20.       vest[j] = est;
  21.      
  22.       if (est.te_nota()) {
  23.     if (nest_amb_nota == 0) suma_notes = est.consultar_nota();
  24.     else suma_notes += est.consultar_nota();
  25.     ++nest_amb_nota;
  26.       }    
  27.     }
  28. }
  29.  
  30. void Cjt_estudiants::esborrar_estudiant(int dni, bool& b) {
  31. /* Pre: cert */
  32. /* Post: b indica si el paràmetre implícit original tenia un estudiant
  33.    amb el dni dni; si b, aquest estudiant ha quedat eliminat
  34.    del paràmetre implícit */
  35.   int i = 0;
  36.   bool exists = false;
  37.  
  38.   while (!exists && i < nest) {
  39.     if (vest[i].consultar_DNI() == dni) exists = true;
  40.     ++i;
  41.   }
  42.  
  43.   if (!exists) b = false;
  44.   else {
  45.     b = true;
  46.     if (vest[i-1].te_nota()) {
  47.       suma_notes -= vest[i-1].consultar_nota();
  48.       --nest_amb_nota;
  49.     }
  50.     for (int j = i; j < nest; ++j) {
  51.       vest[j-1] = vest[j];
  52.     }
  53.     --nest;
  54.   }
  55. }
  56.  
  57. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement