половина 1 практики

This commit is contained in:
Adelina888 2024-06-25 22:22:18 +04:00
parent ec851d7258
commit f5843777d3
6 changed files with 731 additions and 0 deletions

324
Praktika/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,324 @@
namespace Praktika
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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()
{
panel1 = new Panel();
button9 = new Button();
button6 = new Button();
button5 = new Button();
button4 = new Button();
button3 = new Button();
button2 = new Button();
button1 = new Button();
panel2 = new Panel();
arrayTextBox = new RichTextBox();
panel3 = new Panel();
richTextBox1 = new RichTextBox();
button10 = new Button();
label4 = new Label();
label3 = new Label();
label2 = new Label();
textBoxMax = new TextBox();
textBoxMin = new TextBox();
label1 = new Label();
textBoxLen = new TextBox();
button8 = new Button();
button7 = new Button();
panel1.SuspendLayout();
panel2.SuspendLayout();
panel3.SuspendLayout();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(button9);
panel1.Controls.Add(button6);
panel1.Controls.Add(button5);
panel1.Controls.Add(button4);
panel1.Controls.Add(button3);
panel1.Controls.Add(button2);
panel1.Controls.Add(button1);
panel1.Dock = DockStyle.Left;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new Size(176, 653);
panel1.TabIndex = 0;
//
// button9
//
button9.BackColor = Color.DarkViolet;
button9.Location = new Point(12, 324);
button9.Name = "button9";
button9.Size = new Size(147, 41);
button9.TabIndex = 6;
button9.Text = "Вывод задания ";
button9.UseVisualStyleBackColor = false;
button9.Click += Button9_Click;
//
// button6
//
button6.BackColor = Color.Crimson;
button6.Location = new Point(3, 222);
button6.Name = "button6";
button6.Size = new Size(165, 36);
button6.TabIndex = 5;
button6.Text = "Задание 6";
button6.UseVisualStyleBackColor = false;
//
// button5
//
button5.BackColor = Color.Crimson;
button5.Location = new Point(3, 180);
button5.Name = "button5";
button5.Size = new Size(165, 36);
button5.TabIndex = 4;
button5.Text = "задание 5";
button5.UseVisualStyleBackColor = false;
button5.Click += Button5_Click;
//
// button4
//
button4.BackColor = Color.Crimson;
button4.Location = new Point(3, 138);
button4.Name = "button4";
button4.Size = new Size(165, 36);
button4.TabIndex = 3;
button4.Text = "Задание 4";
button4.UseVisualStyleBackColor = false;
button4.Click += Button4_Click;
//
// button3
//
button3.BackColor = Color.Crimson;
button3.Location = new Point(3, 96);
button3.Name = "button3";
button3.Size = new Size(165, 36);
button3.TabIndex = 2;
button3.Text = "Задание 3";
button3.UseVisualStyleBackColor = false;
button3.Click += Button3_Click;
//
// button2
//
button2.BackColor = Color.Crimson;
button2.Location = new Point(3, 54);
button2.Name = "button2";
button2.Size = new Size(165, 36);
button2.TabIndex = 1;
button2.Text = "Задание 2";
button2.UseVisualStyleBackColor = false;
button2.Click += Button2_Click;
//
// button1
//
button1.BackColor = Color.Crimson;
button1.Location = new Point(3, 12);
button1.Name = "button1";
button1.Size = new Size(165, 36);
button1.TabIndex = 0;
button1.Text = "Задание 1";
button1.UseVisualStyleBackColor = false;
button1.Click += Button1_Click;
//
// panel2
//
panel2.Controls.Add(arrayTextBox);
panel2.Controls.Add(panel3);
panel2.Controls.Add(label4);
panel2.Controls.Add(label3);
panel2.Controls.Add(label2);
panel2.Controls.Add(textBoxMax);
panel2.Controls.Add(textBoxMin);
panel2.Controls.Add(label1);
panel2.Controls.Add(textBoxLen);
panel2.Controls.Add(button8);
panel2.Controls.Add(button7);
panel2.Dock = DockStyle.Right;
panel2.Location = new Point(697, 0);
panel2.Name = "panel2";
panel2.Size = new Size(238, 653);
panel2.TabIndex = 1;
//
// arrayTextBox
//
arrayTextBox.Location = new Point(26, 12);
arrayTextBox.Name = "arrayTextBox";
arrayTextBox.Size = new Size(185, 120);
arrayTextBox.TabIndex = 11;
arrayTextBox.Text = "";
//
// panel3
//
panel3.Controls.Add(richTextBox1);
panel3.Controls.Add(button10);
panel3.Location = new Point(26, 390);
panel3.Name = "panel3";
panel3.Size = new Size(200, 251);
panel3.TabIndex = 10;
//
// richTextBox1
//
richTextBox1.Location = new Point(12, 12);
richTextBox1.Name = "richTextBox1";
richTextBox1.Size = new Size(173, 173);
richTextBox1.TabIndex = 12;
richTextBox1.Text = "";
//
// button10
//
button10.BackColor = Color.Blue;
button10.Location = new Point(36, 200);
button10.Name = "button10";
button10.Size = new Size(142, 37);
button10.TabIndex = 1;
button10.Text = "Вывод результата";
button10.UseVisualStyleBackColor = false;
button10.Click += button10_Click;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(26, 201);
label4.Name = "label4";
label4.Size = new Size(199, 15);
label4.TabIndex = 9;
label4.Text = "Диапазон генерируемых значений";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(174, 243);
label3.Name = "label3";
label3.Size = new Size(30, 15);
label3.TabIndex = 8;
label3.Text = "Max";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(39, 243);
label2.Name = "label2";
label2.Size = new Size(28, 15);
label2.TabIndex = 7;
label2.Text = "Min";
//
// textBoxMax
//
textBoxMax.Location = new Point(141, 273);
textBoxMax.Name = "textBoxMax";
textBoxMax.Size = new Size(85, 23);
textBoxMax.TabIndex = 6;
//
// textBoxMin
//
textBoxMin.Location = new Point(15, 273);
textBoxMin.Name = "textBoxMin";
textBoxMin.Size = new Size(81, 23);
textBoxMin.TabIndex = 5;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(26, 159);
label1.Name = "label1";
label1.Size = new Size(91, 15);
label1.TabIndex = 4;
label1.Text = "Длина массива";
//
// textBoxLen
//
textBoxLen.Location = new Point(123, 159);
textBoxLen.Name = "textBoxLen";
textBoxLen.Size = new Size(101, 23);
textBoxLen.TabIndex = 3;
//
// button8
//
button8.BackColor = Color.Chartreuse;
button8.Location = new Point(15, 341);
button8.Name = "button8";
button8.Size = new Size(211, 33);
button8.TabIndex = 2;
button8.Text = "Генерация двумерного массива";
button8.UseVisualStyleBackColor = false;
button8.Click += ButtonTwo_Click;
//
// button7
//
button7.BackColor = Color.Chartreuse;
button7.Location = new Point(15, 302);
button7.Name = "button7";
button7.Size = new Size(211, 33);
button7.TabIndex = 1;
button7.Text = "Генерация одномерного массива";
button7.UseVisualStyleBackColor = false;
button7.Click += ButtonOne_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(935, 653);
Controls.Add(panel2);
Controls.Add(panel1);
Name = "Form1";
Text = "Form1";
panel1.ResumeLayout(false);
panel2.ResumeLayout(false);
panel2.PerformLayout();
panel3.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button button6;
private Button button5;
private Button button4;
private Button button3;
private Button button2;
private Button button1;
private Panel panel2;
private Button button7;
private Label label4;
private Label label3;
private Label label2;
private TextBox textBoxMax;
private TextBox textBoxMin;
private Label label1;
private TextBox textBoxLen;
private Button button8;
private Button button9;
private Panel panel3;
private Button button10;
private RichTextBox arrayTextBox;
private RichTextBox richTextBox1;
}
}

234
Praktika/Form1.cs Normal file
View File

@ -0,0 +1,234 @@
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Praktika
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int[,] array2D;
public static int flag = 0;
private void ButtonOne_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxLen.Text) || string.IsNullOrEmpty(textBoxMin.Text) || string.IsNullOrEmpty(textBoxMax.Text))
{
MessageBox.Show("Ïîæàëóéñòà, ââåäèòå âñå íåîáõîäèìûå äàííûå äëÿ ñîçäàíèÿ ìàññèâà.");
return;
}
int[] array = new int[Convert.ToInt32(textBoxLen.Text)];
Random random = new Random();
for (int i = 0; i < array.Length; i++)
{
array[i] = random.Next(Convert.ToInt32(textBoxMin.Text), Convert.ToInt32(textBoxMax.Text));
}
arrayTextBox.Text = string.Join(", ", array);
}
private void ButtonTwo_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxLen.Text) || string.IsNullOrEmpty(textBoxMin.Text) || string.IsNullOrEmpty(textBoxMax.Text))
{
MessageBox.Show("Ïîæàëóéñòà, ââåäèòå âñå íåîáõîäèìûå äàííûå äëÿ ñîçäàíèÿ ìàññèâà.");
return;
}
int rows = Convert.ToInt32(textBoxLen.Text);
int columns = Convert.ToInt32(textBoxLen.Text);
array2D = new int[rows, columns];
Random random = new Random();
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
array2D[i, j] = random.Next(Convert.ToInt32(textBoxMin.Text), Convert.ToInt32(textBoxMax.Text));
}
}
// Âûâîä äâóìåðíîãî ìàññèâà â òåêñòîâîå ïîëå
StringBuilder sb = new StringBuilder();
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
sb.Append(array2D[i, j] + " ");
}
sb.AppendLine();
}
arrayTextBox.Text = sb.ToString();
}
private void Button1_Click(object sender, EventArgs e)
{
int[] array = Array.ConvertAll(arrayTextBox.Text.Split(','), int.Parse);
int maxLength = 0;
int seriesStartIndex = 0;
int seriesLength = 0;
for (int i = 1; i < array.Length; i++)
{
int currentLength = 1;
for (int j = i; j < array.Length - 1; j++)
{
if (array[j] % array[j - 1] == 0)
{
currentLength++;
}
else
{
break;
}
}
if (currentLength > maxLength && currentLength >= 2)
{
maxLength = currentLength;
seriesStartIndex = i - 1;
seriesLength = currentLength;
}
}
MessageBox.Show($"Ñåðèÿ ñ ìàêñèìàëüíîé äëèíîé íà÷èíàåòñÿ ñ ïîçèöèè {seriesStartIndex} è èìååò äëèíó {seriesLength}");
flag = 1;
}
private void Button9_Click(object sender, EventArgs e)
{
if (flag == 1)
{
richTextBox1.Text = "Äàí öåëî÷èñëåííûé îäíîìåðíûé ìàññèâ ðàçìåðà N." +
"Ñåðèÿ ýòî ïîñëåäîâàòåëüíîñòü ýëåìåíòîâ ìàññèâà, èäóùèõ äðóã çà äðóãîì." +
"Êàæäûé ýëåìåíò ñåðèè äåëèëñÿ íàöåëî íà ïðåäûäóùèé.Ñåðèÿ äîëæíà" +
"ñîäåðæàòü ìèíèìóì 2 ýëåìåíòà.Äëèíà ñåðèè êîëè÷åñòâî ýëåìåíòîâ â" +
"ñåðèè.Íàéòè ñåðèþ ñ ìàêñèìàëüíîé äëèíîé.Âûâåñòè ñ êàêîé ïîçèöèè" +
"íà÷èíàåòñÿ ñåðèÿ è åå äëèíó.";
}
else if (flag == 2)
{
richTextBox1.Text = "";
}
else if (flag == 3)
{
richTextBox1.Text = "";
}
else if (flag == 4)
{
richTextBox1.Text = "";
}
else if (flag == 5)
{
richTextBox1.Text = "";
}
else if (flag == 6)
{
richTextBox1.Text = "";
}
else
{
MessageBox.Show("Ïîæàëóéñòà, âûáåðèòå çàäàíèå");
}
}
private void button10_Click(object sender, EventArgs e)
{
if (flag == 1)
{
}
}
private void Button2_Click(object sender, EventArgs e)
{
int[] array = Array.ConvertAll(arrayTextBox.Text.Split(','), int.Parse);
int Min = int.MaxValue, minIndex = -1, Max = int.MinValue, maxIndex = -1;
for (int i = 0; i < array.Length; i++)
{
if (array[i] > Max && array[i] < 0)
{
Max = array[i];
maxIndex = i;
}
if (array[i] < Min && array[i] > 0)
{
Min = array[i];
minIndex = i;
}
}
int begin = Math.Min(minIndex, maxIndex) + 1, end = Math.Max(minIndex, maxIndex) - 1;
for (; begin < end; begin++, end--)
{
int tmp = array[begin];
array[begin] = array[end];
array[end] = tmp;
}
richTextBox1.Text = string.Join(", ", array);
}
private void Button3_Click(object sender, EventArgs e)
{
int[] array = Array.ConvertAll(arrayTextBox.Text.Split(','), int.Parse);
for (int i = 0; i < array.Length; i++)
{
if (array[i] < 0)
{
Array.Resize(ref array, array.Length + 1); // Óâåëè÷èâàåì ðàçìåð ìàññèâà íà 1
for (int j = array.Length - 1; j > i + 1; j--) // Ñäâèãàåì âñå ýëåìåíòû ïîñëå òåêóùåãî íà 1 ïîçèöèþ âïðàâî
{
array[j] = array[j - 1];
}
array[i + 1] = -1; // Âñòàâëÿåì ÷èñëî 2 ïîñëå òåêóùåãî ýëåìåíòà
i++; // Ïðîïóñêàåì ñëåäóþùóþ èòåðàöèþ öèêëà, ÷òîáû íå îáðàáàòûâàòü âñòàâëåííîå ÷èñëî 2
}
}
richTextBox1.Text = string.Join(", ", array);
}
private void Button4_Click(object sender, EventArgs e)
{
int[] array = Array.ConvertAll(arrayTextBox.Text.Split(','), int.Parse);
for (int i = 0; i < array.Length; i++)
{
if (array[i] < 0)
{
// Óâåëè÷èâàåì ðàçìåð ìàññèâà íà 1
for (int j = i; j < array.Length - 1; j++) // Ñäâèãàåì âñå ýëåìåíòû ïîñëå òåêóùåãî íà 1 ïîçèöèþ âïðàâî
{
array[j] = array[j + 1];
}
Array.Resize(ref array, array.Length - 1);
i--;
}
}
richTextBox1.Text = string.Join(", ", array);
}
private void Button5_Click(object sender, EventArgs e)
{
/* int m = arrayTextBox.Lines.Length-1;
int n = arrayTextBox.Lines[0].Split(' ').Length-1;
int[,] array = new int[m, n];
for (int i = 0; i < m; i++)
{
string[] s = arrayTextBox.Lines[i].Split(' ');
for (int j = 0; j < n; j++)
{
array[i, j] = Int32.Parse(s[j]);
}
}
richTextBox1.Text = string.Join(", ", array);*/
int[,] array2 = array2D;
}
}
}

120
Praktika/Form1.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

11
Praktika/Praktika.csproj Normal file
View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

25
Praktika/Praktika.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Praktika", "Praktika.csproj", "{2C6BDC90-C996-43F3-B279-8B6A900A2FB4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2C6BDC90-C996-43F3-B279-8B6A900A2FB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C6BDC90-C996-43F3-B279-8B6A900A2FB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C6BDC90-C996-43F3-B279-8B6A900A2FB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C6BDC90-C996-43F3-B279-8B6A900A2FB4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {773D3F46-22AE-4613-9642-4D42EC797068}
EndGlobalSection
EndGlobal

17
Praktika/Program.cs Normal file
View File

@ -0,0 +1,17 @@
namespace Praktika
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}