#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;
//----------------------- PROTOTIPO FUNCIONES --------------------------//
void menu(); // Muestra el menu principal
void Agregar(struct Datos Persona[],int,int); // Ingreso de contactos
// Funciones de Consulta
void Consultar(struct Datos Persona[],int); // Busqueda con menu
void BuscaNombre(struct Datos Persona[],int); // Buscar por Nombre
// Funciones para mostrar la info de los contactos
void Listar(struct Datos Persona[],int); // Muestra todos los contactos
void ImprFicha(struct Datos Persona[],int,int); // Imprime la informacion de los contactos
// Funcion Borrar
void Borrar(struct Datos Persona[],int &ocup,int borrado);
//----------------------- ESTRUCTURAS ----------------------------------//
struct Datos
{
string Apellido;
string Nombre;
string Telefono;
string Email;
};
//------------------------ FUNCION PRINCIPAL ----------------------------//
main()
{
const int MAX = 100; // Cantidad de Contactos a guardar
Datos Persona[MAX]; // Defino la variable Persona del tipo Datos (estructura)
int index = 0; // Variable para el Indice cada contacto
int opcion; // Opcion Menu principal
bool salir; // Variable Para salir del menu principal
int borrado;
int ocupado=-1;
do
{
system("cls");
menu(); // Llamada funcion menu();
cout << "\n\t Elija la opcion: ";
cin >> opcion;
cin.ignore();
switch (opcion) // Menu principal
{
case 1:
system("clear");
Agregar(Persona,index,MAX); // Llamo funcion Ingresar();
index++;
break;
case 2:
system("clear");
Consultar(Persona,index); // Llamo funcion Consultar();
break;
case 3:
system("clear");
Borrar(Persona,index,ocupado); // LLamo funcion Borrar();
break;
case 4:
system("clear");
Listar(Persona,index); // LLamo funcion Listar();
break;
case 5:
salir = true;
break;
default:
system("clear");
cout << "Ingrese Opcion valida\n\n";
break;
}
}while(salir == false);
return 0;
}
//--------------------- FUNCIONES ---------------------------//
// Funcion menu
void menu()
{
cout << "\t ******* MENÚ PRINCIPAL ******* \n\n";
cout << "\t 1) Agregar contacto" << endl;
cout << "\t 2) Consultar contacto" << endl;
cout << "\t 3) Borrar contacto" << endl;
cout << "\t 4) Listar contactos" << endl;
cout << "\t 5) Salir" << endl;
}
// Funcion agregar
void Agregar(struct Datos Persona[], int numero, int MAX) // Paso como parametros la estructura,index y LEN
{
if(numero < MAX) // Comparo el numero de contactos con la cantidad que se pueden guardar
{
cout << "\t Igresar Datos Ficha: #" << numero << endl << endl;
cout << " Apellido: ";
getline(cin,Persona[numero].Apellido);
cout << " Nombre: ";
getline(cin,Persona[numero].Nombre);
cout << " Telefono: ";
getline(cin,Persona[numero].Telefono);
cout << " Email: ";
getline(cin, Persona[numero].Email);
cout << endl << endl;
}
else
cout << "LLEGO AL LIMITE DE CONTACTOS PERMITIDOS" << endl << endl;
}
// Funcion imprficha
void ImprFicha(struct Datos Persona[], int x) // x ==> paso parametro iterador i // Funcion Imprimir info
{
cout << "\t Informacion ficha: #" << x << endl << endl;
cout << " Apellido: " << Persona[x].Apellido << endl;
cout << " Nombre: " << Persona[x].Nombre << endl;
cout << " Telefono: " << Persona[x].Telefono << endl;
cout << " Email: " << Persona[x].Email << endl;
}
// Funcion listar
void Listar(struct Datos Persona[], int numero)
{
for(int i=0 ; i<numero ; i++)
{
ImprFicha(Persona,i); // Llamada Funcion para imprimir la info
}
cin.get(); // Pausa
system("clear"); // Lipmpia
}
// Funcion consultar
void Consultar(struct Datos Persona[], int numero)
{
cout << "\t Busqueda por nombre y apellido: \n\n";
string nomb;
string apell;
cout << " Digite el apellido: ";
getline(cin,apell);
cout << endl;
cout << " Digite el nombre: ";
getline(cin,nomb);
cout << endl;
for(int i=0 ; i<numero ; i++)
{
if(nomb == Persona[i].Nombre && apell == Persona[i].Apellido)
{
ImprFicha(Persona,i);
}
else
{
cout<<"Ingrese datos validos"<<endl;
}
}
cin.get();
system("clear");
}
// Funcion borrar
void Borrar(struct Datos Persona[], int &ocup, int borrado)
{ bool encontrado=false;
int i=0;
string tel;
if(ocup>-1)
{
cout<<"Ingrese numero de telefono: ";
getline(cin,tel);
while(i<=ocup && !encontrado)
{
if (Persona[i].Telefono == borrado)
encontrado=true;
else
i++;
}
if(encontrado)
{
while(i<ocup)
{
Persona[i]=Persona[i+1];
i++;
}
ocup--;
cout<<"Borrado"<<endl;
}
else
cout<<"Ingrese un numero de telofono existente.";
}
system("pause");
}