Смекни!
smekni.com

Обучающая программа по информатике (стр. 9 из 11)

private System.Windows.Forms.TextBox textBox5;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.Button button3;

private System.Windows.Forms.Button button4;

private System.Windows.Forms.Button button5;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.Label label4;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Label label5;

private System.Windows.Forms.GroupBox groupBox1;

private System.Windows.Forms.ToolTip toolTip1;

private System.ComponentModel.IContainer components;

public Hemming(){InitializeComponent();}

protected override void Dispose( bool disposing )

{

if(disposing) if(components != null) components.Dispose();

base.Dispose(disposing);

}

public void Generation()

{

X=1;

textBox1.Text="";

Random r=new System.Random();

int d;

for (int i=1; i<10; i++)

{

d=r.Next(0,2);

textBox1.Text+=d;

x[i]=d;

}

}

public void Number()

{

int x1=0;int x2=0;int x3=0;int x4=0;

x1=x[1]+x[3]+x[5]+x[7]+x[9];

if (x1==0 || x1==2 || x1==4) x1=0; else x1=1;

x2=x[2]+x[3]+x[6]+x[7];

if (x2==0 || x2==2 || x2==4) x2=0; else x2=1;

x3=x[4]+x[5]+x[6]+x[7];

if (x3==0 || x3==2 || x3==4) x3=0; else x3=1;

x4=x[8]+x[9];

if (x4==0 || x4==2) x4=0;else x4=1;

Nomer=x4*1000+x3*100+x2*10+x1;

}

public void Otvet(){textBox3.Text = x[1] + "" + x[2] + "" + x[3] + "" + x[4] + "" + x[5] + "" + x[6] + "" + x[7] + "" + x[8] + "" + x[9];}

public void Sravnenie()

{

if (X==1)

{

int i=0;

if (Nomer == 1) i = 1;

if (Nomer == 10) i = 2;

if (Nomer == 11) i = 3;

if (Nomer == 100) i = 4;

if (Nomer == 101) i = 5;

if (Nomer == 110) i = 6;

if (Nomer == 111) i = 7;

if (Nomer == 1000) i = 8;

if (Nomer == 1001) i = 9;

if (i!=0)

{

if (x[i] == 0)

{

x[i] = 1; Otvet();

}

else

{

x[i] = 0; Otvet();

}

}

}

}

public void Proverka()

{

if(textBox2.Text.Length!=textBox1.Text.Length && textBox1.Text.Length!=textBox3.Text.Length)

{

A5=new Error("Исправленный вариант должен содержать 9-ти разрядное двоичное число");

A5.ShowDialog();

X=0;

}

else

{

if(textBox1.Text.Length!=textBox3.Text.Length)

{

for(int i=0; i<textBox2.Text.Length; i++)

{

string a="1";

string b="0";

string d=textBox2.Text.Substring(i,1);

if(d!=b && d!=a)

{

A5=new Error("Исправленный вариант должен содержать 9-ти разрядное двоичное число");

A5.ShowDialog();

X=0;

i=textBox2.Text.Length;

}

else X=1;

}

}

}

}

#region Windows Form Designer generated code

private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Hemming));

this.textBox1 = new System.Windows.Forms.TextBox();

this.textBox2 = new System.Windows.Forms.TextBox();

this.textBox3 = new System.Windows.Forms.TextBox();

this.textBox4 = new System.Windows.Forms.TextBox();

this.textBox5 = new System.Windows.Forms.TextBox();

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.button3 = new System.Windows.Forms.Button();

this.button4 = new System.Windows.Forms.Button();

this.button5 = new System.Windows.Forms.Button();

this.label3 = new System.Windows.Forms.Label();

this.label4 = new System.Windows.Forms.Label();

this.label1 = new System.Windows.Forms.Label();

this.label2 = new System.Windows.Forms.Label();

this.label5 = new System.Windows.Forms.Label();

this.groupBox1 = new System.Windows.Forms.GroupBox();

this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);

this.groupBox1.SuspendLayout();

this.SuspendLayout();

//

// textBox1

//

this.textBox1.Location = new System.Drawing.Point(216, 16);

this.textBox1.Name = "textBox1";

this.textBox1.ReadOnly = true;

this.textBox1.Size = new System.Drawing.Size(88, 20);

this.textBox1.TabIndex = 0;

this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

//

// textBox2

//

this.textBox2.Location = new System.Drawing.Point(216, 40);

this.textBox2.MaxLength = 9;

this.textBox2.Name = "textBox2";

this.textBox2.Size = new System.Drawing.Size(88, 20);

this.textBox2.TabIndex = 1;

this.textBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

//

// textBox3

//

this.textBox3.Location = new System.Drawing.Point(216, 64);

this.textBox3.Name = "textBox3";

this.textBox3.ReadOnly = true;

this.textBox3.Size = new System.Drawing.Size(88, 20);

this.textBox3.TabIndex = 2;

this.textBox3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

//

// textBox4

//

this.textBox4.Location = new System.Drawing.Point(104, 136);

this.textBox4.Name = "textBox4";

this.textBox4.ReadOnly = true;

this.textBox4.Size = new System.Drawing.Size(40, 20);

this.textBox4.TabIndex = 3;

this.textBox4.Text = "1";

this.textBox4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

//

// textBox5

//

this.textBox5.Location = new System.Drawing.Point(272, 136);

this.textBox5.Name = "textBox5";

this.textBox5.ReadOnly = true;

this.textBox5.Size = new System.Drawing.Size(40, 20);

this.textBox5.TabIndex = 4;

this.textBox5.Text = "0";

this.textBox5.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

//

// button1

//

this.button1.Location = new System.Drawing.Point(8, 102);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(88, 24);

this.button1.TabIndex = 5;

this.button1.Text = "Ошибки нет";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// button2

//

this.button2.Location = new System.Drawing.Point(108, 102);

this.button2.Name = "button2";

this.button2.Size = new System.Drawing.Size(88, 24);

this.button2.TabIndex = 6;

this.button2.Text = "Ошибка есть";

this.button2.Click += new System.EventHandler(this.button2_Click);

//

// button3

//

this.button3.Location = new System.Drawing.Point(206, 101);

this.button3.Name = "button3";

this.button3.Size = new System.Drawing.Size(112, 24);

this.button3.TabIndex = 7;

this.button3.Text = "Следующее число";

this.button3.Click += new System.EventHandler(this.button3_Click);

//

// button4

//

this.button4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));

this.button4.Location = new System.Drawing.Point(128, 160);

this.button4.Name = "button4";

this.button4.Size = new System.Drawing.Size(72, 24);

this.button4.TabIndex = 11;

this.button4.Text = "Справка";

this.button4.Click += new System.EventHandler(this.button4_Click);

//

// button5

//

this.button5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));

this.button5.Location = new System.Drawing.Point(80, 192);

this.button5.Name = "button5";

this.button5.Size = new System.Drawing.Size(168, 24);

this.button5.TabIndex = 12;

this.button5.Text = "Вернуться к выбору темы";

this.button5.Click += new System.EventHandler(this.button5_Click);

//

// label3

//

this.label3.Location = new System.Drawing.Point(8, 136);

this.label3.Name = "label3";

this.label3.Size = new System.Drawing.Size(96, 24);

this.label3.TabIndex = 13;

this.label3.Text = "Номер вопроса:";

//

// label4

//

this.label4.Location = new System.Drawing.Point(152, 136);

this.label4.Name = "label4";

this.label4.Size = new System.Drawing.Size(120, 24);

this.label4.TabIndex = 14;

this.label4.Text = "Правильных ответов:";

//

// label1

//

this.label1.Location = new System.Drawing.Point(8, 16);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(216, 16);

this.label1.TabIndex = 15;

this.label1.Text = "Число, возможно содержащее ошибку";

//

// label2

//

this.label2.Location = new System.Drawing.Point(8, 40);

this.label2.Name = "label2";

this.label2.Size = new System.Drawing.Size(128, 16);

this.label2.TabIndex = 16;

this.label2.Text = "Исправленный вариант";

//

// label5

//

this.label5.Location = new System.Drawing.Point(8, 64);

this.label5.Name = "label5";

this.label5.Size = new System.Drawing.Size(112, 16);

this.label5.TabIndex = 17;

this.label5.Text = "Правильный ответ";

//

// groupBox1

//

this.groupBox1.Controls.Add(this.label2);

this.groupBox1.Controls.Add(this.textBox3);

this.groupBox1.Controls.Add(this.label5);

this.groupBox1.Controls.Add(this.textBox1);

this.groupBox1.Controls.Add(this.textBox2);

this.groupBox1.Controls.Add(this.label1);

this.groupBox1.Location = new System.Drawing.Point(6, -1);

this.groupBox1.Name = "groupBox1";

this.groupBox1.Size = new System.Drawing.Size(312, 96);

this.groupBox1.TabIndex = 19;

this.groupBox1.TabStop = false;

this.toolTip1.SetToolTip(this.groupBox1, @"9-ти разрядное двоичное число, закодированно по методу Хэмминга. В одном из разрядов"+"&bsol;n"+"возможно присутствует ошибка. Если она есть, необходимо её исправить и записать правильный"+"&bsol;n"+"вариант в соответствующее окно, после этого нажмите кнопку «Ошибка есть».Если ошибка"+"&bsol;n"+"отсутствует, то в окно Исправленный вариант ничего писать не нужно и следуетнажать"+"&bsol;n"+"кнопку «Ошибки нет». Далее нужно нажать кнопку «Cледующее число»");

//

// toolTip1

//

this.toolTip1.AutomaticDelay = 10;

this.toolTip1.AutoPopDelay = 100000;

this.toolTip1.InitialDelay = 10;

this.toolTip1.ReshowDelay = 2;

this.toolTip1.ShowAlways = true;

//

// Hemming

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.BackColor = System.Drawing.SystemColors.InactiveBorder;

this.ClientSize = new System.Drawing.Size(322, 224);

this.ControlBox = false;

this.Controls.Add(this.groupBox1);

this.Controls.Add(this.label4);

this.Controls.Add(this.label3);

this.Controls.Add(this.button5);

this.Controls.Add(this.button4);

this.Controls.Add(this.button3);

this.Controls.Add(this.button2);

this.Controls.Add(this.button1);

this.Controls.Add(this.textBox5);

this.Controls.Add(this.textBox4);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

this.MaximizeBox = false;

this.Name = "Hemming";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "Hemming";

this.TopMost = true;

this.Load += new System.EventHandler(this.Hemming_Load);

this.groupBox1.ResumeLayout(false);

this.groupBox1.PerformLayout();

this.ResumeLayout(false);

this.PerformLayout();

}

#endregion

private void Hemming_Load(object sender, System.EventArgs e)

{

Generation();

Number();

}

private void button1_Click(object sender, System.EventArgs e)

{

textBox2.Text="";

if(textBox1.Text.Length!=textBox3.Text.Length) X=1;

if (X==1)textBox3.Text="";

int Prav=Convert.ToInt32(textBox5.Text);

if (X==1)

{

if (Nomer==0)

{

Prav++; Otvet();

}

Sravnenie();

if (textBox3.Text.Length==0)

{

Prav++; Otvet();

}

textBox5.Text=""; textBox5.Text+=Prav;

}

X=0;

}

private void button2_Click(object sender, System.EventArgs e)

{

Proverka();

if(X==1)textBox3.Text="";

int Prav=Convert.ToInt32(textBox5.Text);

if (X==1)

{

if (Nomer==0) Otvet();

Sravnenie();

if (textBox3.Text.Length==0) Otvet();

int Moe=Convert.ToInt32(textBox2.Text);

int Pravilnoe=Convert.ToInt32(textBox3.Text);

if (Moe==Pravilnoe) Prav++;

textBox5.Text="";

textBox5.Text+=Prav;

}

X=0;

}

private void button4_Click(object sender, System.EventArgs e)

{

A4 = new Help(2);

A4.ShowDialog();

}

private void button5_Click(object sender, System.EventArgs e){this.Close();}

private void button3_Click(object sender, System.EventArgs e)

{

ChVoprosov++;

textBox2.Text="";

textBox3.Text="";

textBox4.Text="";

textBox4.Text+=ChVoprosov;

Generation();

Number();

}

}

}

Even_ueven

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

namespace Study_Programs

{

public class Even_uneven : System.Windows.Forms.Form

{

int Prav;

int ch;

int ChVoprosov=1;

Help A4;

private System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.TextBox textBox2;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.TextBox textBox3;

private System.Windows.Forms.TextBox textBox4;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.Label label4;

private System.Windows.Forms.Button button3;

private System.Windows.Forms.Button button4;

private System.Windows.Forms.Label label6;

private System.Windows.Forms.GroupBox groupBox1;

private System.ComponentModel.Container components = null;

public Even_uneven(){InitializeComponent();}

protected override void Dispose( bool disposing )

{

if( disposing ) if(components != null) components.Dispose();

base.Dispose( disposing );

}

public void Generation()

{

textBox1.Text="";

Random r=new System.Random();

int d;

for (int i=0; i<7; i++)

{

d=r.Next(0,2);

textBox1.Text+=d;

ch+=d;

}

textBox2.Text="";

int g=r.Next(0,2);

textBox2.Text+=g;

ch+=g;

}

public void ChangeChVoprosov()

{

ChVoprosov++;

textBox3.Text="";

textBox3.Text+=ChVoprosov;

}

public void ChangePrav()

{

textBox4.Text="";

textBox4.Text+=Prav;

}

#region Windows Form Designer generated code

private void InitializeComponent()

{

this.textBox1 = new System.Windows.Forms.TextBox();

this.button1 = new System.Windows.Forms.Button();

this.textBox2 = new System.Windows.Forms.TextBox();