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

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Agenda C++ con estructuras
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Agenda C++ con estructuras  (Leído 13,736 veces)
Ja_90

Desconectado Desconectado

Mensajes: 51



Ver Perfil
Agenda C++ con estructuras
« en: 8 Noviembre 2014, 05:44 am »

Buenas
Por acá dejo el código de la agenda que estoy haciendo....Solo me falta la parte de Eliminar...
Quisiera que me dieran ideas de como hacerlo, solo me falta eso...el resto funciona perfecto...lo pueden compilar y verán que funciona...(no guarda los datos luego de cerrar el programa..Ese es el paso siguiente que quiero hacer y adicional a eso usar vectores pero lo haré mas adelante) por ahora quiero terminar este de esta manera.

Esta hecho y compilado en codeblocks en linux, si utilizan windows y sale algún error posiblemente sea el de system("clear").... en windows se cambia por system("cls") y ya.

Código
  1. //----------------------- LIBRERIAS -----------------------------------//
  2. #include <iostream>
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. #include <cstring>
  8. using std::string;
  9.  
  10. #include <cstdlib>   // system("clear")
  11.  
  12. //----------------------- PROTOTIPO FUNCIONES --------------------------//
  13.  
  14. void menu();                                       // Muestra el menu principal
  15. void Ingresar(struct Datos Persona[],int,int);     // Ingreso de contactos
  16.  
  17. // Funciones para mostrar la info de los contactos
  18. void Mostrar(struct Datos Persona[],int);           // Muestra todos los contactos
  19. void ImprFicha(struct Datos Persona[],int,int);     // Imprime la informacion de los contactos
  20.  
  21. // Funciones de Busqueda
  22. void Buscar(struct Datos Persona[],int);          // Busqueda con menu
  23. void BuscaFicha(struct Datos Persona[],int);      // Buscar por # Ficha
  24. void BuscaNombre(struct Datos Persona[],int);     // Buscar por Nombre
  25. void BuscaTel(struct Datos Persona[],int);       // Buscar por Telefono
  26.  
  27. // Funcion Modificar
  28. void Modificar(struct Datos Persona[],int);
  29.  
  30. //----------------------- ESTRUCTURAS ----------------------------------//
  31. struct Cumpleanos
  32. {
  33.    string Nacimiento;
  34. };
  35.  
  36. struct Datos
  37. {
  38.    string Nombre;
  39.    string Direccion;
  40.    string Telefono;
  41.  
  42.    Cumpleanos Fecha;
  43. };
  44.  
  45. //------------------------ FUNCION PRINCIPAL ----------------------------//
  46. int main()
  47. {
  48.    const int LEN = 2;   // Cantidad de Contactos a guardar
  49.  
  50.    Datos Persona[LEN];  // Defino la variable Persona del tipo Datos (estructura)
  51.  
  52.    int index = 0;  // Variable para el Indice cada contacto
  53.    int opcion;     // Opcion Menu principal
  54.    bool salir;     // Variable Para salir del menu principal
  55.  
  56.    do
  57.    {
  58.        menu();  // Llamada funcion menu();
  59.  
  60.        cout << "\n\t Elija la opcion: ";
  61.        cin >> opcion;
  62.        cin.ignore();
  63.  
  64.        switch (opcion)    // Menu principal
  65.        {
  66.            case 1:
  67.                    system("clear");
  68.                    Ingresar(Persona,index,LEN); // Llamo funcion Ingresar();
  69.                    index++;
  70.                    break;
  71.            case 2:
  72.                    system("clear");
  73.                    Mostrar(Persona,index);  // Llamo funcion Mostrar();
  74.                    break;
  75.            case 3:
  76.                    system("clear");
  77.                    Buscar(Persona,index);  // LLamo funcion Buscar();
  78.                    break;
  79.            case 4:
  80.                    system("clear");
  81.                    Modificar(Persona,index);
  82.                    break;
  83.            case 6:
  84.                    salir = true;
  85.                    break;
  86.            default:
  87.                    system("clear");
  88.                    cout << "Ingrese Opcion valida\n\n";
  89.                    break;
  90.        }
  91.    }while(salir == false);
  92.  
  93.    return 0;
  94. }
  95.  
  96. //--------------------- FUNCIONES ---------------------------//
  97.  
  98. /// FUNCION MENU ///
  99. void menu()
  100. {
  101.    cout << "\t AGENDA INFORMATIVA \n\n";
  102.  
  103.    cout << "\t 1. Ingresar." << endl;
  104.    cout << "\t 2. Mostrar todos." << endl;
  105.    cout << "\t 3. Buscar contacto." << endl;
  106.    cout << "\t 4. Modificar." << endl;
  107.    cout << "\t 5. Eliminar." << endl;
  108.    cout << "\t 6. SALIR." << endl;
  109. }
  110.  
  111. /// FUNCION INGRESAR ///
  112.  
  113. void Ingresar(struct Datos Persona[], int numero, int TAM)  // Paso como parametros la estructura,index y LEN
  114. {
  115.    if(numero < TAM)  // Comparo el numero de contactos con la cantidad que se pueden guardar
  116.    {
  117.        cout << "\t Igresar Datos Ficha: #" << numero << endl << endl;
  118.  
  119.        cout << " Nombre: ";
  120.        getline(cin,Persona[numero].Nombre);
  121.        cout << " Direccion: ";
  122.        getline(cin,Persona[numero].Direccion);
  123.        cout << " Telefono: ";
  124.        getline(cin,Persona[numero].Telefono);
  125.        cout << " Fecha Nacimiento (DD/MM/AAAA): ";
  126.        getline(cin, Persona[numero].Fecha.Nacimiento);
  127.        cout << endl << endl;
  128.    }
  129.    else
  130.        cout << "LLEGO AL LIMITE DE CONTACTOS PERMITIDOS" << endl << endl;
  131. }
  132.  
  133. /// FUNCION IMPRFICHA ///
  134. void ImprFicha(struct Datos Persona[], int x) // x ==> paso parametro iterador i  // Funcion Imprimir info
  135. {
  136.    cout << "\t Informacion ficha: #" << x << endl << endl;
  137.    cout << " Nombre: " << Persona[x].Nombre << endl;
  138.    cout << " Direccion: " << Persona[x].Direccion << endl;
  139.    cout << " Telefono: " << Persona[x].Telefono << endl;
  140.    cout << " Fecha Nacimiento (DD/MM/AAAA): " << Persona[x].Fecha.Nacimiento;
  141.    cout << endl << endl;
  142. }
  143.  
  144. /// FUNCION MOSTRAR ///
  145. void Mostrar(struct Datos Persona[], int numero)
  146. {
  147.    for(int i=0 ; i<numero ; i++)
  148.    {
  149.        ImprFicha(Persona,i);     // Llamada Funcion para imprimir la info
  150.    }
  151.    cin.get();        // Pausa
  152.    system("clear");  // Lipmpia
  153. }
  154.  
  155. /// FUNCION BUSCAR ///
  156. void Buscar(struct Datos Persona[], int numero)
  157. {
  158.    bool exit;  // variable para salir del menu Busqueda
  159.    do
  160.    {   // Menu de Busqueda
  161.        cout << "\t BUSQUEDA: \n\n";
  162.        cout << " 1. # Ficha" << endl;
  163.        cout << " 2. Nombre" << endl;
  164.        cout << " 3. Telefono" << endl;
  165.        cout << " 4. SALIR" << endl << endl;
  166.  
  167.        unsigned int op;
  168.        cout << " Indique Opcion: ";
  169.        cin >> op;
  170.        cin.ignore();
  171.        cout << endl;
  172.  
  173.        switch(op)  // Opciones Menu de Busqueda
  174.        {
  175.            case 1:
  176.                system("clear");
  177.                BuscaFicha(Persona,numero);  // Llamada funcion BuscaFicha(); ==> Busca por # de Ficha
  178.                break;
  179.            case 2:
  180.                system("clear");
  181.                BuscaNombre(Persona,numero); // Llamada funcion BuscaNombre(); ==> Busca por Nombre
  182.                break;
  183.            case 3:
  184.                system("clear");
  185.                BuscaTel(Persona,numero); // Llamada funcion BuscaTel(); ==> Busca por Telefono
  186.                break;
  187.            case 4:
  188.                exit = true;
  189.                break;
  190.  
  191.            default:
  192.                cout << "ERROR, DIGITE OPCION CORRECTA\n";
  193.                break;
  194.        }
  195.    }while(exit == false);
  196.  
  197.    system("clear");     // Limpiar
  198. }
  199.  
  200. /// FUNCION BUSCAFICHA ///
  201. void BuscaFicha(struct Datos Persona[], int numero)
  202. {
  203.    cout << "\t Busqueda por ficha: \n\n";
  204.  
  205.    unsigned int Ficha;
  206.    cout << " Digite # Ficha: ";
  207.    cin >> Ficha;
  208.    cin.ignore();
  209.    cout << endl;
  210.  
  211.    for(int i=0 ; i<numero ; i++)
  212.    {
  213.        if(Ficha == i)
  214.        {
  215.            ImprFicha(Persona,i);
  216.        }
  217.    }
  218.    cin.get();        // Pausa
  219.    system("clear");  // Limpia
  220. }
  221.  
  222. /// FUNCION BUSCANOMBRE ///
  223. void BuscaNombre(struct Datos Persona[], int numero)
  224. {
  225.    cout << "\t Busqueda por nombre: \n\n";
  226.  
  227.    string nomb;
  228.    cout << " Digite el nombre: ";
  229.    getline(cin,nomb);
  230.    cout <<  endl;
  231.  
  232.    for(int i=0 ; i<numero ; i++)
  233.    {
  234.        if(nomb == Persona[i].Nombre)
  235.        {
  236.            ImprFicha(Persona,i);
  237.        }
  238.    }
  239.    cin.get();
  240.    system("clear");
  241. }
  242.  
  243. /// FUNCION BUSCAFECHA ///
  244. void BuscaTel(struct Datos Persona[], int numero)
  245. {
  246.    cout << "\t Busqueda por Telefono: \n\n";
  247.  
  248.    string tel;
  249.    cout << "Digite Telefono: ";
  250.    getline(cin,tel);
  251.    cout << endl;
  252.  
  253.    for(int i=0 ; i<numero ; i++)
  254.    {
  255.        if(tel == Persona[i].Telefono)
  256.        {
  257.            ImprFicha(Persona,i);
  258.        }
  259.    }
  260.    cin.get();
  261.    system("clear");
  262. }
  263.  
  264. /// FUNCION MODIFICAR ///
  265. void Modificar(struct Datos Persona[], int numero)
  266. {
  267.    cout << " Modificar o Editar la informacion: \n\n";
  268.  
  269.    string tel;
  270.    cout << "Digite Telefono: ";
  271.    getline(cin,tel);
  272.    cout << endl;
  273.  
  274.    for(int i=0 ; i<numero ; i++)
  275.    {
  276.        if(tel == Persona[i].Telefono)
  277.        {
  278.            ImprFicha(Persona,i);
  279.  
  280.            cout << " Nombre: ";
  281.            getline(cin,Persona[i].Nombre);
  282.            cout << " Direccion: ";
  283.            getline(cin,Persona[i].Direccion);
  284.            cout << " Telefono: ";
  285.            getline(cin,Persona[i].Telefono);
  286.            cout << " Fecha Nacimiento (DD/MM/AAAA): ";
  287.            getline(cin, Persona[i].Fecha.Nacimiento);
  288.            cout << endl << endl;
  289.        }
  290.    }
  291. }
  292.  
  293.  


En línea

:D  ::::Ja_90::::   :D
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Agenda bat V1 by my
Scripting
J3FFR3Y .4 C3D3Ñ0 0 3,741 Último mensaje 17 Diciembre 2006, 21:46 pm
por J3FFR3Y .4 C3D3Ñ0
Agenda java « 1 2 »
Java
Burnhack 13 52,070 Último mensaje 6 Marzo 2008, 00:47 am
por Burnhack
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines