ΠŸΠΎΠΌΠΎΡ‰ΡŒ Π² написании студСнчСских Ρ€Π°Π±ΠΎΡ‚
АнтистрСссовый сСрвис

Алгоритмы Ρ€Π΅ΡˆΠ΅Π½ΠΈΡ Π·Π°Π΄Π°Ρ‡

Π Π΅Ρ„Π΅Ρ€Π°Ρ‚ΠŸΠΎΠΌΠΎΡ‰ΡŒ Π² Π½Π°ΠΏΠΈΡΠ°Π½ΠΈΠΈΠ£Π·Π½Π°Ρ‚ΡŒ ΡΡ‚ΠΎΠΈΠΌΠΎΡΡ‚ΡŒΠΌΠΎΠ΅ΠΉ Ρ€Π°Π±ΠΎΡ‚Ρ‹

Π”Π°Π½ массив Ρ†Π΅Π»Ρ‹Ρ… чисСл A, n>1000. Π’ ΠΎΡ‚сортированном (ΠΏΠΎ Π½Π΅ΡƒΠ±Ρ‹Π²Π°Π½ΠΈΡŽ) ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠΌ Π¨Π΅Π»Π»Π° массивС Π½Π°ΠΉΡ‚ΠΈ элСмСнт x (поиск ΠΎΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚ΡŒ двумя ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌΠΈ, сравнив ΠΈΡ… ΡΡ„Ρ„Π΅ΠΊΡ‚ΠΈΠ²Π½ΠΎΡΡ‚ΡŒ). Π­Π»Π΅ΠΌΠ΅Π½Ρ‚ x Π²Π²ΠΎΠ΄ΠΈΡ‚ся с ΠΊΠ»Π°Π²ΠΈΠ°Ρ‚ΡƒΡ€Ρ‹, Ссли искомого элСмСнта Π½Π΅Ρ‚ — вывСсти сообщСниС. Π—Π°Π΄Π°Π½ΠΈΠ΅ 5. ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ интСрфСйс Ρ‚Π°Π±Π»ΠΈΡ‡Π½Ρ‹ΠΉ Π‘ΡƒΠΌΠΌΠ° Π΄Π²ΡƒΡ… ΠΏΠ΅Ρ€Π²Ρ‹Ρ… Ρ†ΠΈΡ„Ρ€ Π·Π°Π΄Π°Π½Π½ΠΎΠ³ΠΎ Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅Ρ…Π·Π½Π°Ρ‡Π½ΠΎΠ³ΠΎ числа Ρ€Π°Π²Π½Π° суммС Π΄Π²ΡƒΡ… Π΅Π³ΠΎ послСдних Ρ†ΠΈΡ„Ρ€… Π§ΠΈΡ‚Π°Ρ‚ΡŒ Π΅Ρ‰Ρ‘ >

Алгоритмы Ρ€Π΅ΡˆΠ΅Π½ΠΈΡ Π·Π°Π΄Π°Ρ‡ (Ρ€Π΅Ρ„Π΅Ρ€Π°Ρ‚, курсовая, Π΄ΠΈΠΏΠ»ΠΎΠΌ, ΠΊΠΎΠ½Ρ‚Ρ€ΠΎΠ»ΡŒΠ½Π°Ρ)

Π—Π°Π΄Π°Π½ΠΈΠ΅ 1.

Π Π°Π·Ρ€Π°Π±ΠΎΡ‚Π°ΠΉΡ‚Π΅ ΠΈΠ½Π΄ΠΈΠ²ΠΈΠ΄ΡƒΠ°Π»ΡŒΠ½Ρ‹ΠΉ интСрфСйс (Π΄ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²ΠΎΠ΅ ΠΎΠΊΠ½ΠΎ) ΠΏΠΎ Π·Π°ΠΏΠΎΠ»Π½Π΅Π½ΠΈΡŽ Ρ‚Π°Π±Π»ΠΈΡ‡Π½ΠΎΠΉ Π±Π°Π·Ρ‹ Π΄Π°Π½Π½Ρ‹Ρ… ΠΈ Π²Π½Π΅ΡΠΈΡ‚Π΅ 10 записСй. Π Π°Π·Ρ€Π°Π±ΠΎΡ‚Π°ΠΉΡ‚Π΅ ΠΈ ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΡ‚Π΅ Π΄ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²ΠΎΠ΅ ΠΎΠΊΠ½ΠΎ «Π’Ρ‹Π±ΠΎΡ€ΠΊΠ°» для подсчСта Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹Ρ… записСй ΠΈΠ· ΡΠΏΠΈΡΠΊΠ° Π½Π° ΠΎΡΠ½ΠΎΠ²Π΅ ΡΠ°ΠΌΠΎΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΠ½ΠΎ Π·Π°Π΄Π°Π½Π½ΠΎΠ³ΠΎ критСрия.

Листинг ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:

Public Function yy (x As Double) As Double.

yy = Sin (Application.WorksheetFunction.Pi () * x) * Exp (-2 * x).

End Function.

Public Function Komiss (Prodag As Double) As Double.

Const one = 0.08.

Const two = 0.105.

Const three = 0.12.

Select Case Prodag.

Case 0 To 9999.99: Komiss = Prodag * one.

Case 10 000 To 19 999.99: Komiss = Prodag * two.

Case Is >= 20 000: Komiss = Prodag * three.

End Select.

End Function.

Sub Кнопка4_Π©Π΅Π»Ρ‡ΠΎΠΊ ()

UserForm1.Show

End Sub

Sub Кнопка6_Π©Π΅Π»Ρ‡ΠΎΠΊ ()

UserForm2.Show

End Sub

2.

Π”Π°Π½ массив Ρ†Π΅Π»Ρ‹Ρ… чисСл A[n], n>1000. Π’ ΠΎΡ‚сортированном (ΠΏΠΎ Π½Π΅ΡƒΠ±Ρ‹Π²Π°Π½ΠΈΡŽ) ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠΌ Π¨Π΅Π»Π»Π° массивС Π½Π°ΠΉΡ‚ΠΈ элСмСнт x (поиск ΠΎΡΡƒΡ‰Π΅ΡΡ‚Π²ΠΈΡ‚ΡŒ двумя ΠΌΠ΅Ρ‚ΠΎΠ΄Π°ΠΌΠΈ, сравнив ΠΈΡ… ΡΡ„Ρ„Π΅ΠΊΡ‚ΠΈΠ²Π½ΠΎΡΡ‚ΡŒ). Π­Π»Π΅ΠΌΠ΅Π½Ρ‚ x Π²Π²ΠΎΠ΄ΠΈΡ‚ся с ΠΊΠ»Π°Π²ΠΈΠ°Ρ‚ΡƒΡ€Ρ‹, Ссли искомого элСмСнта Π½Π΅Ρ‚ — вывСсти сообщСниС.

Листинг ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:

unit Unit1;

interface.

uses.

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,.

Dialogs, StdCtrls;

type.

TForm1 = class (TForm).

Button1: TButton;

Edit1: TEdit;

ListBox1: TListBox;

Label1: TLabel;

Button2: TButton;

Label2: TLabel;

procedure Button1Click (Sender: TObject);

procedure Button2Click (Sender: TObject);

private.

{ Private declarations }.

public.

{ Public declarations }.

end;

var.

Form1: TForm1;

implementation.

{$R *.dfm}.

procedure TForm1. Button1Click (Sender: TObject);

var A: Array[0.1000] of Integer;

i, w: Integer;

prov:boolean;

begin.

if Edit1. Text=''.

then.

ShowMessage ('Π—Π°ΠΏΠΎΠ»Π½ΠΈΡ‚Π΅ ΠΏΠΎΠ»Π΅!').

else.

try.

prov:=false;

Randomize;

for i := Low (A) to High (A) do.

begin.

A[i] := Random (1000);

ListBox1.Items.Add (IntToStr (A[i]));

end;

w:=strtoint (Edit1.text);

for i:=1 to 1000 do.

if a[i]=w then.

begin.

prov:=true;

label1.caption:='Π­Π»Π΅ΠΌΠ΅Π½Ρ‚ Π½Π°ΠΉΠ΄Π΅Π½!'.

end;

if not (prov) then.

label1.caption:='Π­Π»Π΅ΠΌΠ΅Π½Ρ‚ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½!'.

except.

end;

end;

procedure TForm1. Button2Click (Sender: TObject);

begin.

Listbox1.Clear;

label1.Caption:='';

end;

end.

Π—Π°Π΄Π°Π½ΠΈΠ΅ 3.

Найти ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ ΠΈ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ элСмСнты ΠΈ ΠΏΠΎΠΌΠ΅Π½ΡΡ‚ΡŒ ΠΈΡ… ΠΌΠ΅ΡΡ‚Π°ΠΌΠΈ.

Листинг ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:

unit Unit1;

interface.

uses.

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,.

Dialogs, StdCtrls;

type.

TForm1 = class (TForm).

ListBox1: TListBox;

Button1: TButton;

Button2: TButton;

Label1: TLabel;

Label2: TLabel;

procedure Button1Click (Sender: TObject);

procedure Button2Click (Sender: TObject);

private.

{ Private declarations }.

public.

{ Public declarations }.

end;

var.

Form1: TForm1;

a: array [1.25] of integer;

implementation.

{$R *.dfm}.

function MinI: integer;//ΠΈΡ‰Π΅ΠΌ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ.

var.

i: integer;

begin.

result:=a[1];

for i:=1 to 25 do.

if a[result]>a[i] then.

result:=i;

end;

function MaxI: integer;//ΠΈΡ‰Π΅ΠΌ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ.

var.

i: integer;

begin.

result:=a[1];

for i:=1 to 25 do.

if a[result]

result:=i;

end;

procedure Vipolnit;//заполняСм массивы.

var.

Ia, m: integer;

begin.

randomize;

Form1.ListBox1.clear;

for Ia:=1 to 25 do begin.

a[Ia]: =random (100);

Form1.ListBox1.items.add (inttostr (a[Ia]));

end;

end;

procedure Prosmotr;//просмотр

var.

Ia, m: integer;

begin.

m:=a[MaxI];

Ia:=a[MinI];

a[MinI]: =m;

a[MaxI]: =Ia;

showmessage ('a[MinI]='+inttostr (a[MinI])+', a[MaxI]='+inttostr (a[MaxI]));

Form1.ListBox1.clear;

for Ia:=1 to 25 do.

Form1.ListBox1.items.add (inttostr (a[Ia]));

end;

procedure TForm1. Button1Click (Sender: TObject);

begin.

Vipolnit;

end;

procedure TForm1. Button2Click (Sender: TObject);

begin.

Prosmotr;

end;

end.

4.

ΠšΠΎΠ΄ΠΈΡ€ΠΎΠ²Ρ‰ΠΈΠΊ. ΠΠ°ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡƒ, ΠΏΠ΅Ρ€Π΅ΠΊΠΎΠ΄ΠΈΡ€ΡƒΡŽΡ‰ΡƒΡŽ строку Π² ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ΅ KOI Π² ΡΡ‚Ρ€ΠΎΠΊΡƒ Π² ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ΅ Windows-1251 ΠΈ ΠΎΠ±Ρ€Π°Ρ‚Π½ΠΎ.

Листинг ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:

using System;

using System.Collections.Generic;

using System. Linq;

using System. Text;

using System.Threading.Tasks;

namespace ConsoleApplication2.

{.

class ConvertExampleClass.

{.

static void Main ().

{.

string unicodeString = «Π― Π³Π°Π½Π°Ρ€ΡƒΡΡ, Ρ‡Ρ‚ΠΎ ΠΆΡ‹Π²Ρƒ Ρƒ Π‘Сларуси!» ;

Encoding ascii = Encoding. ASCII;

Encoding unicode = Encoding. Unicode;

byte[] unicodeBytes = unicode. GetBytes (unicodeString);

byte[] asciiBytes = Encoding. Convert (unicode, ascii, unicodeBytes);

char[] asciiChars = new char[ascii.GetCharCount (asciiBytes, 0, asciiBytes. Length)];

ascii.GetChars (asciiBytes, 0, asciiBytes. Length, asciiChars, 0);

string asciiString = new string (asciiChars);

// Display the strings created before and after the conversion.

Console.WriteLine («ΠžΡ€ΠΈΠ³ΠΈΠ½Π°Π»ΡŒΠ½Π°Ρ строка: {0}», unicodeString);

Console.WriteLine («Ascii строка: {0}», asciiString);

System.Threading.Thread.Sleep (10 000);

}.

}.

}.

Π—Π°Π΄Π°Π½ΠΈΠ΅ 5. ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ интСрфСйс Ρ‚Π°Π±Π»ΠΈΡ‡Π½Ρ‹ΠΉ Π‘ΡƒΠΌΠΌΠ° Π΄Π²ΡƒΡ… ΠΏΠ΅Ρ€Π²Ρ‹Ρ… Ρ†ΠΈΡ„Ρ€ Π·Π°Π΄Π°Π½Π½ΠΎΠ³ΠΎ Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅Ρ…Π·Π½Π°Ρ‡Π½ΠΎΠ³ΠΎ числа Ρ€Π°Π²Π½Π° суммС Π΄Π²ΡƒΡ… Π΅Π³ΠΎ послСдних Ρ†ΠΈΡ„Ρ€.

Листинг ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:

using System;

using System.Collections.Generic;

using System. Linq;

using System. Text;

using System.Threading.Tasks;

namespace ConsoleApplication2.

{.

class Program.

{.

static void Main (string[] args).

{.

int x = int. Parse (Console.ReadLine ());

if (x 9999) Console. WriteLine («Π§ΠΈΡΠ»ΠΎ Π½Π΅ Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅Ρ…Π·Π½Π°Ρ‡Π½ΠΎΠ΅»);

else if ((x / 1000) + ((x / 100) % 10) == ((x / 10) % 10) + (x % 10)) Console. WriteLine («Π Π°Π²Π½ΠΎ»);

else Console. WriteLine («ΠΠ΅ Ρ€Π°Π²Π½ΠΎ»);

System.Threading.Thread.Sleep (100 000);

}.

}.

}.

Π—Π°Π΄Π°Π½ΠΈΠ΅ 6.

Π Π°Π·Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π‘Π” SQL со ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΌΠΈ сущностями: страна, Π³ΠΎΡ€ΠΎΠ΄, ΠΎΠ±Π»Π°ΡΡ‚ΡŒ, ΠΊΡ€Π°ΠΉ.

Листинг ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:

using System;

using System.Collections.Generic;

using System. ComponentModel;

using System. Data;

using System.Data.OleDb;

using System. Drawing;

using System. Linq;

using System. Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace DB_______________________________________.

{.

public partial class Form1: Form.

{.

public Form1().

{.

InitializeComponent ();

}.

private void Form1_Load (object sender, EventArgs e).

{.

// TODO: данная строка ΠΊΠΎΠ΄Π° позволяСт Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ Π΄Π°Π½Π½Ρ‹Π΅ Π² Ρ‚Π°Π±Π»ΠΈΡ†Ρƒ «_1DataSet.strana». ΠŸΡ€ΠΈ нСобходимости ΠΎΠ½Π° ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π΅Π½Π° ΠΈΠ»ΠΈ ΡƒΠ΄Π°Π»Π΅Π½Π°.

this.stranaTableAdapter.Fill (this._1DataSet.strana);

// TODO: данная строка ΠΊΠΎΠ΄Π° позволяСт Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ Π΄Π°Π½Π½Ρ‹Π΅ Π² Ρ‚Π°Π±Π»ΠΈΡ†Ρƒ «_1DataSet.obl». ΠŸΡ€ΠΈ нСобходимости ΠΎΠ½Π° ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π΅Π½Π° ΠΈΠ»ΠΈ ΡƒΠ΄Π°Π»Π΅Π½Π°.

this.oblTableAdapter.Fill (this._1DataSet.obl);

// TODO: данная строка ΠΊΠΎΠ΄Π° позволяСт Π·Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ Π΄Π°Π½Π½Ρ‹Π΅ Π² Ρ‚Π°Π±Π»ΠΈΡ†Ρƒ «_1DataSet.city». ΠŸΡ€ΠΈ нСобходимости ΠΎΠ½Π° ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π΅Π½Π° ΠΈΠ»ΠΈ ΡƒΠ΄Π°Π»Π΅Π½Π°.

this.cityTableAdapter.Fill (this._1DataSet.city);

_1DataSet d = new _1DataSet ();

for (int i = 0; i < d.Tables.Count; i++).

listBox1.Items.Add (d.Tables[i]. TableName);

}.

private void listBox1_DoubleClick (object sender, EventArgs e).

{.

switch (listBox1.SelectedIndex).

{.

case 0:

bindingNavigator1.BindingSource = cityBindingSource;

dataGridView1.DataSource = cityBindingSource;

break;

case 1:

bindingNavigator1.BindingSource = oblBindingSource;

dataGridView1.DataSource = oblBindingSource;

break;

case 2:

bindingNavigator1.BindingSource = stranaBindingSource;

dataGridView1.DataSource = stranaBindingSource;

break;

}.

}.

Π—Π°Π΄Π°Π½ΠΈΠ΅ 7.

Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ XML справочник ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€ΠΎΠ². Π‘Ρ‚Ρ€ΡƒΠΊΡ‚ΡƒΡ€Ρƒ XML-Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π° ΠΏΡ€ΠΎΠ΄ΡƒΠΌΠ°Ρ‚ΡŒ ΡΠ°ΠΌΠΎΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΠ½ΠΎ. Π Π°ΡΡˆΠΈΡ€ΠΈΡ‚ΡŒ класс Computer срСдствами Ρ€Π°Π±ΠΎΡ‚Ρ‹ с XML-Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°ΠΌΠΈ. Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ контсруктор Π½Π° ΠΎΡΠ½ΠΎΠ²Π΅ XML-Ρ‚Π΅Π³Π° (конструктор ΠΏΡ€ΠΈΠ½7ΠΈΠΌΠ°Π΅Ρ‚ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ класса XmlNode). Π Π°Π·Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ чтСния ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€ΠΎΠ² ΠΈΠ· ΡΠΏΡ€Π°Π²ΠΎΡ‡Π½ΠΈΠΊΠ° Π² ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΡŽ ArrayList. Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ записи ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€ΠΎΠ² Π² ΡΠΏΡ€Π°Π²ΠΎΡ‡Π½ΠΈΠΊ ΠΏΡƒΡ‚Π΅ΠΌ добавлСния Π½ΠΎΠ²ΠΎΠ³ΠΎ Ρ‚Π΅Π³Π°.

Листинг ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:

using System;

using System.Collections.Generic;

using System. Linq;

using System. Text;

using System.Threading.Tasks;

using System. Xml;

using System. Collections;

namespace xml.

{.

class Program.

{.

static void Main (string[] args).

{.

XmlDocument xml = new XmlDocument ();

xml.Load («…Computers.xml»);

XmlNodeList items = xml. GetElementsByTagName («Item»);

// int m=666;

string g="11″ ;

while (Convert.ToString (g) ≠ «0»).

{.

Console.Clear ();

Console.WriteLine («1) ΠŸΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ записи.»);

Console.WriteLine («2) Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ запись.»);

Console.WriteLine («3) Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π² ΡΠΏΠΈΡΠΎΠΊ ArrayList.»);

Console.WriteLine («0) Π’Ρ‹Ρ…ΠΎΠ΄.»);

g = Convert. ToString (Console.ReadLine ());

switch (Convert.ToString (g)).

{.

case «1» :

Console.Clear ();

foreach (XmlNode x in items).

{.

Console.WriteLine («Item {0} = {1}», x. Attributes[0]. Name, x. Attributes[0]. Value);

foreach (XmlNode z in x. ChildNodes).

Console.WriteLine («{0,-10}: {1,-10}», z.Name, z. InnerText);

Console.WriteLine (««);

}.

Console.ReadKey ();

break;

case «2» :

Console.Clear ();

XmlNodeList itemss = xml. GetElementsByTagName («Item»);

XmlElement newItem = xml. CreateElement («Item»);

XmlAttribute at = xml. CreateAttribute («id»);

at.Value = Convert. ToString (itemss.Count + 1);

newItem.SetAttributeNode (at);

XmlElement el;

foreach (XmlNode x in itemss[0]. ChildNodes).

{.

el = xml. CreateElement (x.Name);

Console.Write («{0}: «, x.Name);

string name = Console. ReadLine ();

el.InnerText = name;

newItem.AppendChild (el);

}.

xml.DocumentElement.InsertAfter (newItem, xml.DocumentElement.LastChild);

xml.Save («…Computers.xml»);

break;

case «3» :

ArrayList list = new ArrayList ();

XmlNodeList listN = xml. GetElementsByTagName («Item»);

for (int i = 0; i < listN. Count; i++).

list.Add (listN[i]);

Console.Clear ();

Console.WriteLine («Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΎ!»);

Console.ReadKey ();

break;

}.

}.

}.

}.

}.

Π—Π°Π΄Π°Π½ΠΈΠ΅ 8.

Π Π°Π·Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ рисования ΠΈ ΡƒΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΡ Ρ€Π°Π·Π»ΠΈΡ‡Π½Ρ‹ΠΌΠΈ гСомСтричСскими Ρ„ΠΈΠ³ΡƒΡ€Π°ΠΌΠΈ.

Листинг ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:

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 gdi.

{.

public partial class Form1: Form.

{.

private Circle f1;

private Square f2;

private bool stats;

private float sclare;

private float shagSetki;

private Figure f;

private Pen pen;

private PointF cen;

private Color tekColor;// =Color.Red;

Graphics g;

public Form1().

{.

InitializeComponent ();

stats = true;

sclare = (float)1;

shagSetki = 25;

tekColor = Color. Red;

pen = new Pen (tekColor);

this.toolStripLabel4.Text = «X» + Convert. ToString (this.sclare);

}.

private void toolStripButton1_Click (object sender, EventArgs e).

{.

cen = new PointF ();

cen.X = Convert. ToInt32(toolStripTextBox1.Text);

cen.Y = Convert. ToInt32(toolStripTextBox2.Text);

pen = new Pen (tekColor, 3);

if (tabControl1.SelectedIndex == 0).

{.

g = this. tabPage1.CreateGraphics ();

f = new Circle (cen, Convert. ToInt32(toolStripTextBox3.Text), pen, sclare);

}.

else.

{.

g = this. tabPage2.CreateGraphics ();

f = new Square (cen, Convert. ToInt32(toolStripTextBox3.Text), pen, sclare);

}.

tabControl1.Invalidate ();

}.

private void tabPage1_Paint (object sender, PaintEventArgs e).

{.

if (stats).

{.

Pen ww = new Pen (Color.Blue, 1);

PointF p1 =new Point ();

PointF p2 =new Point ();

p1.X=0;

p2.X=tabPage1.Size.Width;

for (float i = tabPage1.Size.Height / 2; i < tabPage1.Size.Height; i += shagSetki * this. sclare)//y.

{.

p1.Y = p2. Y = i;

e.Graphics.DrawLine (ww, p1, p2);

}.

for (float i = tabPage1.Size.Height / 2; i > 0; i -= shagSetki * this. sclare)//y.

{.

p1.Y = p2. Y = i;

e.Graphics.DrawLine (ww, p1, p2);

}.

p1.Y = 0;

p2.Y = tabPage1.Size.Height;

for (float i = tabPage1.Size.Width / 2; i < tabPage1.Size.Width; i += shagSetki * this. sclare)//y.

{.

p1.X = p2. X = i;

e.Graphics.DrawLine (ww, p1, p2);

}.

for (float i = tabPage1.Size.Width / 2; i > 0; i -= shagSetki * this. sclare)//y.

{.

p1.X = p2. X = i;

e.Graphics.DrawLine (ww, p1, p2);

}.

ww.Width = 2;

p1.X = p2. X = tabPage1.Size.Width/2;

p1.Y=0;

p2.Y=tabPage1.Size.Height;

e.Graphics.DrawLine (ww, p1, p2);

p1.Y = p2. Y = tabPage1.Size.Height / 2;

p1.X = 0;

p2.X = tabPage1.Size.Width;

e.Graphics.DrawLine (ww, p1, p2);

}.

if (f ≠ null) f. Draw (g, this. tabPage1. Size);

}.

private void toolStripButton2_Click (object sender, EventArgs e).

{.

stats = !stats;

tabControl1.Invalidate ();

if (stats) toolStripButton2. CheckState = CheckState. Checked;

else toolStripButton2. CheckState = CheckState. Unchecked;

}.

private void tabPage2_Paint (object sender, PaintEventArgs e).

{.

if (stats).

{.

Pen ww = new Pen (Color.Blue, 1);

PointF p1 = new Point ();

PointF p2 = new Point ();

p1.X = 0;

p2.X = tabPage2.Size.Width;

for (float i = tabPage2.Size.Height / 2; i < tabPage2.Size.Height; i += shagSetki * this. sclare)//y.

{.

p1.Y = p2. Y = i;

e.Graphics.DrawLine (ww, p1, p2);

}.

for (float i = tabPage2.Size.Height / 2; i > 0; i -= shagSetki * this. sclare)//y.

{.

p1.Y = p2. Y = i;

e.Graphics.DrawLine (ww, p1, p2);

}.

p1.Y = 0;

p2.Y = tabPage2.Size.Height;

for (float i = tabPage2.Size.Width / 2; i < tabPage2.Size.Width; i += shagSetki * this. sclare)//y.

{.

p1.X = p2. X = i;

e.Graphics.DrawLine (ww, p1, p2);

}.

for (float i = tabPage2.Size.Width / 2; i > 0; i -= shagSetki * this. sclare)//y.

{.

p1.X = p2. X = i;

e.Graphics.DrawLine (ww, p1, p2);

}.

ww.Width = 2;

p1.X = p2. X = tabPage2.Size.Width / 2;

p1.Y = 0;

p2.Y = tabPage2.Size.Height;

e.Graphics.DrawLine (ww, p1, p2);

p1.Y = p2. Y = tabPage2.Size.Height / 2;

p1.X = 0;

p2.X = tabPage2.Size.Width;

e.Graphics.DrawLine (ww, p1, p2);

}.

if (f ≠ null) f. Draw (g, this. tabPage2. Size);

}.

private void toolStripButton5_Click (object sender, EventArgs e).

{.

if (f ≠ null).

{.

f.Move ((float)Convert.ToDouble (this.toolStripTextBox4.Text), this. sclare, Direction. Down);

f.Draw (g, this. tabPage1. Size);

tabControl1.Invalidate ();

}.

}.

private void toolStripButton6_Click (object sender, EventArgs e).

{.

if (f ≠ null).

{.

f.Move ((float)Convert.ToDouble (this.toolStripTextBox4.Text), this. sclare, Direction. Up);

f.Draw (g, this. tabPage1. Size);

tabControl1.Invalidate ();

}.

}.

private void toolStripButton7_Click (object sender, EventArgs e).

{.

if (f ≠ null).

{.

f.Move ((float)Convert.ToDouble (this.toolStripTextBox4.Text), this. sclare, Direction. Left);

f.Draw (g, this. tabPage1. Size);

tabControl1.Invalidate ();

}.

}.

private void toolStripButton8_Click (object sender, EventArgs e).

{.

if (f ≠ null).

{.

f.Move ((float)Convert.ToDouble (this.toolStripTextBox4.Text), this. sclare, Direction. Right);

f.Draw (g, this. tabPage1. Size);

tabControl1.Invalidate ();

}.

}.

private void exitToolStripMenuItem_Click (object sender, EventArgs e).

{.

Application.Exit ();

}.

private void colorToolStripMenuItem_Click (object sender, EventArgs e).

{.

colorDialog1.ShowDialog ();

tekColor = pen. Color = this. colorDialog1.Color;

tabControl1.Invalidate ();

}.

private void toolStripButton3_Click (object sender, EventArgs e).

{.

this.sclare *= 2;

this.toolStripLabel4.Text = «X» + Convert. ToString (this.sclare);

if (f ≠ null) f. Reduce ();

tabControl1.Invalidate ();

}.

private void toolStripButton4_Click (object sender, EventArgs e).

{.

this.sclare /= 2;

this.toolStripLabel4.Text = «X» + Convert. ToString (this.sclare);

if (f ≠ null) f. Increase ();

tabControl1.Invalidate ();

}.

private void tabPage2_MouseDoubleClick (object sender, MouseEventArgs e).

{.

Point p = new Point (e.X, e. Y);

if (f ≠ null) if (f.CheckHit (p)) MessageBox. Show («ΠŸΠΎΠΏΠ°Π»!»);

}.

private void tabPage1_MouseDoubleClick (object sender, MouseEventArgs e).

{.

Point p = new Point (e.X, e. Y);

if (f ≠ null) if (f.CheckHit (p)) MessageBox. Show («ΠŸΠΎΠΏΠ°Π»!»);

}.

private void tabControl1_SelectedIndexChanged (object sender, EventArgs e).

{.

this.sclare = 1;

this.toolStripLabel4.Text = «X» + Convert. ToString (this.sclare);

}.

}.

}.

ΠŸΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ вСсь тСкст
Π—Π°ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ Ρ„ΠΎΡ€ΠΌΡƒ Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Ρ€Π°Π±ΠΎΡ‚ΠΎΠΉ