elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / no se como hacer una función correctamente con arreglos en: 4 Diciembre 2016, 18:49 pm
Cordial saludo,
podrían hacer el favor de ayudarme con esta agenda, es que no puedo hacer una función donde se consulte por nombre, estoy trabajando con falcon

Código
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include <windows.h>
  5. #include <stdio.h>
  6. using namespace std;
  7.  
  8. char nombre[15][20];//Matriz tipo char bidimensional de 15 filas y 20 columnas.
  9.  
  10. int telefono[15]; //Matriz tipo enetro unidimensional.
  11.  
  12. void ingresar();
  13. void mostrar();
  14. void consulte();
  15. int norepeticion(int znum);
  16. void gotoxy(int x,int y)
  17. {
  18. HANDLE hCon;
  19. hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  20. COORD dwPos;
  21. dwPos.X=x;
  22. dwPos.Y=y;
  23. SetConsoleCursorPosition(hCon,dwPos);
  24. }
  25.  
  26. int main()
  27.  
  28. {
  29.  
  30. int n;
  31.  
  32. int salida=0;
  33.  
  34. do
  35.  
  36. {
  37.  
  38. system("cls");
  39.  
  40. cout<<"\t\t******MENU******";
  41.  
  42. cout<<endl<<"1. INGRESAR CONTACTOS";
  43.  
  44. cout<<endl<<"2. MOSTRAR CONTACTOS";
  45.  
  46. cout<<endl<<"3. CONSULTE POR NOMBRE";
  47.  
  48. cout<<endl<<"4. SALIR";
  49.  
  50. cout<<endl<<"Elija una opci\xa2n : ";
  51.  
  52. cin>>n;
  53.  
  54. switch(n)
  55.  
  56. { case 1: ingresar();
  57.  break;
  58.   case 2: mostrar();
  59.  break;        
  60.   case 3: consulte();
  61.              break;
  62.  case 4: salida=1;
  63.   break;
  64.  default:
  65.  
  66.  
  67.   cout<<endl<<endl<<"Presione una de las teclas indicadas";
  68.  
  69.   cout<<endl<<endl;
  70.  
  71. system("pause");
  72.  
  73.   break;
  74. }
  75.  
  76. }
  77. while(salida==0);
  78.  
  79. cout<<endl<<endl;
  80.  
  81.  return 0;
  82.  
  83. }
  84.  
  85. void ingresar()
  86. {
  87. int i, znumtel, norepetir1 ;
  88. system("cls");
  89. for (i=0; i<5; i++)
  90. {
  91. telefono[i]=0;
  92. strcpy (nombre[i]," ");
  93. }
  94. cout<<endl<<"\t************  INGRESAR CONTACTOS  ***********";
  95. cout<<endl<<endl;
  96. for ( i=0; i<5 ; i++ )
  97. {
  98.              cout<<"\nDIGITE UN NOMBRE: ";
  99.              cin>>nombre[i];
  100.              cout<<"\nDIGITE UN NUMERO DE TELEFONO: ";
  101.              cin>>znumtel;
  102.              while(znumtel<1 or znumtel>8000000)
  103.  {
  104.   cout<<endl<<"\t******  NUMERO DE TELEFONO INCORRECTO...INGRESE OTRO NUMERO DE TELFONO";
  105.   cout<<"\nDIGITE UN NUMERO DE TELEFONO CORRECTO: ";
  106.   cin>>znumtel;
  107.  }
  108.  norepetir1=norepeticion(znumtel);
  109.  if(norepetir1==1)
  110.  {
  111.   cout<<endl<<endl<<"ESTE NUMERO TELEFONICO YA ESTA REGISTRADO...DIGITE OTRO NUMERO TELEFONICO",
  112.   i--;
  113.   cout<<endl;
  114.  }
  115.  else
  116.  {
  117.   telefono[i]=znumtel;
  118.  }
  119. }
  120. cout<<endl;
  121.    system("PAUSE");
  122.  
  123. }
  124.  
  125. int norepeticion(int znum)
  126. {
  127. int i, nor1=0;
  128. for (i=0; i<5; i++)
  129. {
  130. if(znum==telefono[i])
  131. {
  132. nor1=1;
  133. break;
  134. }
  135. }
  136. return (nor1);
  137. }
  138.  
  139. void mostrar()
  140. {
  141. int i;
  142. system("cls");
  143. cout<<"\t************  MOSTRAR CONTACTOS  ***********";
  144. gotoxy (3,3); cout<<"NOMBRE";
  145. gotoxy (15,3);cout<<"TELEFONO";
  146. for (i=0; i<5; i++)
  147. {
  148. gotoxy(3,i+5); cout<<nombre[i];
  149. gotoxy(15,i+5);cout<<telefono[i];
  150. }
  151. cout<<endl;
  152.    system("PAUSE");
  153. }
  154.  
  155. void consulte()
  156. {
  157. bool encontro=FALSE;
  158. int i;
  159. char busca[20];
  160. system("cls");
  161.    cout << "\t Busqueda por nombre: \n\n";
  162.    cout<<endl<<endl<<"digite nombre a buscar";
  163.    fflush(stdin);
  164. cin.getline(busca,20);
  165. for(i=0;i<5;i++)
  166. {
  167. if(strcmp(nombre[i],busca)==0)
  168. {
  169. cout<<endl<<endl"Tel\202fono:"<<i;
  170. encontro=TRUE;
  171. break;
  172. }
  173. }
  174. if(encontro==FALSE) cout<<"nombre no registrado";
  175. cout<<endl<<endl;
  176. system("PAUSE");
  177. }
  178.  
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines