Compare commits

..

9 Commits

Author SHA1 Message Date
idkWhatUserNameToUse
1804300a41 added comments 2023-06-02 19:38:58 +03:00
idkWhatUserNameToUse
901f3764cc added comments 2023-06-02 19:32:43 +03:00
idkWhatUserNameToUse
4ce763a535 added lab6 (without comments yet :3) 2023-05-30 21:44:47 +03:00
idkWhatUserNameToUse
8548f7c734 modified text message 2023-05-18 11:19:11 +03:00
Maxim Papko
5e1040d05b Delete Lab2 directory 2023-05-18 11:18:18 +03:00
Maxim Papko
5f4e295f72 Create READ ME 2023-05-18 11:16:04 +03:00
idkWhatUserNameToUse
534f830672 competed lab4 2023-05-18 11:12:06 +03:00
idkWhatUserNameToUse
d127ee3456 completed lab2 2023-05-17 09:54:33 +03:00
idkWhatUserNameToUse
b1f37e7fae fixed lab3 2023-05-12 13:09:47 +03:00
6 changed files with 252 additions and 36 deletions

View File

@@ -1,32 +0,0 @@
using System;
public class Laba2
{
public static void Main(string[] args)
{
const int a = 2;
int[][] b = new[]
{
new int[] { 1, 2, 8 },
new int[] { 3, 4, 5 },
new int[] { 6, 7, 9 }
};
calculation(b, a);
}
private static int[][] calculation(int[][] b, int a)
{
int[][]c = new int[b.Length][b[0].Length]; //недопустимий специфікатор рангу: вимагається "," або "]";
for (int i = 0; i < b.Length; i++)
{
c[i] = new int[b[i].Length];
for (int j = 0; j < b[i].Length; j++)
{
c[i][j] = b[i][j] * a;
}
}
return c;
}
}

40
Lab3/Lab2/Lab2/Program.cs Normal file
View File

@@ -0,0 +1,40 @@
using System;
public class Laba2
{
public static void Main(string[] args)
{
const int a = 2;
int[,] b = new[,] //створення матриці;
{
{ 1, 2, 8 },
{ 3, 4, 5 },
{ 6, 7, 9 }
};
int rows = b.GetLength(0); //отримання довжини рядків
int cols = b.GetLength(1); //отримання довжини стовпців
for (int i = 0; i < rows; i++)
{
int Avg = 0;
for (int j = 0; j < cols; j++)
{
Console.Write(b[i, j] + " "); // перебір матриці для обчислення середнього значення рядка
Avg += b[i, j];
}
Avg = Avg / cols;
Console.Write($"-average of row is:{Avg};" );
Console.WriteLine(" ");
}
Console.WriteLine(" ");
for (int x = 0; x < rows; x++)
{
for (int y = 0; y < cols; y++)
{
Console.Write(b[x, y] * a + " "); //виведення матриці, помноженої на константу
}
Console.WriteLine(" ");
}
}
}

View File

@@ -15,17 +15,17 @@ class Lab3
int[] amountOfWords = new int[textSplit.Length];
for (int i = 0; i < textSplit.Length; i++)
{
string[] words = textSplit[i].Trim().Split(' ');
string[] words = textSplit[i].Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries);
amountOfWords[i] = words.Length;
}
// створюємо Dictionary, де ключ - кількість слів у реченні, а значення - речення
Dictionary<int, string> sentenceDictionary = new Dictionary<int, string>();
Dictionary<string, int> sentenceDictionary = new Dictionary<string, int>();
for (int i = 0; i < textSplit.Length; i++)
{
sentenceDictionary.Add(amountOfWords[i], textSplit[i]);
sentenceDictionary.Add(textSplit[i],amountOfWords[i] );
}
var sortedDict = sentenceDictionary.OrderBy(x => x.Key).ToDictionary(x => x.Value, x => x.Key);
var sortedDict = sentenceDictionary.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
Console.WriteLine(String.Join(";", sortedDict.Keys));

86
Lab3/Lab4/Lab4/Program.cs Normal file
View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Furniture
{
// 5 полів
private string type;
private string material;
private string color;
private int price;
private int amount;
// конструктор з атрибутами
public Furniture(string type, string material, string color, int price, int amount)
{
this.type = type;
this.material = material;
this.color = color;
this.price = price;
this.amount = amount;
}
// методи для повернення атрибутів
public string getType()
{
return type;
}
public string getMaterial()
{
return material;
}
public string getColor()
{
return color;
}
public int getPrice()
{
return price;
}
public int getAmount()
{
return amount;
}
public static void Main(string[] args)
{
Furniture[] furnitureArr = {
new Furniture("шафа", "дерево", "коричневий", 5000, 2),
new Furniture("стiл", "скло", "чорний", 3000, 3),
new Furniture("лiжко", "метал", "срiблястий", 8000, 1),
new Furniture("диван", "тканина", "сiрий", 10000, 2),
new Furniture("стiлець", "метал", "синій", 500, 4)
};
// Сортування масиву за ціною за зростанням
var sorted = furnitureArr.OrderBy(ob => ob.price).ToArray();
// Вивести відсортований масив
Console.WriteLine("Всортований за цiною (за зростанням):");
foreach (Furniture f in sorted)
{
Console.WriteLine(f.getType() + " - " + f.getPrice() + " грн;");
}
Console.WriteLine(' ');
// Сортування масиву за кількістю за спаданням
var sortedReversery = furnitureArr.OrderBy(ob => ob.amount).ToArray().Reverse();
// Вивести відсортований масив
Console.WriteLine("Всортований за кiлькiстю (за спаданням):");
foreach (Furniture f in sortedReversery)
{
Console.Write($"{f.getType()} - {f.getAmount()}; " );
}
Console.WriteLine(' ');
}
}
}

121
Lab6/Lab6/Program.cs Normal file
View File

@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Formats.Asn1;
// Визначити ієрархію рухомого складу залізничного транспорту.Створити пасажирський потяг.Порахувати загальну чисельність пасажирів і багажу в потязі.
// Провести сортування вагонів потягу за рівнем комфортності. Знайти вагон в потязі, що відповідає заданому діапазону кількості пасажирів.
class Lab6
{
public static void Main(string[] args)
{
List<Wagons> wagons = new List<Wagons>(); //створюємо лист-список вагонів;
// Додаємо вагони за допомогою класу Wagons;
wagons.Add(new Wagons.PassengerWagons("Пасажирський", 100, 100, "Вищий", 10));
wagons.Add(new Wagons.PassengerWagons("Пасажирський", 50, 48, "Середнiй", 20));
wagons.Add(new Wagons.PassengerWagons("Пасажирський", 20, 15, "Низький", 30));
wagons.Add(new Wagons.FreightWagons("Вантажний", 10, 10));
wagons.Add(new Wagons.FreightWagons("Вантажний", 20, 20));
wagons.Add(new Wagons.FreightWagons("Вантажний", 30, 30));
Console.WriteLine("Усi вагони:"); //відображення всіх вагонів;
foreach (Wagons wagon in wagons)
{
Console.WriteLine(wagon.GetType() + ": " + wagon.GetPassengers() + " пасажирiв(-а), " + wagon.GetBaggage() +
" валiз/контейнерiв, " + wagon.GetComfort() + ", " + wagon.GetAmount() + ";");
}
int amountOfPassangers = 0; //обчислення загальної кількості пасажирів;
foreach (Wagons p in wagons)
{
amountOfPassangers += p.GetPassengers();
}
var sorted = wagons.OrderByDescending(ob => ob.GetComfort()).ToArray(); //сортування вагонів за рівнем комфорту;
Console.WriteLine("\nКiлькiсть пасажиру пасажирському вагонi: " + amountOfPassangers + ";");
Console.WriteLine("\nВеддiть мiнiмальну кiлькiсть пасажирiв: ");
var minPassangers = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Веддiть максимальну кiлькiсть пасажирiв: ");
var maxPassangers = Convert.ToInt32(Console.ReadLine());
foreach (Wagons t in wagons)
{
if (t.GetPassengers() != null && t.GetPassengers() >= minPassangers && t.GetPassengers() <= maxPassangers) //пошук вагону за кількістю пасажирів;
{
Console.Write(t.GetType() + " - " + t.GetPassengers()+"; ");
}
else
{
throw (new InvalidOperationException("Немає такого вагону;"));
}
}
}
class Wagons
{
private string type; // тип вагону
private int passengers; // кількість пасажирів
private int baggage; // кількість багажу в тоннах
private string comfort; // рейтиг комфорту вагону
private int amount; // кількість вагонів
public Wagons(string type, int? passengers, int? baggage, string comfort, int amount) //конструктор вагонів;
{
this.type = type;
this.passengers = Convert.ToInt32(passengers);
this.baggage = Convert.ToInt32(baggage);
this.comfort = comfort;
this.amount = amount;
}
public string GetType() //геттери атрибутів класу;
{
return type;
}
public int GetPassengers()
{
return passengers;
}
public int? GetBaggage()
{
return baggage;
}
public string GetComfort()
{
return comfort;
}
public int GetAmount()
{
return amount;
}
// підклас Пасажирський вагон який наслідує батьківський клас Вагони;
public class PassengerWagons : Wagons
{
public PassengerWagons(string type, int passengers, int baggage, string comfort, int amount) : base(type,
passengers, baggage, comfort, amount)
{
}
}
// підклас Вантажний вагон який наслідує батьківський клас Вагони;
public class FreightWagons : Wagons
{
public FreightWagons(string type, int baggage, int amount) : base(type, null, baggage, null, amount)
{
}
}
}
}

1
READ ME Normal file
View File

@@ -0,0 +1 @@
Files with lab2,3,4 located in in Lab3. My excuses for confusing you