void fills (Arbre &fe, Arbre &fd) /* Pre: el p.i. no és buit i li diem A, fe i fd són buits */ /* Post: fe és el fill esquerre d'A, fd és el fill dret d'A, el p.i. és buit */ { if (primer_node!=NULL and fe.primer_node==NULL and fd.primer_node==NULL) { if (&fe != &fd) { node_arbre* aux; aux= primer_node; fe.primer_node= aux->segE; fd.primer_node= aux->segD; primer_node= NULL; delete aux; } else throw PRO2Excepcio ("Els dos paràmetres de fills no poden coincidir"); } else if (primer_node==NULL) throw PRO2Excepcio ("Un arbre buit no té fills"); else throw PRO2Excepcio ("Els dos paràmetres de fills han de ser buits a la crida"); }
void Estudiant::modificar_nota(double nota) { if (this-> nota==-1) throw PRO2Excepcio(ER1); if (nota<0 or nota>MAX_NOTA) throw PRO2Excepcio(ER2); this->nota = nota; }
void Estudiant::afegir_nota(double nota) { if (te_nota()) throw PRO2Excepcio(ER3); if (nota<0 or nota>MAX_NOTA) throw PRO2Excepcio(ER2); this->nota = nota; }
void Estudiant::llegir_estudiant() { DNI= readint(); if (DNI<0) throw PRO2Excepcio(ER4); double x = readdouble(); if (x >= 0 and x <= MAX_NOTA) nota = x; else nota=-1; }
T arrel() const /* Pre: el p.i. no és buit */ /* Post: el resultat és l'arrel del p.i. */ { if (primer_node!=NULL) return primer_node->info; else throw PRO2Excepcio ("Un arbre buit no té arrel"); }
void plantar(const T &x, Arbre &a1, Arbre &a2) /* Pre: el p.i. és buit, a1=A1, a2=A2 */ /* Post: el p.i. té x com a arrel, A1 com a fill esquerre i A2 com a fill dret; a1 i a2 són buits; si A1 i A2 són el mateix objecte, el fill dret n'és una còpia */ { if (this != &a1 and this != &a2) { if (primer_node==NULL) { node_arbre* aux; aux= new node_arbre; aux->info= x; aux->segE= a1.primer_node; if (a1.primer_node == a2.primer_node) aux->segD= copia_node_arbre(a1.primer_node); else aux->segD= a2.primer_node; primer_node= aux; a1.primer_node= NULL; a2.primer_node= NULL; } else throw PRO2Excepcio ("El p.i. de plantar ha de ser buit a la crida"); } else throw PRO2Excepcio ("El p.i. de plantar no pot coincidir amb els paràmetres"); }
int main() { cout << "Escribe la cola, acabada en 0:" << endl; queue<int> p; llegir_queue_int(p,0); cout << "Escribe el elemento a buscar:" << endl; int valor=readint(); queue<int> copia(p); // copiamos para no destruir p cout << "Version iterativa o recursiva (escribe 1 o 2):" << endl; int i =readint(); bool es_trobat; if (i==1) es_trobat = pertqueue_it(copia, valor); else if (i==2) es_trobat = pertqueue_rec(copia, valor); else throw PRO2Excepcio("Hay que escribir 1 o 2"); if(es_trobat) cout << " Está" << endl; else cout << " No está" << endl; cout << "Escribimos la cola original para ver que no se ha destruido:" << endl ; escriure_queue_int(p); }
double Estudiant::consultar_nota() const { if (nota ==-1) throw PRO2Excepcio(ER1); return nota; }
Estudiant::Estudiant(int dni) { if (dni<0) throw PRO2Excepcio(ER4); DNI = dni; nota=-1; }
Estudiant Cjt_estudiants::consultar_iessim(int i) const { if (i<1 or i>nest) throw PRO2Excepcio("Index no v��lid per a consultar_iessim"); return vest[i-1]; }
void Cjt_estudiants::modificar_iessim(int i, const Estudiant &est) { if (i<1 or i>nest) throw PRO2Excepcio("Index no v��lid per a modificar_iessim"); vest[i-1]= est; }