Guest

parcial 4

By: a guest on May 16th, 2010  |  syntax: C#  |  size: 7.28 KB  |  hits: 218  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. /*Desarrollar un programa en C# para capturar una frase entre una y 10 palabras para luego determinar
  5.  * e imprimir lo siguiente:
  6.  * # de letras vocales total en la frase
  7.  * # de consonantes total en la frase
  8.  * # de vocales A,a,á en la frase
  9.  * # de vocales E,e,é en la frase
  10.  * # de vocales I,i,í en la frase
  11.  * # de vocales O,o,ó en la frase
  12.  * # de vocales U,u,ú en la frase
  13.  * # de caracteres no vocales, ni consonantes total en la frase
  14.  * # de palabras que inician con letra mayusculas en la frase.
  15.  * */
  16. namespace parcial_4
  17. {
  18.     class Program
  19.     {
  20.         static void Main(string[] args)
  21.         {
  22.             int I, Pal, B = 0, Esp, Caract, conta = 0, conte = 0, conti = 0, conto = 0, contu = 0, conts = 0, a = 0;
  23.             string F="";
  24.             Console.Write("\n\nPrograma que analiza una frase ingresada\n\n");
  25.             do
  26.             {
  27.                 Console.Write("Ingrese la frase: ");
  28.                 F = Console.ReadLine();
  29.                 a = F.Length;
  30.                 while (a == 0)
  31.                 {
  32.                  Console.WriteLine("\n No introdujo ninguna frase, ");
  33.                  Console.Write("Ingrese la frase: ");
  34.                  F = Console.ReadLine();
  35.                  a = F.Length;
  36.                 }
  37.  
  38.                 char[] aux = F.ToCharArray();
  39.                 Esp = 0;
  40.                 Pal = 0;
  41.                 I = 0;
  42.                 Caract = 0;
  43.                 while ((I != F.Length) && (Esp < 2))
  44.                 {
  45.                     if (aux[I] == ' ')
  46.                     {
  47.                         if (B == 1)
  48.                         {
  49.                             Pal = Pal + 1;
  50.                             B = 0;
  51.                         }
  52.                         Esp = Esp + 1;
  53.                     }
  54.                     else
  55.                     {
  56.                         B = 1;
  57.                         Esp = 0;
  58.                         Caract++;
  59.                     }
  60.                     I++;
  61.                 }
  62.                 if ((I == F.Length) && (aux[I - 1] != ' '))
  63.                 {
  64.                     Pal++;
  65.                 }
  66.                 if (Esp > 1)
  67.                 {
  68.                     Console.WriteLine("\n Introdujo una frase con dos o mas espacios juntos, ");
  69.                     Console.WriteLine("tendrá que ingresar la frase nuevamente.\n");
  70.                 }
  71.                 if (Pal > 10)
  72.                 {
  73.                     Console.WriteLine("\nIntrodujo una frase con una cantidad de palabras inválida, ");
  74.                     Console.WriteLine("\n Ingrese otra frase.\n");
  75.                 }
  76.  
  77.             }
  78.             while (Esp > 1 || Pal > 10);
  79.            
  80.             Console.Write("\n La frase original es: ");
  81.             Console.Write("\n" + F + "\n");
  82.             Console.WriteLine("\nCantidad de Palabras: " + Pal);
  83.             Console.WriteLine();
  84.             string[] Frase = F.Split(new char[] { ' ' });
  85.             int mayu = 0, contc = 0;
  86.            
  87.             I = 0;
  88.             foreach (string Palabra in Frase)
  89.             {
  90.                 bool x;
  91.                 char[] arreglo = Palabra.ToCharArray();
  92.                 int con;
  93.                 con = arreglo.Length;
  94.                 x = char.IsUpper(arreglo[0]);
  95.                     if (x == true)
  96.                     {
  97.                         mayu = mayu + 1;
  98.                     }
  99.                
  100.                 for (I = 0; I < con; I++)
  101.                 {
  102.                    
  103.  
  104.                     if ((arreglo[I] == 'A') || (arreglo[I] == 'a') || (arreglo[I] == 'á'))
  105.                     {
  106.                         conta = conta + 1;
  107.                     }
  108.                     else
  109.                     {
  110.                         if ((arreglo[I] == 'E') || (arreglo[I] == 'e') || (arreglo[I] == 'é'))
  111.                         {
  112.                             conte = conte + 1;
  113.  
  114.                         }
  115.                         else
  116.                         {
  117.                             if ((arreglo[I] == 'I') || (arreglo[I] == 'i') || (arreglo[I] == 'í'))
  118.                             {
  119.                                 conti = conti + 1;
  120.                             }
  121.                             else
  122.                             {
  123.                                 if ((arreglo[I] == 'O') || (arreglo[I] == 'o') || (arreglo[I] == 'ó'))
  124.                                 {
  125.                                     conto = conto + 1;
  126.                                 }
  127.                                 else
  128.                                 {
  129.                                     if ((arreglo[I] == 'U') || (arreglo[I] == 'u') || (arreglo[I] == 'ú'))
  130.                                     {
  131.                                         contu = contu + 1;
  132.                                     }
  133.                                     else
  134.                                     {
  135.                                         if ((arreglo[I] == 'B') || (arreglo[I] == 'b') || (arreglo[I] == 'C') || (arreglo[I] == 'c') || (arreglo[I] == 'D') || (arreglo[I] == 'd') || (arreglo[I] == 'F') || (arreglo[I] == 'f') || (arreglo[I] == 'G') || (arreglo[I] == 'g') || (arreglo[I] == 'H') || (arreglo[I] == 'h') || (arreglo[I] == 'J') || (arreglo[I] == 'j') || (arreglo[I] == 'K') || (arreglo[I] == 'k') || (arreglo[I] == 'L') || (arreglo[I] == 'l') || (arreglo[I] == 'M') || (arreglo[I] == 'm') || (arreglo[I] == 'N') || (arreglo[I] == 'n') || (arreglo[I] == 'Ñ') || (arreglo[I] == 'ñ') || (arreglo[I] == 'P') || (arreglo[I] == 'p') || (arreglo[I] == 'Q') || (arreglo[I] == 'q') || (arreglo[I] == 'R') || (arreglo[I] == 'r') || (arreglo[I] == 'S') || (arreglo[I] == 's') || (arreglo[I] == 'T') || (arreglo[I] == 't') || (arreglo[I] == 'V') || (arreglo[I] == 'v') || (arreglo[I] == 'W') || (arreglo[I] == 'w') || (arreglo[I] == 'X') || (arreglo[I] == 'x') || (arreglo[I] == 'Y') || (arreglo[I] == 'y') || (arreglo[I] == 'Z') || (arreglo[I] == 'z'))
  136.                                         {
  137.                                             contc = contc + 1;
  138.                                         }
  139.                                         else
  140.                                         {
  141.                                             conts = conts + 1;
  142.                                         }
  143.                                     }
  144.  
  145.                                 }
  146.                             }
  147.                         }
  148.                     }
  149.                 }
  150.  
  151.             }
  152.  
  153.             Console.WriteLine("Cantidad de Vocales A,a,á = " + conta);
  154.             Console.WriteLine("Cantidad de Vocales E,e,é = " + conte);
  155.             Console.WriteLine("Cantidad de Vocales I,i,í = " + conti);
  156.             Console.WriteLine("Cantidad de Vocales O,o,ó = " + conto);
  157.             Console.WriteLine("Cantidad de Vocales U,u,ú = " + contu);
  158.             Console.WriteLine("Cantidad de Consonantes =" + contc);
  159.             Console.WriteLine("Cantidad de caracteres que no son consonantes ni vocales =" + conts);
  160.             int totalv = 0;
  161.             totalv = conta + conte + conti + conto + contu;
  162.  
  163.             Console.WriteLine("Cantidad Total de Vocales =" + totalv);
  164.             Console.WriteLine("Cantidad de Palabras que empiezan con mayuscula=" + mayu);
  165.             Console.ReadLine();
  166.  
  167.  
  168.         }
  169.     }
  170. }