Смекни!
smekni.com

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

this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

//

// groupBox1

//

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

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

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

this.groupBox1.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

this.groupBox1.Location = new System.Drawing.Point(8, 48);

this.groupBox1.Name = "groupBox1";

this.groupBox1.Size = new System.Drawing.Size(296, 120);

this.groupBox1.TabIndex = 1;

this.groupBox1.TabStop = false;

this.groupBox1.Text = "Выберите раздел";

//

// hemming_button

//

this.hemming_button.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.hemming_button.Cursor = System.Windows.Forms.Cursors.Hand;

this.hemming_button.Location = new System.Drawing.Point(8, 89);

this.hemming_button.Name = "hemming_button";

this.hemming_button.Size = new System.Drawing.Size(280, 22);

this.hemming_button.TabIndex = 2;

this.hemming_button.Text = "Кодирование по методу Хэмминга";

this.hemming_button.Click += new System.EventHandler(this.hemming_button_Click);

//

// post_button

//

this.post_button.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.post_button.Cursor = System.Windows.Forms.Cursors.Hand;

this.post_button.Location = new System.Drawing.Point(8, 25);

this.post_button.Name = "post_button";

this.post_button.Size = new System.Drawing.Size(280, 22);

this.post_button.TabIndex = 0;

this.post_button.Text = "Программирование машины Поста";

this.post_button.Click += new System.EventHandler(this.post_button_Click);

//

// even_uneven_button

//

this.even_uneven_button.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.even_uneven_button.Cursor = System.Windows.Forms.Cursors.Hand;

this.even_uneven_button.Location = new System.Drawing.Point(8, 56);

this.even_uneven_button.Name = "even_uneven_button";

this.even_uneven_button.Size = new System.Drawing.Size(280, 22);

this.even_uneven_button.TabIndex = 1;

this.even_uneven_button.Text = "Кодирование по методу четности\нечетности";

this.even_uneven_button.Click += new System.EventHandler(this.even_uneven_button_Click);

//

// exit_button

//

this.exit_button.Cursor = System.Windows.Forms.Cursors.Hand;

this.exit_button.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

this.exit_button.Location = new System.Drawing.Point(112, 176);

this.exit_button.Name = "exit_button";

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

this.exit_button.TabIndex = 2;

this.exit_button.Text = "Выход";

this.exit_button.Click += new System.EventHandler(this.exit_button_Click);

//

// Start

//

this.AutoScale = false;

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

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

this.ClientSize = new System.Drawing.Size(306, 206);

this.ControlBox = false;

this.Controls.Add(this.exit_button);

this.Controls.Add(this.groupBox1);

this.Controls.Add(this.label1);

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

this.MaximizeBox = false;

this.MinimizeBox = false;

this.Name = "Start";

this.ShowInTaskbar = false;

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

this.Text = "Study Programs";

this.TopMost = true;

this.groupBox1.ResumeLayout(false);

this.ResumeLayout(false);

}

#endregion

[STAThread]

static void Main() {Application.Run(new Start());}

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

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

{

A1 = new Post();

A1.ShowDialog();

}

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

{

A2 = new Even_uneven();

A2.ShowDialog();

}

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

{

A3 = new Hemming();

A3.ShowDialog();

}

}

}

Post

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

namespace Study_Programs

{

public class Post : System.Windows.Forms.Form

{

private System.Windows.Forms.Label label1;

private System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.TextBox textBox2;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.TextBox textBox3;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.Button button3;

private System.ComponentModel.Container components = null;

private System.Windows.Forms.Button help;

Help A4;Error A5;

static char []input;

static char [][] command;

static byte l,finish,k;

static sbyte position;

static bool chk=true;

public Post(){InitializeComponent();}

protected override void Dispose(bool disposing)

{

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

base.Dispose(disposing);

}

#region Windows Form Designer generated code

private void InitializeComponent()

{

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

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

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

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

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

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

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

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

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

this.SuspendLayout();

//

// label1

//

this.label1.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

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

this.label1.Name = "label1";

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

this.label1.TabIndex = 0;

this.label1.Text = "Входная строка машины Поста";

//

// textBox1

//

this.textBox1.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

this.textBox1.Location = new System.Drawing.Point(8, 24);

this.textBox1.Name = "textBox1";

this.textBox1.Size = new System.Drawing.Size(224, 21);

this.textBox1.TabIndex = 1;

this.textBox1.Text = "Введите строку, состоящую из 0 и 1";

//

// label2

//

this.label2.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

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

this.label2.Name = "label2";

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

this.label2.TabIndex = 2;

this.label2.Text = "Список команд";

//

// textBox2

//

this.textBox2.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

this.textBox2.Location = new System.Drawing.Point(8, 72);

this.textBox2.Name = "textBox2";

this.textBox2.Size = new System.Drawing.Size(224, 21);

this.textBox2.TabIndex = 3;

this.textBox2.Text = "Введите список команд";

//

// label3

//

this.label3.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

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

this.label3.Name = "label3";

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

this.label3.TabIndex = 4;

this.label3.Text = "Выходная строка";

//

// textBox3

//

this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.None;

this.textBox3.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

this.textBox3.Location = new System.Drawing.Point(8, 120);

this.textBox3.Name = "textBox3";

this.textBox3.ReadOnly = true;

this.textBox3.Size = new System.Drawing.Size(224, 14);

this.textBox3.TabIndex = 5;

this.textBox3.Text = "";

//

// help

//

this.help.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

this.help.Location = new System.Drawing.Point(136, 144);

this.help.Name = "help";

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

this.help.TabIndex = 8;

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

this.help.Click += new System.EventHandler(this.help_Click);

//

// button2

//

this.button2.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

this.button2.Location = new System.Drawing.Point(40, 176);

this.button2.Name = "button2";

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

this.button2.TabIndex = 9;

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

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

//

// button3

//

this.button3.Font = new System.Drawing.Font("MS Reference Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(204)));

this.button3.Location = new System.Drawing.Point(40, 144);

this.button3.Name = "button3";

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

this.button3.TabIndex = 10;

this.button3.Text = "GO";

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

//

// Post

//

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

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

this.ClientSize = new System.Drawing.Size(242, 208);

this.ControlBox = false;

this.Controls.Add(this.button3);

this.Controls.Add(this.button2);

this.Controls.Add(this.help);

this.Controls.Add(this.textBox3);

this.Controls.Add(this.label3);

this.Controls.Add(this.textBox2);

this.Controls.Add(this.label2);

this.Controls.Add(this.textBox1);

this.Controls.Add(this.label1);

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

this.MaximizeBox = false;

this.Name = "Post";

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

this.Text = "Post";

this.TopMost = true;

this.ResumeLayout(false);

}

#endregion

public static byte first()

{

position++;

return(k=Convert.ToByte(char.GetNumericValue(command[k][2])-1));

}

public static byte second()

{

position--;

return(k=Convert.ToByte(char.GetNumericValue(command[k][2])-1));

}

public static byte third()

{

input[position]='1';

return(k=Convert.ToByte(char.GetNumericValue(command[k][2])-1));

}

public static byte fourth()

{

input[position]='0';

return(k=Convert.ToByte(char.GetNumericValue(command[k][2])-1));

}

public void fifth()

{

if(position<input.Length)

{

if (input[position]=='0') k=Convert.ToByte(char.GetNumericValue(command[k][2])-1);

else k=Convert.ToByte(char.GetNumericValue(command[k][3])-1);

}

else

{

A5=new Error("Выход за границы входной строки");

A5.ShowDialog();

finish=1;chk=false;

}

}

bool check_string(string str)

{

int i,s=0,cnt=0;

for (i=0;i<str.Length;i++) if(str[i]==';')cnt++;

for (i=0;i<cnt;i++)

{

if (!char.IsDigit(str[s])||str[s]=='0') return(false);

s++;

if (str[s]!=',') return(false);

s++;

if (char.GetNumericValue(str[s])>6||char.GetNumericValue(str[s])<1) return(false);

s++;

if (str[s]!=',') return(false);

s++;

if (!char.IsDigit(str[s])) return (false);

s++;

if (str[s]!=',') return(false);

s++;

if (!char.IsDigit(str[s])) return(false);

s++;

if (str[s]!=';') return(false);

s++;

}

if(s!=str.Length) return(false);

return(true);

}

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

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

{

A4 = new Help(0);

A4.ShowDialog();

}

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

{

l=1;k=0;position=0;finish=0;textBox3.Text="";chk=true;

int i,j;

//массив из входной строки

input = new char [textBox1.Text.Length];

command = new char [textBox2.Text.Length/8][];

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

{

if (textBox1.Text[i]!='0' && textBox1.Text[i]!='1')

{

A5 = new Error("Неправильный формат входной строки");

A5.ShowDialog();

i=textBox1.Text.Length;

chk=false;

}

else input[i]=textBox1.Text[i];

}

//массив из списка комманд

if (check_string(textBox2.Text))

{

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

{

command [i]=new char[4];

for (j=0;j<4;j++) command[i][j]=textBox2.Text[i*8+j*2];

}

}

else

{

A5 = new Error("Некорректный формат команды");

A5.ShowDialog();

chk=false;

}

if (chk)

{

do

{

switch(command[k][l])

{

case('1'):

{

first();

break;

}

case('2'):

{

second();

break;

}

case('3'):

{

third();

break;

}

case('4'):

{

fourth();

break;

}

case('5'):

{

fifth();

break;

}

case('6'):

{

finish=1;

break;

}

}

}while (finish!=1);

}

if(chk) for(i=0;i<input.Length;i++) textBox3.Text+=input[i];

}

}

}

Hemming

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

namespace Study_Programs

{

public class Hemming : System.Windows.Forms.Form

{

int ChVoprosov=1;

int X=0;

int Nomer=0;

int [] x=new int[10];

Help A4; Error A5;

private System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.TextBox textBox2;

private System.Windows.Forms.TextBox textBox3;

private System.Windows.Forms.TextBox textBox4;