jueves, 14 de noviembre de 2013

Arreglos con Char, buscar arreglo (string)

#include <cstdlib>
#include <iostream>
#include <string.h>
#define ARRAY_SIZE 100 // se declara el arreglo de cuanto va a hacer puede ser X numero

using namespace std;

int main(int argc, char *argv[])
{
    //declaramos el arreglo en este caso será  un char por que va a ser texto
    char laArray[50][ARRAY_SIZE];
    int N; //numero del arreglo
    int resultado;//para preguntar si quiere otra ejecución :)
   
        strcpy(laArray[1],"ALMAZAN_ESTRADA_SEBASTIAN_OLAF");
        strcpy(laArray[2],"ALVAREZ CISNEROS IZYALYTH ERNESTINA");
        strcpy(laArray[3],"ALVAREZ QUINTERO DANIEL ISAI");
        strcpy(laArray[4],"ARENAS GUTIERREZ CAROLINA");
        strcpy(laArray[5],"CHAVEZ GUTIERREZ FERNANDO SAUL");
        strcpy(laArray[6],"GOMEZ MORALES ANDRES ANGEL");
        strcpy(laArray[7],"GONZALEZ SAUCEDO KARINA ISELA");
        strcpy(laArray[8],"HERNANDEZ GUTIERREZ CAROLINA");
        strcpy(laArray[9],"HERNANDEZ LEAL BRENDA ITZEL");
        strcpy(laArray[10],"HERNANDEZ VALDEZ MARGARITA");
        strcpy(laArray[11],"MIÑON MILLAN LUZ AIDA");
        strcpy(laArray[12],"ORDOÑEZ MUÑOZ GUADALUPE MONTSERRAT");
        strcpy(laArray[13],"PEREZ JIMENEZ BRAYAN ROBERTO");
        strcpy(laArray[14],"SANCHEZ BELLO GUSTAVO");
        strcpy(laArray[15],"SANTIAGO MARTINEZ GONZALO");
        strcpy(laArray[16],"VAZQUEZ REGALADO SAUL HIRAM");
        strcpy(laArray[17],"El ISRRA :) ");
       
        do
        {
            cout<<"        ***Este programa te brinda un nombre de acuerdo a su N. de lista .*** \n\n"<<endl;
            cout<<"~Introduce el numero a buscar 1 al 17: "<<endl; //pide un numero X para mostrar resultado
            cin>>N;
            if (N>17)
                {
                    cout<<"Este numero no se encuentra en la lista de Alumnos.\n\n"<<endl;//avisa que sobrepasa y no existe
                    cout<<"~Deseas buscar otro numero presiona 1 de lo contrario preciona 0"<<endl;// preguntar si quieres volver a ejecutar
                    cin>>resultado;
                }
            else
            {
            cout<<"El nombre que solicitaste es:"<<laArray[N]<<endl;//Muestra el contenido del arreglo
            cout<<"\n"<<endl;
            cout<<"~Deseas buscar otro numero presiona 1 de lo contrario presiona 0"<<endl;//vuelve a preguntar la ejecución
            cin>>resultado;
            }
        }
            while(resultado==1);// sirve para que si es 1 vuelve a preguntar
       
   
    system("pause");
    return 0;
}

image

image

No hay comentarios:

Publicar un comentario