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

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  una ayuda en c sharp con ste ejemplo weno
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: una ayuda en c sharp con ste ejemplo weno  (Leído 2,557 veces)
tomygrey

Desconectado Desconectado

Mensajes: 5


Ver Perfil
una ayuda en c sharp con ste ejemplo weno
« en: 10 Julio 2010, 01:41 am »

HI, weno tengo un problemilla para practicar en aplicacion por consola en c sharp
ahi va:
a travez de un menu que tenga las opciones:
1 insertar
2 listar
3 buscar
4 eliminar
5 salir

tengo que manipular datos ya sea con vector o matriz (sug creo que con vectores es mas conveniente) sobre el nombre, apellido, direccion y telefono de una persona.
El limite para los datos pueden ser 50 x ejemplo.

Digamos que quiera ingresar 3 personas: Por cada una de ellas ingresar los datos correspondientes y manipularlos a traves del menu mencionado. (Al eliminar se debe borrar todos los datos de la persona).

!!!stare totalemnt agradecido mens!!!!!!


En línea

criskapunk

Desconectado Desconectado

Mensajes: 277



Ver Perfil
Re: una ayuda en c sharp con ste ejemplo weno
« Respuesta #1 en: 10 Julio 2010, 16:33 pm »

Coloca lo que llevas hecho hasta el momento ;)


En línea

tomygrey

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Re: una ayuda en c sharp con ste ejemplo weno
« Respuesta #2 en: 11 Julio 2010, 16:44 pm »

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace My_Agenda
  6. {
  7.    class Program
  8.    {
  9.        static void Main(string[] args)
  10.        {
  11.        string[,] alumno = new string[100,4];
  12.            int n; string op;
  13.            n = 0;
  14.  
  15.            do
  16.            {
  17.                op = Menu();
  18.                switch (op)
  19.                {
  20.                    case "I":
  21.                    case "i": Insertar(ref alumno, ref n); break;
  22.                    case "E":
  23.                    case "e": Eliminar(ref alumno, ref n); break;
  24.                   /*case "O":
  25.                     case "o": Ordenar(ref alumno, ref n); break;*/
  26.                    case "B":
  27.                    case "b": Buscar(ref alumno, ref n); break;
  28.                    case "L":
  29.                    case "l": Listar(ref alumno , ref n); break;
  30.                    default:
  31.                        {
  32.                            if (op != "S" && op != "s")
  33.                                Console.WriteLine("\nOpcion invalida!!!"); break;
  34.                        }
  35.                }
  36.            } while (op != "S" && op != "s");
  37.        }
  38.  
  39.        //Menu del Programa Principal
  40.        public static string Menu()
  41.        {
  42.            string op;
  43.            Console.WriteLine("\n\t\t\tMENU");
  44.            Console.WriteLine("\t\t\t====\n");
  45.            Console.WriteLine("\t(I)nsertar");
  46.            Console.WriteLine("\t(E)liminar");
  47.            Console.WriteLine("\t(O)rdenar");
  48.            Console.WriteLine("\t(B)uscar");
  49.            Console.WriteLine("\t(L)istar");
  50.            Console.WriteLine("\t(S)alir");
  51.            Console.Write("\n\tIngresar Opcion: ");
  52.            op = Console.ReadLine();
  53.            return op;
  54.        }
  55.  
  56.        public static int MenuInsertar()
  57.        {
  58.            int op;
  59.            Console.Write("\n\tCuantos Desea Ingresar? ");
  60.  
  61.            op = int.Parse(Console.ReadLine());
  62.            return op;
  63.        }
  64.  
  65.        public static int MenuEliminar()
  66.        {
  67.            int op;
  68.            Console.Write("\n\t(1) Por Nombre");
  69.            Console.Write("\t(2) Por Posicion");
  70.            Console.Write("\t>>>Opcion: ");
  71.            op = int.Parse(Console.ReadLine());
  72.            return op;
  73.        }
  74.  
  75.        public static int MenuOrdenar()
  76.        {
  77.            int op;
  78.            Console.Write("\n\t(1) Ascendente");
  79.            Console.Write("\t(2) Descendente");
  80.            Console.Write("\t>>>Opcion:");
  81.            op = int.Parse(Console.ReadLine());
  82.            return op;
  83.        }
  84.  
  85.        public static int MenuBuscar()
  86.        {
  87.            int op;
  88.            Console.Write("\n\t(1) Por Nombre");
  89.            Console.Write("\t(2) Por Posicion");
  90.            Console.Write("\t>>>Opcion: ");
  91.            op = int.Parse(Console.ReadLine());
  92.            return op;
  93.        }
  94.  
  95.        public static void Insertar(ref string[,] alumno, ref int n)
  96.        {
  97.            int op, i,j;
  98.            op = MenuInsertar();
  99.            for (i = n; i < op + n; i++)
  100.            {
  101.                Console.WriteLine("\tALUMNO {0} ", i);
  102.                for (j = 0; j < 4; j++)
  103.                {
  104.                    if (j == 0)
  105.                    {
  106.                        Console.Write("\t\tNOMBRE   : ");
  107.                        alumno[i, j] = Console.ReadLine();
  108.                    }
  109.                    if (j == 1)
  110.                    {
  111.                        Console.Write("\t\tAPELLIDO : ");
  112.                        alumno[i, j] = Console.ReadLine();
  113.                    }
  114.                    if (j == 2)
  115.                    {
  116.                        Console.Write("\t\tEDAD     : ");
  117.                        alumno[i, j] = Console.ReadLine();
  118.                    }
  119.                    if (j == 3)
  120.                    {
  121.                        Console.Write("\t\tTELEFONO : ");
  122.                        alumno[i, j] = Console.ReadLine();
  123.                    }
  124.                }
  125.            }
  126.            n = op + n;
  127.        }
  128.  
  129.        public static void Eliminar(ref string[,] alumno, ref int n)
  130.        {
  131.            int op, p, i,j;
  132.            string valor;
  133.            op = MenuEliminar();
  134.            p = -1;
  135.            switch (op)
  136.            {
  137.                case 1:
  138.                    {
  139.                        Console.Write("Nombre:");
  140.                        valor = Console.ReadLine();
  141.                        for (i = 0; i < n; i++)
  142.                        {
  143.                            for (j = 0; j < 1; j++)
  144.                            {
  145.                                if (valor == alumno[i, j])
  146.                                {
  147.                                    p = i;
  148.                                }
  149.                            }
  150.                        }
  151.                        if (p >= 0)
  152.                        {
  153.                            for (i = p; i < n - 1; i++)
  154.                            {
  155.                                for (j = 0; j < 4; j++)
  156.                                {
  157.                                    if (j == 0)
  158.                                    {
  159.                                        alumno[i, j] = alumno[i + 1, j];
  160.                                    }
  161.                                    if (j == 1)
  162.                                    {
  163.                                        alumno[i, j] = alumno[i + 1, j];
  164.                                    }
  165.                                    if (j == 2)
  166.                                    {
  167.                                        alumno[i, j] = alumno[i + 1, j];
  168.                                    }
  169.                                    if (j == 3)
  170.                                    {
  171.                                        alumno[i, j] = alumno[i + 1, j];
  172.                                    }
  173.                               }
  174.                            }
  175.                            n--;
  176.  
  177.                            for (j = 0; j < 4; j++)
  178.                            {
  179.                                if (j == 0)
  180.                                {
  181.                                    alumno[n, j] = "";
  182.                                }
  183.                                if (j == 1)
  184.                                {
  185.                                    alumno[n, j] = "";
  186.                                }
  187.                                if (j == 2)
  188.                                {
  189.                                    alumno[n, j] = "";
  190.                                }
  191.                                if (j == 3)
  192.                                {
  193.                                    alumno[n, j] = "";
  194.                                }
  195.                            }
  196.                        }
  197.                        else
  198.                        {
  199.                            Console.WriteLine("Elemento No Encontrado");
  200.                        }
  201.                        break;
  202.                    }
  203.                case 2:
  204.                    {
  205.                        do
  206.                        {
  207.                            Console.Write("Posicion:");
  208.                            p = int.Parse(Console.ReadLine());
  209.                        } while (p >= n);
  210.                        if (p == n-1)
  211.                        {
  212.                            for (i = p; i < n - 1; i++)
  213.                            {
  214.                                for (j = 0; j < 4; j++)
  215.                                {
  216.                                    if (j == 0)
  217.                                    {
  218.                                        alumno[i, j] = alumno[i + 1, j];
  219.                                    }
  220.                                    if (j == 1)
  221.                                    {
  222.                                        alumno[i, j] = alumno[i + 1, j];
  223.                                    }
  224.                                    if (j == 2)
  225.                                    {
  226.                                        alumno[i, j] = alumno[i + 1, j];
  227.                                    }
  228.                                    if (j == 3)
  229.                                    {
  230.                                        alumno[i, j] = alumno[i + 1, j];
  231.                                    }
  232.                                }
  233.                            }
  234.                            n--;
  235.                            for (j = 0; j < 4; j++)
  236.                            {
  237.                                if (j == 0)
  238.                                {
  239.                                    alumno[n, j] = "";
  240.                                }
  241.                                if (j == 1)
  242.                                {
  243.                                    alumno[n, j] = "";
  244.                                }
  245.                                if (j == 2)
  246.                                {
  247.                                    alumno[n, j] = "";
  248.                                }
  249.                                if (j == 3)
  250.                                {
  251.                                    alumno[n, j] = "";
  252.                                }
  253.                            }                  
  254.                        }
  255.                        else
  256.                        {
  257.                            for (i = p; i < n - 1; i++)
  258.                            {
  259.                                for (j = 0; j < 4; j++)
  260.                                {
  261.  
  262.                                    if (j == 0)
  263.                                    {
  264.                                        alumno[i, j] = alumno[i + 1, j];
  265.                                    }
  266.                                    if (j == 1)
  267.                                    {
  268.                                        alumno[i, j] = alumno[i + 1, j];
  269.                                    }
  270.                                    if (j == 2)
  271.                                    {
  272.                                        alumno[i, j] = alumno[i + 1, j];
  273.                                    }
  274.                                    if (j == 3)
  275.                                    {
  276.                                        alumno[i, j] = alumno[i + 1, j];
  277.                                    }
  278.                                }
  279.  
  280.                            }
  281.                            n--;
  282.                            for (j = 0; j < 4; j++)
  283.                            {
  284.                                if (j == 0)
  285.                                {
  286.                                    alumno[n, j] = "";
  287.                                }
  288.                                if (j == 1)
  289.                                {
  290.                                    alumno[n, j] = "";
  291.                                }
  292.                                if (j == 2)
  293.                                {
  294.                                    alumno[n, j] = "";
  295.                                }
  296.                                if (j == 3)
  297.                                {
  298.                                    alumno[n, j] = "";
  299.                                }
  300.                            }                          
  301.                        }                      
  302.                        break;
  303.                    }
  304.                default: Console.WriteLine("\nOpcion invalida!!!"); break;
  305.            }
  306.        }
  307.  
  308.        public static void Buscar(ref string [,] alumno, ref int n)
  309.        {
  310.            int op, i, p,j;
  311.            string valor;
  312.            op = MenuBuscar();
  313.            //Metodo de Busqueda Secuencial
  314.            switch (op)
  315.            {
  316.                case 1:
  317.                    {
  318.                        Console.Write("Nombre:");
  319.                        valor = Console.ReadLine();
  320.                        for (i = 0; i < n; i++)
  321.                        {
  322.                            for (j = 0; j < 1; j++)
  323.                            {
  324.                                if (valor == alumno[i, j])
  325.                                {
  326.                                    Console.WriteLine("El Elemento Buscado se encuentra en la Posicion: {0}", i);
  327.                                }
  328.                            }
  329.  
  330.                        }
  331.                        break;
  332.                    }
  333.                case 2:
  334.                    {
  335.                        do
  336.                        {
  337.                            Console.Write("Posicion:");
  338.                            p = int.Parse(Console.ReadLine());
  339.                        } while (p >= n);
  340.                        for (i = 0; i < 100; i++)
  341.                        {
  342.                                if (i == p)
  343.                                {
  344.                                    Console.WriteLine("El alumno Buscado es: ");
  345.                                    for(j=0;j<4;j++)
  346.                                    {
  347.                                        if (j == 0)
  348.                                        {
  349.                                            Console.Write("NOMBRE: " + alumno[i, j]);
  350.                                        }
  351.                                        if (j == 1)
  352.                                        {
  353.                                            Console.Write("APELLIDO: " + alumno[i, j]);
  354.                                        }
  355.                                        if (j == 2)
  356.                                        {
  357.                                            Console.Write("EDAD: " + alumno[i, j]);
  358.                                        }
  359.                                        if (j == 3)
  360.                                        {
  361.                                            Console.Write("TELEFONO: " + alumno[i, j]);
  362.                                        }
  363.                                    }                                  
  364.                                }
  365.                        }        
  366.                        break;
  367.                    }
  368.                default: Console.WriteLine("\nOpcion invalida!!!"); break;
  369.            }
  370.        }
  371.  
  372.        /*public static void Ordenar(ref string[] Elementos, ref int n, ref int m)
  373.         {
  374.             int op, i, j, indice, k;
  375.             string Aux;
  376.             op = MenuOrdenar();
  377.             switch (op)
  378.             {
  379.                 case 1:
  380.                     {
  381.                         //Array.Sort(Elementos);
  382.                         //Metodo de Ordenamiento de Burbuja                        
  383.                         for (i = 0; i < n; i++)
  384.                         {
  385.                             indice = i;
  386.                             for (j = i + 1; j < n; j++)
  387.                             {
  388.                                 k = Elementos[j].CompareTo(Elementos[indice]);
  389.                                 if (k < 0)
  390.                                 {
  391.                                     indice = j;
  392.                                     if (i != indice)
  393.                                     {
  394.                                         Aux = Elementos[i];
  395.                                         Elementos[i] = Elementos[indice];
  396.                                         Elementos[indice] = Aux;
  397.                                     }
  398.                                 }
  399.                             }
  400.                         }
  401.                         break;
  402.                     }
  403.                 case 2:
  404.                     {
  405.                         //Array.Sort(Elementos); Array.Reverse(Elementos);
  406.                         for (i = 0; i < n; i++)
  407.                         {
  408.                             indice = i;
  409.                             for (j = i + 1; j < n; j++)
  410.                             {
  411.                                 k = Elementos[j].CompareTo(Elementos[indice]);
  412.                                 if (k > 0)
  413.                                 {
  414.                                     indice = j;
  415.                                     if (i != indice)
  416.                                     {
  417.                                         Aux = Elementos[i];
  418.                                         Elementos[i] = Elementos[indice];
  419.                                         Elementos[indice] = Aux;
  420.                                     }
  421.                                 }
  422.                             }
  423.                         }
  424.                         break;
  425.                     }
  426.                 default: Console.WriteLine("\nOpcion invalida!!!"); break;
  427.             }
  428.         }*/
  429.  
  430.        public static void Listar(ref string[,] alumno, ref int n)
  431.        {
  432.            int i,j;
  433.  
  434.            if (n > 0)
  435.            {
  436.                for (i = 0; i < n; i++)
  437.                {
  438.                    for (j = 0; j < 4; j++)
  439.                    {
  440.                        Console.Write(alumno[i,j]+" ");
  441.                    }
  442.                    Console.WriteLine();                      
  443.                }
  444.            }
  445.            else Console.WriteLine("\nLista Vacia!!!");
  446.        }
  447.    }
  448. }

la parte del ordenamiento no lo puedo hacer
osea tiene que ordenarse alfabeticamente por nombre o por apellido
aver kkien me puede ayudar!!!
« Última modificación: 12 Julio 2010, 16:41 pm por Novlucker » En línea

raul338


Desconectado Desconectado

Mensajes: 2.633


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: una ayuda en c sharp con ste ejemplo weno
« Respuesta #3 en: 12 Julio 2010, 16:37 pm »

A simple vista creo que esta bien, solo que en la parte de ordenar, deberias comprobar solo lo que se quiere ordenar no? :P



Código
  1. for (i = p; i < n - 1; i++)
  2. {
  3.    for (j = 0; j < 4; j++)
  4.    {
  5.  
  6.        if (j == 0)
  7.        {
  8.            alumno[i, j] = alumno[i + 1, j];
  9.        }
  10.        if (j == 1)
  11.        {
  12.            alumno[i, j] = alumno[i + 1, j];
  13.        }
  14.        if (j == 2)
  15.        {
  16.            alumno[i, j] = alumno[i + 1, j];
  17.        }
  18.        if (j == 3)
  19.        {
  20.            alumno[i, j] = alumno[i + 1, j];
  21.        }
  22.    }
  23.  
  24. }
  25. n--;
  26. for (j = 0; j < 4; j++)
  27. {
  28.    if (j == 0)
  29.    {
  30.        alumno[n, j] = "";
  31.    }
  32.    if (j == 1)
  33.    {
  34.        alumno[n, j] = "";
  35.    }
  36.    if (j == 2)
  37.    {
  38.        alumno[n, j] = "";
  39.    }
  40.    if (j == 3)
  41.    {
  42.        alumno[n, j] = "";
  43.    }
  44. }
  45.  

Las 2 partes se pueden resumir a una linea cada una, no entiendo porque comparas j, si en todos casos se hace lo mismo :huh:



Siempre pon el codigo entre las etiquetas code ([ code = chsarp]) (sin espacios o usa el selector GeShi)

PD: esto no deberia ir en la sección .net?
« Última modificación: 12 Julio 2010, 16:41 pm por raul338 » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
ayuda*¨ejercio c sharp « 1 2 »
.NET (C#, VB.NET, ASP)
XxFolkeNxX 12 4,765 Último mensaje 27 Noviembre 2011, 15:54 pm
por $Edu$
Ayuda mas Informacion de SharpKit en C SHARP
.NET (C#, VB.NET, ASP)
ematrix 0 1,423 Último mensaje 12 Marzo 2013, 16:56 pm
por ematrix
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines