Sayıyı Yazıya Çeviren Uygulama[C#] Google'da Ara Büyüt Küçült

Genişlet
04 Nisan 2010 – 10:10

Rakamlarla girilen yazıyı sayıyıa çeviren program.Basit ve anlaşılır kodlama başlangıç için güzel örnek.

sayiyazi Sayıyı Yazıya Çeviren Uygulama[C#]

Kodlar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace YazıyaÇevir
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.Label label1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.button1 = new System.Windows.Forms.Button();
   this.label1 = new System.Windows.Forms.Label();
   this.SuspendLayout();
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point(8, 24);
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(200, 20);
   this.textBox1.TabIndex = 0;
   this.textBox1.Text = "textBox1";
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(216, 24);
   this.button1.Name = "button1";
   this.button1.TabIndex = 1;
   this.button1.Text = "Çevir";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // label1
   //
   this.label1.AutoSize = true;
   this.label1.Location = new System.Drawing.Point(8, 56);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(35, 13);
   this.label1.TabIndex = 2;
   this.label1.Text = "label1";
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   this.ClientSize = new System.Drawing.Size(292, 94);
   this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                              this.label1,
                                                              this.button1,
                                                              this.textBox1});
   this.Name = "Form1";
   this.Text = "Form1";
   this.Load += new System.EventHandler(this.Form1_Load);
   this.ResumeLayout(false);

  }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

  string çevir(string sayı)
  {
   int max_basamak_say = 18; //18 basamaklı-katrilyon, daha da artırılabilir
   string[] birler =  { "", "bir", "iki", "üç", "dört", "beş", "altı",
                       "yedi", "sekiz", "dokuz"};
   string[] onlar  = { "", "on", "yirmi", "otuz", "kırk", "elli", "altmış",
                       "yetmiş", "seksen", "doksan"};
   //Eğer 18 basamaktan daha fazla kullanacaksanız
   //katrilyondan önce o basamakları da ekleyin
   string[] binler = {"katrilyon", "trilyon", "milyar", "milyon", "bin", ""};
   int i, uz ;
   int[] bas = new int[3];
   string sonuç="", ara_sonuç="";
   uz = sayı.Length;
   //sayının kullanılmayan basamaklarını sıfırla doldur
   sayı = sayı.PadLeft(max_basamak_say, '0');
   //sayıyı üçerli basamaklar halinde ele al
   for (i = 0 ; i < = max_basamak_say / 3 - 1 ; i++)
   {
    //üçlü basamaktaki birinci sayı yani yüzler basamağı
    bas[0] = int.Parse(sayı.Substring(i * 3, 1));
    //üçlü basamaktaki ikinci sayı yani onlar basamağı
    bas[1] = int.Parse(sayı.Substring((i * 3) + 1, 1));
    //üçlü basamaktaki üçüncü sayı yani birler basamağı
    bas[2] = int.Parse(sayı.Substring((i * 3) + 2, 1));
    if (bas[0] == 0)
     ara_sonuç = ""; //yüzler basamağı boş
    else
     if (bas[0] == 1)
     ara_sonuç = "yüz"; //yüzler basamağında 1 varsa 1 yüz olmaz sadece yüz
    else
     ara_sonuç = birler[bas[0]] + "yüz"; //yüzler basamağındaki sayı ve yüz
    //ikiyüz gibi
    //yüzler+onlar+birler basamağını birleştir
    ara_sonuç = ara_sonuç + onlar[bas[1]] + birler[bas[2]];
    //basamak değeri oluşmadıysa yani 000 ise binler basamağını ekle
    if (ara_sonuç != "")
     ara_sonuç = ara_sonuç + binler[i];
    //birbin olmaz
    if ((i > 1) && (ara_sonuç == "birbin"))
     ara_sonuç = "bin";
    if (ara_sonuç != "")
     sonuç = sonuç + ara_sonuç + " ";
   }
   if (sonuç.Trim() == "")
    sonuç = "sıfır";
   return sonuç.Trim();
  }

  private void button1_Click(object sender, System.EventArgs e)
  {
   try
   {
    label1.Text = çevir(textBox1.Text);
   }
   catch
   {
    MessageBox.Show("Geçersiz sayı");
   }
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {
   this.AcceptButton=button1;
  }
    }
}

Linkler
RapidShare
SendSpace
Csharptr

Etiketler Etiketler: ”,

Benzer Yazılar

Yorum Yap

Isim : (gerekli)
E-mail : (gerekli)
Yorumunuz: