Advertisement
gersy

Vowel_letter_class

Jan 19th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Let
  11. {
  12.     public partial class MainForm : Form
  13.     {
  14.         List<char> VOWELS = new List<char>();
  15.         public  bool Is_Vowel(char a)
  16.         {
  17.             if (char.IsUpper(a))
  18.                 a = char.ToLower(a);
  19.             return VOWELS.Contains(a);
  20.         }
  21.         public MainForm()
  22.         {
  23.             InitializeComponent();
  24.             VOWELS.Add('a');
  25.             VOWELS.Add('e');
  26.             VOWELS.Add('i');
  27.             VOWELS.Add('u');
  28.             VOWELS.Add('o');
  29.         }
  30.  
  31.         private void btn_ex_Click(object sender, EventArgs e)
  32.         {
  33.             this.Close();
  34.         }
  35.  
  36.         private void MainForm_Load(object sender, EventArgs e)
  37.         {
  38.  
  39.         }
  40.        
  41.  
  42.         private void btn_dis_Freq_Click(object sender, EventArgs e)
  43.         {
  44.  
  45.             if (textBox1.Text.Length < 1) return; /// return if text is empty
  46.             string sentence = textBox1.Text;
  47.             string res="";
  48.             foreach (char a in sentence)
  49.            
  50.                 if(Is_Vowel(a))
  51.                     res+=("'"+a.ToString()+"'  >>>>> "+Letter.Frequency(a)+"%"+Environment.NewLine);
  52.  
  53.             MessageBox.Show(res);
  54.              }
  55.  
  56.         private void conv_to_up_Click(object sender, EventArgs e)
  57.         {
  58.             string res="";
  59.             foreach (char a in textBox1.Text)
  60.             {
  61.                 if (Is_Vowel(a))
  62.                     res += (char.ToUpper(a)).ToString();
  63.                 else
  64.                 res += a.ToString();
  65.             }
  66.             textBox1.Text = res;
  67.         }
  68.  
  69.         private void conv_to_low_Click(object sender, EventArgs e)
  70.         {
  71.             string res = "";
  72.             foreach (char a in textBox1.Text)
  73.             {
  74.                 if (Is_Vowel(a))
  75.                     res += (char.ToLower(a)).ToString();
  76.                 else
  77.                     res += a.ToString();
  78.             }
  79.             textBox1.Text = res;
  80.         }
  81.  
  82.         private void btn_start_end_Click(object sender, EventArgs e)
  83.         {
  84.             if (textBox1.Text.Length < 1) return; /// return if text is empty
  85.          
  86.             bool is_start_with_vowel=false;
  87.             bool is_End_with_vowel=false;
  88.             int last_index = textBox1.Text.Length-1;
  89.            
  90.             is_start_with_vowel= Is_Vowel(textBox1.Text[0]);
  91.             is_End_with_vowel=Is_Vowel(textBox1.Text[last_index]);
  92.  
  93.             if (is_start_with_vowel && is_End_with_vowel)
  94.                 MessageBox.Show("Start and end with Vowel ");
  95.             else if (is_start_with_vowel && !is_End_with_vowel)
  96.                 MessageBox.Show("Start With Vowel ");
  97.             else if (!is_start_with_vowel &&  is_End_with_vowel)
  98.             MessageBox.Show("End With Vowel ");
  99.             else MessageBox.Show("No Vowel in start or end");
  100.         }
  101.  
  102.         private void btn_vowel_Loc_Click(object sender, EventArgs e)
  103.         {
  104.             if (textBox1.Text.Length < 1) return; /// return if text is empty
  105.            
  106.             string res = "";
  107.             string v = textBox1.Text;
  108.  
  109.             for (int i = 0; i < v.Length; i++)
  110.  
  111.                 if (Is_Vowel(v[i]))
  112.                     res += (v[i].ToString() + " at index of " + i.ToString() + Environment.NewLine);
  113.             MessageBox.Show(v+Environment.NewLine+res,"Location Of Vowel");
  114.         }
  115.  
  116.         private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  117.         {
  118.             System.Diagnostics.Process.Start("http://en.wikipedia.org/wiki/Letter_frequency");
  119.         }
  120.        
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement