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
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 (cpp) [Seleccionar]
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include <windows.h>
#include <stdio.h>
using namespace std;
char nombre[15][20];//Matriz tipo char bidimensional de 15 filas y 20 columnas.
int telefono[15]; //Matriz tipo enetro unidimensional.
void ingresar();
void mostrar();
void consulte();
int norepeticion(int znum);
void gotoxy(int x,int y)
{
HANDLE hCon;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X=x;
dwPos.Y=y;
SetConsoleCursorPosition(hCon,dwPos);
}
int main()
{
int n;
int salida=0;
do
{
system("cls");
cout<<"\t\t******MENU******";
cout<<endl<<"1. INGRESAR CONTACTOS";
cout<<endl<<"2. MOSTRAR CONTACTOS";
cout<<endl<<"3. CONSULTE POR NOMBRE";
cout<<endl<<"4. SALIR";
cout<<endl<<"Elija una opci\xa2n : ";
cin>>n;
switch(n)
{ case 1: ingresar();
break;
case 2: mostrar();
break;
case 3: consulte();
break;
case 4: salida=1;
break;
default:
cout<<endl<<endl<<"Presione una de las teclas indicadas";
cout<<endl<<endl;
system("pause");
break;
}
}
while(salida==0);
cout<<endl<<endl;
return 0;
}
void ingresar()
{
int i, znumtel, norepetir1 ;
system("cls");
for (i=0; i<5; i++)
{
telefono[i]=0;
strcpy (nombre[i]," ");
}
cout<<endl<<"\t************ INGRESAR CONTACTOS ***********";
cout<<endl<<endl;
for ( i=0; i<5 ; i++ )
{
cout<<"\nDIGITE UN NOMBRE: ";
cin>>nombre[i];
cout<<"\nDIGITE UN NUMERO DE TELEFONO: ";
cin>>znumtel;
while(znumtel<1 or znumtel>8000000)
{
cout<<endl<<"\t****** NUMERO DE TELEFONO INCORRECTO...INGRESE OTRO NUMERO DE TELFONO";
cout<<"\nDIGITE UN NUMERO DE TELEFONO CORRECTO: ";
cin>>znumtel;
}
norepetir1=norepeticion(znumtel);
if(norepetir1==1)
{
cout<<endl<<endl<<"ESTE NUMERO TELEFONICO YA ESTA REGISTRADO...DIGITE OTRO NUMERO TELEFONICO",
i--;
cout<<endl;
}
else
{
telefono[i]=znumtel;
}
}
cout<<endl;
system("PAUSE");
}
int norepeticion(int znum)
{
int i, nor1=0;
for (i=0; i<5; i++)
{
if(znum==telefono[i])
{
nor1=1;
break;
}
}
return (nor1);
}
void mostrar()
{
int i;
system("cls");
cout<<"\t************ MOSTRAR CONTACTOS ***********";
gotoxy (3,3); cout<<"NOMBRE";
gotoxy (15,3);cout<<"TELEFONO";
for (i=0; i<5; i++)
{
gotoxy(3,i+5); cout<<nombre[i];
gotoxy(15,i+5);cout<<telefono[i];
}
cout<<endl;
system("PAUSE");
}
void consulte()
{
bool encontro=FALSE;
int i;
char busca[20];
system("cls");
cout << "\t Busqueda por nombre: \n\n";
cout<<endl<<endl<<"digite nombre a buscar";
fflush(stdin);
cin.getline(busca,20);
for(i=0;i<5;i++)
{
if(strcmp(nombre[i],busca)==0)
{
cout<<endl<<endl"Tel\202fono:"<<i;
encontro=TRUE;
break;
}
}
if(encontro==FALSE) cout<<"nombre no registrado";
cout<<endl<<endl;
system("PAUSE");
}