Список использованных источников

 

1. Афанасьев, А. П. Программирование на языке С# / А. И. Афанасьев. – Минск: БНТУ, 2001. – 322 c.

2. Культин, Н. Б. Microsoft Visual C# в задачах и примерах / Н. Б. Культин. – Полоцк: IT-teg, 2003. – 120 с.

3. Лабор, В. В. Си Шарп: Создание приложений для Windows / В. В. Лабор. – Минск: Харвест, 2003. – 384 с.

4. Марченко, А. Л. C#. Введение в программирование / А. Л. Марченко. – Брест: IT–resyrs, 1991. – 654 с.

5. Павловская, Т. А. С#. Программирование на языке высокого уровня / Т. А. Павловская. – Минск: БГУИР, 1999. – 349 с.

 



ПРИЛОЖЕНИЕ А

(обязательное «Главная форма»)

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace ИДЗ

{

public partial class Form1: Form

{

   public Form1()

   {

       InitializeComponent();

   }

 

   private void button3_Click(object sender, EventArgs e)

   {

       Form4 form4 = new Form4();

       form4.Show();

       this.Visible = false;

   }

 

   private void button4_Click(object sender, EventArgs e)

   {

       //this.Visible = false;

       Application.Exit();

   }

 

   private void button1_Click(object sender, EventArgs e)

   {

       System.Diagnostics.Process.Start("IDZ.docx");

   }

 

   private void button2_Click(object sender, EventArgs e)

   {

       Form3 form3 = new Form3();

       form3.Show();

       this.Visible = false;

  }

 

   private void Form1_Load(object sender, EventArgs e)

   {

      }

 

   }

}



ПРИЛОЖЕНИЕ Б

(обязательное «Алгоритм Форда-Фалкерсона»)

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.IO;

 

namespace ИДЗ

{

public partial class Form3: Form

{

   public static int MAX_VERTICES = 40;

   public static int INFINITY = 10000;

   public static int[,] f = new int[MAX_VERTICES, MAX_VERTICES];

   public static int[,] c = new int[MAX_VERTICES, MAX_VERTICES];

   public static int[] Flow = new int[MAX_VERTICES];

   public static int[] Link = new int[MAX_VERTICES];

   public static int[] Queue = new int[MAX_VERTICES];

   public static int QP, QC;

 

   public Form3()

   {

       InitializeComponent();

   }

 

   private void button2_Click(object sender, EventArgs e)

   {

       Form1 ifrm = new Form1();

       ifrm.Show();

       this.Close();

   }

 

   private void label3_Click(object sender, EventArgs e)

   {

 

   }

 

   private void textBox2_TextChanged(object sender, EventArgs e)

   {

       int NUM_VERTICES;

       if (!(textBox2.Text == ""))

       {

           if (!(int.TryParse(textBox2.Text, out NUM_VERTICES) && NUM_VERTICES >= 2 && NUM_VERTICES < 40))

           {

               MessageBox.Show("Invalid input numbers", "Error");

               textBox2.Text = "";

           }

       }

   }

 

   private void textBox3_TextChanged(object sender, EventArgs e)

   {

       int source;

       if (!(textBox3.Text == ""))

           if (!(int.TryParse(textBox3.Text, out source)))

           {

               MessageBox.Show("Invalid input numbers", "Error");

               textBox3.Text = "";

           }

   }

 

     private void textBox4_TextChanged(object sender, EventArgs e)

   {

       int target;

       if (!(textBox4.Text == ""))

           if (!(int.TryParse(textBox4.Text, out target)))

           {

               MessageBox.Show("Invalid input numbers", "Error");

               textBox4.Text = "";

 

           }

   }

 

   private void button3_Click(object sender, EventArgs e)

   {

       if (textBox1.Text!= "" && textBox2.Text!= "" && textBox3.Text!= "" && textBox4.Text!= "")

       {

           int source, target, i, j, k = 0, NUM_VERTICES;

           string s = "";

           NUM_VERTICES = Convert.ToInt32(textBox2.Text);

           source = Convert.ToInt32(textBox3.Text);

           target = Convert.ToInt32(textBox4.Text);

           StreamReader fs = new StreamReader(textBox1.Text);//Чтение из текстового файла

 

           while (s!= null)

           {

               s = fs.ReadLine();

               label7.Text += s;

           }

           string[] m = label7.Text.Split(' ');

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

               for (j = 0; j < NUM_VERTICES; j++)

               {

                   c[i, j] = int.Parse(m[k]);

                   k++;

               }

           label6.Text = (MaxFlow(source, target, NUM_VERTICES)).ToString();//Вызов функции самого алгоритма

       }

       else MessageBox.Show("No values", "Error");

   }

   static int FindPath(int source, int target, int NUM_VERTICES)//поиск максимального потока

   {

       QP = 0; QC = 1; Queue[0] = source; Link[target] = -1;

       int i;

       int CurVertex;

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

           Flow[i] = 0;

       Flow[source] = INFINITY;

       while (Link[target] == -1 && QP < QC)

       {

           CurVertex = Queue[QP];

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

               if ((c[CurVertex, i] - f[CurVertex, i]) > 0 && Flow[i] == 0)

               {

                   Queue[QC] = i; QC++;

                   Link[i] = CurVertex;

                   if (c[CurVertex, i] - f[CurVertex, i] < Flow[CurVertex])

                       Flow[i] = c[CurVertex, i];

                   else

                       Flow[i] = Flow[CurVertex];

               }

           QP++;

       }

 

       if (Link[target] == -1) return 0;

       CurVertex = target;

       while (CurVertex!= source)

       {

           f[Link[CurVertex], CurVertex] += Flow[target];

           CurVertex = Link[CurVertex];

       }

       return Flow[target];

   }

   static int MaxFlow(int source, int target, int NUM_VERTICES)

   {

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

       {

           for (int j = 0; j < MAX_VERTICES; j++)

           {

               f[i, j] = 0;

           }

       }

       int MaxFlow = 0;

       int AddFlow;

       do

       {

           AddFlow = FindPath(source, target, NUM_VERTICES);

           MaxFlow += AddFlow;

       } while (AddFlow > 0);

       return MaxFlow;

   }

 

   private void label1_Click(object sender, EventArgs e)

   {

 

   }

 

   private void Form3_Load(object sender, EventArgs e)

   {

 

   }

 

   private void button1_Click(object sender, EventArgs e)

       {

           OpenFileDialog OPF = new OpenFileDialog();

           if (OPF.ShowDialog() == DialogResult.OK)

           {

               textBox1.Text = OPF.FileName;

           }

 

             }

       }

   }


ПРИЛОЖЕНИЕ В

(обязательное «Шифрование с использованием системы Цезаря(аффинная система подстановок)»)

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace ИДЗ

{

public partial class Form4: Form

{

   public Form4()

   {

       InitializeComponent();

   }

 

   private void button1_Click(object sender, EventArgs e)

   {

 

       string abc = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";

       char[] abC = abc.ToCharArray();

       char[] abcCop = new char[abc.Length];

       string s = textBox2.Text;

 

       int a = (int)numericUpDown1.Value;

       int b = (int)numericUpDown2.Value;

 

       //int min;

       //if (a > b) min = b;

       //else min = a;

       //int u = min;

       //int c = 0;

       //while (u > 0 && c == 0)

       //{

       // if ((a % u == 0) && (b % u == 0))

       //   c = u;

       // u--;

       //}

       int min;

       if (a > abC.Length) min = abC.Length;

       else min = a;

       int u = min;

       int c = 0;

       while (u > 0 && c == 0)

       {

           if ((a % u == 0) && (abc.Length % u == 0))

               c = u;

           u--;

       }

       int min1;

       if (b > abC.Length) min1 = abC.Length;

       else min = b;

       int u1 = min;

       int c1 = 0;

       while (u1 > 0 && c1 == 0)

       {

           if ((b % u1 == 0) && (abC.Length % u1 == 0))

               c1 = u1;

           u1--;

       }

 

       if (c > 1 || c1 > 1)

       {

           MessageBox.Show("Эти числа не взаимно простые");

           Application.Restart();

       }

 

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

       {

           abcCop[i] = abc[(a * i + b) % abcCop.Length];

       }

 

 

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

       {

           if (s[i] == ' ')

           {

               textBox1.Text += ' ';

               continue;

           }

           textBox1.Text += abcCop[Array.IndexOf(abC, s[i])];

       }

 

 

   }

 

   private void Form1_Load(object sender, EventArgs e)

   {

 

   }

 

   private void Form4_Paint(object sender, PaintEventArgs e)

   {

 

   }

}

}



Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: