mendoza_franco

TP03: FUNCIONES

Sep 7th, 2023
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdlib.h> //GENERARA NUMEROS
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. #include <string>
  7. #include <cstdlib>
  8. #include <cstring>
  9. using namespace std;
  10. // 01 /////////////////////////////////////////////////////////////////////////
  11.     int takeInt(string mensaje){
  12.         int entero;
  13.             do{
  14.                 cout<<mensaje;
  15.                     cin>>entero;
  16.                 if(cin.fail()==true){
  17.                     cin.clear();
  18.                         cin.ignore(100,'\n');
  19.                             cout<<"\n\t #ERROR: INGRESE UN NUMERO ENTERO\n\n"<<endl;
  20.                     continue;
  21.                 }
  22.                 else{break;}
  23.             }while(true);  
  24.     return entero;  }
  25. // 02 /////////////////////////////////////////////////////////////////////////
  26.     double takeDouble(string mensaje){
  27.         double numero;
  28.             do{
  29.                 cout<<mensaje;
  30.                 cin>>numero;
  31.                     if(cin.fail()==true){
  32.                         cin.clear();
  33.                             cin.ignore(100,'\n');
  34.                                 cout<<"\n\t #ERRO: INGRESE UN NUMERO\n\n";
  35.                     continue;
  36.                 }
  37.                 else{break;}
  38.             }while(true);
  39.     return numero;  }  
  40. // 03 /////////////////////////////////////////////////////////////////////////
  41.     float takeFloat(string mensaje){
  42.         float numero;
  43.             do{
  44.                 cout<<mensaje;
  45.                 cin>>numero;
  46.                     if(cin.fail() == true){
  47.                         cin.clear();
  48.                             cin.ignore(100,'\n');
  49.                                 cout<<"\n\t - ERROR CARGUE "<< mensaje <<"\n\n";
  50.                     continue;
  51.                 }
  52.                 else{break;}
  53.             }while(true);
  54.     return numero;  }
  55. // 04 /////////////////////////////////////////////////////////////////////////    
  56.     int takeOption(string mensaje,  int desde,  int hasta){
  57.         int option;
  58.                 do{
  59.                 cout<<mensaje;
  60.                     cin>>option;
  61.                 if(cin.fail()==true||option<desde||option>hasta){
  62.                     cin.clear();
  63.                         cin.ignore(100,'\n');
  64.                             cout<<"\t  # ERROR: OPCION NO EXISTE.\n"<<endl;
  65.                     continue;
  66.                 }
  67.                 else{break;}
  68.             }while(true);      
  69.     return option;  }
  70. // 05 /////////////////////////////////////////////////////////////////////////
  71.     char validarRespuesta(string mensaje,   char respuesta){
  72.         do{
  73.             if(respuesta== 'S'||respuesta == 's'||respuesta=='n'||respuesta=='N'){
  74.                 return respuesta;
  75.             }
  76.             else{   fflush(stdin);//LIMPIA EL BUFFER
  77.                     cout<<mensaje;
  78.                         cin>>respuesta;
  79.             }
  80.         }while(1); 
  81.     }
  82. // 06 /////////////////////////////////////////////////////////////////////////
  83.     void int_Cadena(int numero, char cadena[]){
  84.         //convierte un int a cadena
  85.         int digitos = 0;
  86.         int auxiliar = numero;
  87.         int dig;
  88.             while(auxiliar>0){
  89.                 auxiliar = auxiliar/10;
  90.                 digitos++;
  91.             }
  92.         cadena[digitos]='\0';
  93.         auxiliar = numero;
  94.         int posicion = digitos-1;
  95.             while(posicion>=0){
  96.                 dig = auxiliar%10;
  97.                 auxiliar = auxiliar/10;
  98.                 cadena[posicion]= dig + '0';
  99.                 posicion--;
  100.             }
  101.     }
  102. // 07 /////////////////////////////////////////////////////////////////////////
  103.     void saltoDeLinea(){
  104.         cout<<"\n\n";
  105.     }
  106. // 08 /////////////////////////////////////////////////////////////////////////
  107.     void listaVacia(string tipo){
  108.         cout<<"\n\t - LISTA DE "<<tipo<<" -> SIN ELEMENTOS.";
  109.         saltoDeLinea();
  110.     }
  111. // 09 /////////////////////////////////////////////////////////////////////////
  112.     void takeChar(string mensaje, int demencion, char cadena[]){
  113.         char texto[demencion] = "\0";
  114.                 do{
  115.                 cout<<mensaje;
  116.                     cin.getline(texto,30,'\n');
  117.                 if(cin.fail() == true){
  118.                         cin.clear();
  119.                             cin.ignore(100,'\n');
  120.                                 cout<<"\n\t - ERROR EN LA CARGA. \n\n";
  121.                     continue;
  122.                 }
  123.                 else{break;}
  124.             }while(true);
  125.     }
  126. // 10 /////////////////////////////////////////////////////////////////////////
  127.     long int takeLongInt(string mensaje){
  128.         long int entero;
  129.             do{
  130.                 cout<<mensaje;
  131.                     cin>>entero;
  132.                 if(cin.fail()==true){
  133.                     cin.clear();
  134.                         cin.ignore(100,'\n');
  135.                             cout<<"\n\t # ERROR: INGRESE NUMEROS. \n\n"<<endl;
  136.                     continue;
  137.                 }
  138.                 else{break;}
  139.             }while(true);  
  140.     return entero;  }
  141. // 11 /////////////////////////////////////////////////////////////////////////
  142.     using std::cout; using std::endl;
  143.     using std::cin; using std::string;
  144. //---------------------------------------------------------------------------//
  145. /*  void validarDNI(){
  146.         int dni,longitud;
  147.         char dniCadena[] = "vacio";
  148.         do{
  149.             dni = takeInt("\t > INGRESE DNI:");
  150.                 int_Cadena(dni,dniCadena);
  151.                     longitud = strlen(dniCadena);
  152.                         if( longitud == 7 ||longitud == 8 ){
  153.                             auto dniCadena = std::strtol(dniCadena.data(), nullptr, 10);
  154.                             printf("%ld", dniCadena);
  155.                             break;
  156.                         }
  157.                         else{
  158.                             cout<<" # ERROR: VERIFIQUE BIEN LOS DIGITOS DE SU DNI.\n";
  159.                         }  
  160.         }while(true);
  161.         cout<<"\n - DNI: "<<dniCadena;
  162.     }*/
  163. // 12 /////////////////////////////////////////////////////////////////////////
  164. // 13 /////////////////////////////////////////////////////////////////////////
  165. // 14 /////////////////////////////////////////////////////////////////////////
  166. // 15 /////////////////////////////////////////////////////////////////////////
  167. // 16 /////////////////////////////////////////////////////////////////////////
  168. // 17 /////////////////////////////////////////////////////////////////////////
  169. // 18 /////////////////////////////////////////////////////////////////////////
  170. // 19 /////////////////////////////////////////////////////////////////////////
  171. // 20 /////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment