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

Y resulta eferion, que logré hacer las validaciones, pongo el código:

Código C++:
Ver original
  1. #include <ctime>
  2. #include <ctype.h>
  3. #include <cstring>
  4. #ifndef UTIL_H
  5. #define UTIL_H
  6. using namespace std;
  7. bool checkInt(string s){
  8.     int cont =0;
  9.     for(int i=0; i < s.size(); i++){
  10.         if(s[i] >= 90 and s[i]<= 122) {
  11.             cont++;
  12.         }
  13.     }
  14.     return !s.empty() and cont == 0;
  15. }
  16. bool checkStr(string s){
  17.     int cont =0;
  18.     for(int i=0; i < s.size(); i++){
  19.         if(s[i] >= 48 and s[i]<= 57) {
  20.             cont++;
  21.         }
  22.     }
  23.     return !s.empty() and cont == 0;
  24. }
  25. void pause(int dur) {
  26.     int temp = time(NULL) + dur;
  27.     while(temp > time(NULL));
  28. }
  29. string passUpper(string s){
  30.     for(int i=0; i < s.size(); i++){
  31.         s[i] = toupper(s[i]);
  32.     }
  33.     return s;
  34. }
  35. string addString(string type){
  36.     int intento = 1;
  37.     string nom = "";    
  38.     while(!checkStr(nom)){
  39.         cout << "\n intento nro "<< intento << " Ingrese " << type <<": ";
  40.         cin >> nom;
  41.         intento++;
  42.     }
  43.     return passUpper(nom);
  44. }
  45.  
  46. int addInt(string type){
  47.     int intento = 1;    
  48.     string numero;
  49.     while(!checkInt(numero)){
  50.         cout << "\n intento nro "<< intento << " Ingrese " << type <<": ";
  51.         cin >> numero;
  52.         intento++;
  53.     }
  54.     return std::stoi(numero);
  55. }
  56. #endif  /* UTIL_H */

Mil gracias tanto a tí como a Instru.

Saludos.