Ver Mensaje Individual
  #19 (permalink)  
Antiguo 12/03/2016, 19:31
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Respuesta: headers, carpetas y menúes c++

Hola eferion, al final no me da más error con los getRow, lamentablemente tuve que usar los punteros para eso:

Código C++:
Ver original
  1. #include <list>
  2. #include "Persona.h"
  3. #ifndef MANPERSONAS_H
  4. #define MANPERSONAS_H
  5. using namespace std;    
  6.     std::list<Persona*>lista;
  7.     static int maxIdP = 0;
  8.     int getMaxIdP(){
  9.         return ++maxIdP;
  10.     }
  11.     bool check(Persona* p){
  12.         for(Persona* per : lista){
  13.             if(per->id == p->id){
  14.                 return true;
  15.             }
  16.         }
  17.         return false;
  18.     }
  19.     Persona* getRow(std::string xnom){
  20.         for(Persona* p : lista){
  21.             if(p->nom == xnom){
  22.                 return p;
  23.             }
  24.         }
  25.         return NULL;
  26.     }
  27.     Persona* getRow(int xid){
  28.         for(Persona* p : lista){
  29.             if(p->id == xid){
  30.                 return p;
  31.             }
  32.         }
  33.         return NULL;
  34.     }
  35.     bool create(Persona* p){
  36.         if(check(p)){            
  37.             return false;
  38.         }
  39.         else{
  40.             lista.push_back(p);
  41.             return true;
  42.         }
  43.     }
  44.     bool update(Persona* p){
  45.        
  46.     }
  47.     void deleted(Persona* p){
  48.         lista.remove(p);        
  49.     }
  50.     std::list<Persona*> read(){
  51.         return lista;        
  52.     }  
  53. #endif  /* MANPERSONAS_H */

Pero tengo ahora 2 problemas y es que el checkInt y el addInt no me andan ya q lo que quiero es que me validen de si lo que ingreso es númerico o no:

Código C++:
Ver original
  1. #include <ctime>
  2. #ifndef UTIL_H
  3. #define UTIL_H
  4. using namespace std;
  5. bool checkInt(int s){
  6.     return isdigit(s);
  7. }
  8. bool checkStr(string s){
  9.     for(int i=0; i < s.size(); i++){
  10.         if((s[i] >= 65 and s[i]<= 90) or (s[i] >= 90 and s[i]<= 122)){
  11.             return true;
  12.         }
  13.     }
  14.     return false;
  15. }
  16. void pause(int dur) {
  17.     int temp = time(NULL) + dur;
  18.     while(temp > time(NULL));
  19. }
  20. string addString(string type){
  21.     int intento = 1;
  22.     string nom = "";    
  23.     while(!checkStr(nom)){
  24.         cout << "\n intento nro "<< intento << " Ingrese " << type <<": ";
  25.         cin >> nom;
  26.         intento++;
  27.     }
  28.     return nom;
  29. }
  30. int addInt(string type){
  31.     int intento = 1;
  32.     int nro =0;    
  33.     while(!checkInt(nro)){
  34.         cout << "\n intento nro "<< intento << " Ingrese " << type <<": ";
  35.         cin >> nro;
  36.         intento++;
  37.     }
  38.     return nro;
  39. }
  40. #endif  /* UTIL_H */

Por otro lado cuando quiero agregar un nuevo elemento a mi lista al crear me da el error de: Segmentation Failed.

¿sugerencias?

Espero sus respuestas y saludos