You are on page 1of 8

Міністерство освіти і науки України

Тернопільський національний університет ім. Івана Пулюя

Кафедра математики та
математичного моделювання

Звіт
Про виконання лабораторної роботи №3
З дисципліни “ООП”
На тему: “ Знайомство з графічними Git-
клієнтами. Масиви у мові С#.”

Виконав:
Студент групи СН-21
Козловський А. І.

Перевірив: Готович В. А.

Тернопіль, 2020 р.

Варіант 11
Тема: Знайомство з графічними Git-клієнтами. Масиви у мові С#.
Мета роботи: навчитися користуватися графічними Git-клієнтами. Набути
практичного досвіду використання одновимірних та багатовимірних масивів у
мові C#.
Виконання:
1. Складаємо програми:
Консольний додаток для завдання 1
Додаток WinForms для завдання 1
Консольний додаток для завдання 2
Додаток WinForms для завдання 2
2. Компілюємо, виправляємо помилки.
Висновок: Під час виконання лабораторної роботи №3 я ознайомився з графічними
Git-клієнтами та масивами у мові С#.
Завдання 1 (консоль)
using System;

namespace Arrays1DConsole
{
class Program
{
static void Main(string[] args)
{
System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)
System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ".";
System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
Console.WriteLine("Лабораторна робота №3");
Console.WriteLine("Виконав: Козловський А.I., група СН-21");
Console.WriteLine("Варiант 11");
Console.WriteLine("Завдання 1");
int N, q = 0, w = 0;
double product = 0;
bool f;
do
{
do
{
Console.WriteLine("Введiть кiлькiсть елементiв в масивi: ");
f = Int32.TryParse(Console.ReadLine(), out N);
if (f == false)
Console.WriteLine("Помилка! Введено невiрне значення.");
} while (!f);
double[] arr = new double[N];
Random rnd = new Random();
for (Int32 i = 0; i < N; i++)
{
arr[i] = rnd.Next(-278, 784) / 10.0;
Console.Write("{0,10}", arr[i]);
}

double max = arr[0];


for (Int32 i = 0; i < N; i++)
{
if (arr[i] > max)
{
max = arr[i];
q = i;
}
}
double min = arr[0];
for (Int32 i = 0; i < N; i++)
{
if (arr[i] < min)
{
min = arr[i];
w = i;
}
}
for (Int32 i = 0; i < N; i++)
{
if (q < i && w > i || q > i && w < i)
product *= Math.Abs(arr[i]);
}
Console.WriteLine($"добуток = {product}");
Console.WriteLine("вiдсортований массив");
for (Int32 i = 0; i < N; i++)
{
if (arr[i] == max)
{
int e = N - i;
Array.Sort(arr, q, e);
Array.Reverse(arr, q, e);
}
}
for (int i = 0; i < N; i++)
{
Console.Write("{0,12}", arr[i]);
}
} while (!false);
}
}
}

Завдання 1 (WinForms)
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 Arrays1DWinForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)
System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ".";
System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
}
double[] arr;
public Random rnd = new Random();
private void button1_Click(object sender, EventArgs e)
{
Int32 n;
n = (Int32)numericUpDown1.Value;
arr = new double[n];
dataGridViewArray.ColumnCount = n;
dataGridViewArray.RowCount = 3;
for (Int32 i = 0; i < n; i++)
{
arr[i] = Math.Round(-27.8 + rnd.NextDouble() * (78.4 + 27.8), 1);
dataGridViewArray[i, 0].Value = arr[i];
dataGridViewArray.Columns[i].HeaderText = i.ToString();
dataGridViewArray.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridViewArray.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
}
}
private void button2_Click(object sender, EventArgs e)
{
int q = 0, w = 0;
Int32 n = (Int32)numericUpDown1.Value;
double max = arr[0];
for (int i = 0; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
q = i;
}
}
double min = arr[0];
for (int i = 0; i < n; i++)
{
if (arr[i] < min)
{
min = arr[i];
w = i;
}
}
for (int y = 0; y < n; y++)
{
if (arr[y] == max)
{
int t = n - y;
Array.Sort(arr, q, t);
Array.Reverse(arr, q, t);
}
}
for (int i = 0; i < n; i++)
{
dataGridViewArray[i, 2].Value = arr[i];
}

private void button3_Click(object sender, EventArgs e)


{
double product = 0;
double max = arr[0];
int q = 0, w = 0;
Int32 n = (Int32)numericUpDown1.Value;
for (Int32 i = 0; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
q = i;
}
}
double min = arr[0];
for (Int32 i = 0; i < n; i++)
{
if (arr[i] < min)
{
min = arr[i];
w = i;
}
}
for (Int32 i = 0; i < n; i++)
{
if (q < i && w > i || q > i && w < i)
product *= Math.Abs(arr[i]);
}
prodtext.Text = product.ToString();

}
}
}

Завдання 2 (Консоль)
using System;

namespace Array2DConsole
{
class Program
{
static void Main(string[] args)
{
System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)
System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ".";
System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
Console.WriteLine("Лабораторна робота №3");
Console.WriteLine("Виконав: Козловський А.I., група СН-21");
Console.WriteLine("Варiант №11");
Console.WriteLine("Завдання 2");
int N, P;
double summ = 0;
bool f;
do
{
do
{
Console.Write("Введiть кiлькiсть рядкiв в масивi: ");
f = Int32.TryParse(Console.ReadLine(), out N);
if (f == false)
Console.WriteLine("Помилка! Введено некоректне значення.");
} while (!f);
do
{
Console.Write("Введiть кiлькiсть стовпцiв в масивi: ");
f = Int32.TryParse(Console.ReadLine(), out P);
if (f == false)
Console.WriteLine("Помилка! Введено некоректне значення.");
} while (!f);
int o = P / 2;
double[,] arr = new double[N, P];
Random rnd = new Random();
for (int i = 0; i < N; i++)
{
for (int j = 0; j < P; j++)
{
arr[i, j] = rnd.Next(-1051, 1053) / 10.0;
Console.Write("{0,9}", arr[i, j]);
}
Console.WriteLine();
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < P; j++)
{
summ += arr[i, j];
}
Console.WriteLine($"Сума {i + 1} рядка = {summ} ");
summ = 0;
}
double temp;
int k;
Console.WriteLine("Вiдсортований масив");
for (int l = 0; l < P; l++)
{
for (int j = 0; j < P; j++)
{
for (int i = 0; i < N; i++)
{
k = i + 1;
if (k == N)
{
break;
}
if (arr[i, j] > 0)
{
temp = arr[i, j];
arr[i, j] = arr[i + 1, j];
arr[i + 1, j] = temp;
}
}
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < P; j++)
{
Console.Write("{0,9}", arr[i, j]);
}
Console.WriteLine();
}

} while (!false);
}

}
}

Завдання 2 (WinForms)
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 Arrays2DWindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)
System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ".";
System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
}
public double[,] arr;
public Random rnd = new Random();
private void button1_Click(object sender, EventArgs e)
{
Int32 n = (Int32)numericCol.Value;
Int32 m = (Int32)numericRow.Value;
dataGridViewMatr.ColumnCount = n;
dataGridViewMatr.RowCount = m;
arr = new double[n, m];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
arr[i, j] = Math.Round(-10.51 + rnd.NextDouble() * (10.53 + 10.51), 1);
dataGridViewMatr[i, j].Value = arr[i, j];
dataGridViewMatr.Rows[j].HeaderCell.Value = j.ToString();
dataGridViewMatr.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridViewMatr.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dataGridViewMatr.Columns[i].HeaderText = i.ToString();
dataGridViewMatr.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
}

private void button2_Click(object sender, EventArgs e)


{
Int32 n = (Int32)numericCol.Value;
Int32 m = (Int32)numericRow.Value;
dataGridSum.ColumnCount = 1;
dataGridSum.RowCount = m;
double summ = 0.0;
int q = 0;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
dataGridSum.Rows[j].HeaderCell.Value = j.ToString();
dataGridSum.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridSum.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dataGridSum.Columns[i].HeaderText = i.ToString();
dataGridSum.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
summ += arr[i, j];
}
dataGridSum[0, 0 + q].Value = summ;
summ = 0;
q++;
}
double min = arr[0, n + 1];
for (int j = n + 1; j < 1; j++)
{
for (int i = 0; i < m; i++)
{
if (arr[i, j] < min)
{
min = arr[i, j];
}
}

textsum.Text = min.ToString();
}

}
private void button3_Click(object sender, EventArgs e)
{
Int32 n = (Int32)numericCol.Value;
Int32 m = (Int32)numericRow.Value;
dataGridSort.ColumnCount = n;
dataGridSort.RowCount = m;
double temp;
int k;
for (int c = 0; c < m; c++)
{
for (int j = 0; j < n; j++)
{
for (int i = 0; i < m; i++)
{
dataGridSort.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridSort.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dataGridSort.Columns[i].HeaderText = i.ToString();
dataGridSort.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
k = i + 1;
if (k == m)
{
break;
}
if (arr[i, j] > 0)
{
temp = arr[i, j];
arr[i, j] = arr[i + 1, j];
arr[i + 1, j] = temp;
}
dataGridSort[i, j].Value = arr[i, j];
}

}
}
}
}
}

You might also like