Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Runtime.Serialization;
- namespace TasksOOP
- {
- // 1 task
- /*class Weather: ICloneable
- {
- private string city;
- private int temperature;
- private DateTime data = new DateTime();
- public string City { get => city;}
- public int Temperature { get => temperature; set => temperature = value; }
- public DateTime Data { get => data; set => data = value; }
- public Weather(string city, int temperature, DateTime dateTime)
- {
- this.city = city;
- Temperature = Converse(temperature);
- Data = dateTime;
- }
- public int Converse(int t)
- {
- return t * (9 / 5) + 32;
- }
- public object Clone()
- {
- //return new Weather(City, Temperature, Data);
- return MemberwiseClone();
- }
- }*/
- // 2 task
- /*class Tourist
- {
- private string name;
- private string direction;
- private int duration;
- //public string Name { get => name; }
- public string Direction { get => direction; set => direction = value; }
- public int Duration { get => duration; set => duration = value; }
- public string Name { get => name; set => name = value; }
- public Tourist(string name, string direction)
- {
- this.Name = name;
- Direction = direction;
- }
- public override string ToString()
- {
- return $"Турист: Имя {Name} Направление {Direction} Продолжительность {Duration} дней";
- }
- public static int operator +(Tourist tourist, int val)
- {
- return tourist.Duration + val;
- }
- }*/
- //3 task
- /*class Meropriyatie: IComparable
- {
- private string name;
- private DateTime date;
- private string mesto;
- public Meropriyatie(string name, DateTime dateTime, string mesto)
- {
- this.name = name;
- Date = dateTime;
- Mesto = mesto;
- }
- public string Name { get => name; }
- public DateTime Date { get => date; set => date = value; }
- public string Mesto { get => mesto; set => mesto = value; }
- public bool Check()
- {
- if (Date >= DateTime.Now) return true;
- else return false;
- }
- public int CompareTo(object o)
- {
- if (o is Meropriyatie os)
- {
- if (os != null)
- {
- return DateTime.Compare(this.date, os.Date);
- }
- else throw new ArgumentNullException("Нулевой элемент");
- }
- else
- {
- throw new ArgumentException("Аргумент неправильного типа!");
- }
- }
- }*/
- //4 task
- /*class Cube
- {
- private int riblength;
- public Cube(int rl)
- {
- Riblength = rl;
- }
- public int Riblength { get => riblength; set => riblength = value; }
- public int Volume()
- {
- return riblength * riblength * riblength;
- }
- public static int operator +(Cube c1, Cube c2)
- {
- return c1.Volume() + c2.Volume();
- }
- public override string ToString()
- {
- return $"Куб с ребрами = {Riblength} и объемом = {Volume()}";
- }
- }*/
- //5 task
- /*class Teacher
- {
- private string surname;
- private string kaf;
- private double rating;
- public string Surname { get => surname; set => surname = value; }
- public string Kaf { get => kaf; set => kaf = value; }
- public double Rating { get => rating; set => rating = value; }
- public override string ToString()
- {
- return $"Учитель - {Surname} с кафедры - {Kaf} с рейтингом - {Rating}";
- }
- }
- // 5 variant
- [Serializable]
- class Theacher
- {
- private string surname;
- private string cathedra;
- private double rating;
- public string Surname
- {
- get => this.surname;
- set => this.surname = value;
- }
- public string Cathedra
- {
- get => this.cathedra;
- set=> this.cathedra = value;
- }
- public double Rating
- {
- get => this.rating;
- set => this.rating = value;
- }
- public Theacher()
- {
- this.surname = "noname";
- this.cathedra = "Nope";
- this.rating = 0;
- }
- public void WriteOfFiles()
- {
- string path = "input.txt";
- using (StreamWriter writer = new StreamWriter(path, true))
- {
- writer.WriteLineAsync($"{this.surname}\t{this.cathedra}\t{this.rating}");
- }
- }
- public object Clone()
- {
- using (MemoryStream stream = new MemoryStream())
- {
- if (this.GetType().IsSerializable)
- {
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize(stream, this);
- stream.Position = 0;
- return formatter.Deserialize(stream);
- }
- return null;
- }
- }
- public override string ToString()
- {
- return $"{this.surname}\t{this.cathedra}\t{this.rating}";
- }
- }*/
- //6 task
- /*class Driver
- {
- private string surname;
- private List<String> category;
- private int exper; // стаж
- public string Surname
- {
- get => this.surname;
- set => this.surname = value;
- }
- public List<String> Category
- {
- get => this.category;
- set => this.category = value;
- }
- public int Exper
- {
- get => this.exper;
- set => this.exper = value;
- }
- public Driver(string surname, List<String> category, int exper)
- {
- this.surname = surname;
- this.category = category;
- this.exper = exper;
- }
- public override int GetHashCode()
- {
- return surname.Count() + category.Count() + exper;
- }
- public string this[int index]
- {
- get => category[index];
- set => category[index] = value;
- }
- public override string ToString()
- {
- return $"Фамилия: {this.surname}\tКатегории: {string.Join(" ", this.category)}\tСтаж: {this.exper}";
- }
- }*/
- //7 task
- /*class TK
- {
- private string name;
- private int count;
- public List<string> countries = new List<string>();
- public string Name { get => name; }
- public int Count { get => count; set => count = value; }
- public string this[int index]
- {
- get => countries[index];
- }
- public TK(string name, int count, List<string> vs)
- {
- this.name = name;
- Count = count;
- countries.AddRange(vs);
- }
- public override string ToString()
- {
- return $"Транспортная компания - {Name} с автопарком в {Count} машин, который сотрудничает с такими странами, как {string.Join(", ", countries)}";
- }
- }*/
- //8 task
- /*class Ticket: IComparable
- {
- private string name;
- private string group;
- private DateTime date;
- public string Name
- {
- get => this.name;
- }
- public string Group
- {
- get => this.group;
- set => this.group = value;
- }
- public DateTime Date
- {
- get => this.date;
- set => this.date = value;
- }
- public Ticket(string name, string group, DateTime date)
- {
- this.name = name;
- this.group = group;
- this.date = date;
- }
- public void OutputConcert(DateTime dateTime, Ticket[] tickets)
- {
- Console.WriteLine($"Концерты в {dateTime.Day}.{dateTime.Month}.{dateTime.Year}");
- foreach (var item in tickets)
- {
- if (item.date == dateTime)
- {
- Console.WriteLine(item.ToString());
- }
- }
- }
- public override string ToString()
- {
- return $"Название: {this.name}\tГруппа: {this.group}\tДата: {this.date.Day}.{this.date.Month}.{this.date.Year}";
- }
- public int CompareTo(object o)
- {
- Ticket tmp = o as Ticket;
- if (tmp != null)
- {
- return DateTime.Compare(this.date, tmp.date);
- }
- else
- throw new ArgumentException
- ("не параметр");
- }
- }*/
- //9 task
- /*class Creditka<T>
- {
- private T number;
- private int dolg;
- private DateTime date = DateTime.Now;
- public Creditka(T number, int dolg)
- {
- Number = number;
- Dolg = dolg;
- }
- public bool CheckOverdue()
- {
- if (Date > DateTime.Now) return true;
- else return false;
- }
- public static bool operator ==(Creditka<T> c1, Creditka<T> c2)
- {
- if (ReferenceEquals(c1, c2)) return true;
- if ((((object)c1) == null) || (((object)c2) == null)) return false;
- return false;
- }
- static public bool operator !=(Creditka<T> c1, Creditka<T> c2)
- {
- return !(c1 == c2);
- }
- public T Number { get => number; set => number = value; }
- public int Dolg { get => dolg; set => dolg = value; }
- public DateTime Date { get => date; set => date = value; }
- public override string ToString()
- {
- return $"Номер счета: {Number}; Дата задолженности: {Date}";
- }
- }*/
- //10 task
- /*class Picture: ICloneable
- {
- private string name;
- private string artist;
- private string museum;
- public Picture(string name, string artist, string museum)
- {
- this.name = name;
- this.artist = artist;
- Museum = museum;
- }
- public string Name { get => name;}
- public string Artist { get => artist;}
- public string Museum { get => museum; set => museum = value; }
- public override string ToString()
- {
- return $"Картина: {Name}; Художника: {Artist}; Хранится в музее: {Museum}";
- }
- public object Clone()
- {
- return MemberwiseClone();
- }
- }*/
- //26 task
- /*class Company
- {
- private string name;
- private List<string> productions = new List<string>();
- public Company(string name)
- {
- this.Name = name;
- }
- public string Name { get => name; set => name = value; }
- public List<string> Productions { get => productions; set => productions = value; }
- public void AddProd(params string[] vs)
- {
- productions.AddRange(vs);
- }
- public string this[int index]
- {
- get => productions[index];
- }
- }*/
- //27 task
- /*class Flight: IComparer<Flight>
- {
- private string mesto_otpr;
- private string mesto_pr;
- private DateTime date;
- public Flight(string mesto_otpr, string mesto_pr, DateTime date)
- {
- this.Mesto_otpr = mesto_otpr;
- this.Mesto_pr = mesto_pr;
- this.Date = date;
- }
- public string Mesto_otpr { get => mesto_otpr; set => mesto_otpr = value; }
- public string Mesto_pr { get => mesto_pr; set => mesto_pr = value; }
- public DateTime Date { get => date; set => date = value; }
- public override string ToString()
- {
- return $"{Mesto_otpr} {Mesto_pr} {Date}";
- }
- public int Compare(Flight f1, Flight f2)
- {
- if (f1.Date > f2.Date) return 1;
- if (f1.Date.Year == f2.Date.Year && f1.Date.Month == f2.Date.Month && f1.Date.Day == f2.Date.Day) return 0;
- else return -1;
- //return
- }*/
- }
- class Program
- {
- static void Main(string[] args)
- {
- //1 task
- /*List<Weather> weathers = new List<Weather>();
- Weather weather1 = new Weather("Nurlat", 37, new DateTime(2023, 01, 17));
- Weather weather2 = new Weather("Kazan", 10, new DateTime(2023, 03, 15));
- Weather weather3 = new Weather("Nurlat", -78, new DateTime(2023, 05, 27));
- weathers.Add(weather1);
- weathers.Add(weather2);
- weathers.Add(weather3);
- var linqweathers = weathers.GroupBy(c => c.Data);
- foreach (var weathers1 in linqweathers)
- {
- foreach (var item in weathers1)
- {
- Console.WriteLine($"{item.City} \t {item.Temperature} \t {item.Data}");
- }
- }*/
- // 2 task
- /*int n = 0;
- Console.Write("Введите кол-во туристов: ");
- n = Int32.Parse(Console.ReadLine());
- Tourist[] tourists = new Tourist[n];
- for (int i = 0; i < tourists.Length; i++)
- {
- Console.Write($"Введите имя для {i + 1}-го туриста: ");
- string tname = (string)(Console.ReadLine());
- Console.Write($"Введите направление для {i + 1}-го туриста: ");
- string tdirection = (string)(Console.ReadLine());
- tourists[i] = new Tourist(tname, tdirection);
- }
- for (int i = 0; i < tourists.Length; i++)
- {
- Console.Write($"Введите продолжительность отдыха для {tourists[i].Name}: ");
- int d = Int32.Parse(Console.ReadLine());
- tourists[i].Duration += d;
- }
- var selectedtourusts = tourists.Where(t => t.Duration < 7);
- foreach (var item in selectedtourusts)
- {
- Console.WriteLine(item.ToString());
- }
- Console.WriteLine($"Минимальная продолжительность отдыха: {tourists.Min(x => x.Duration)}");*/
- // 3 task
- /*Meropriyatie[] meropriyaties = { new Meropriyatie("Самы", new DateTime(2022, 05, 22), "Nurlat"), new Meropriyatie("sdasdas", new DateTime(2022, 06, 11), "Dubai"), new Meropriyatie("dasdada", new DateTime(2022, 08, 11), "Ddsai"), new Meropriyatie("fsdfsdfs", new DateTime(2022, 09, 12), "Kazan") };
- var groupMP = meropriyaties.GroupBy(x => x.Mesto);
- foreach (var item in groupMP)
- {
- foreach (var elem in item)
- {
- Console.WriteLine($"{elem.Name} - {elem.Date} - {elem.Mesto}");
- }
- }
- var cs = meropriyaties.Where(x => x.Check() == false);
- //meropriyaties
- Console.WriteLine($"Количество прошедних мероприятий {cs.Count()}");*/
- // 4 task
- /*List<Cube> cubes = new List<Cube>() { new Cube(3), new Cube(5), new Cube(4), new Cube(2), new Cube(7) };
- cubes.Add(new Cube(cubes[0] + cubes[1]));
- var selected = cubes.OrderByDescending(x => x.Riblength);
- foreach (var item in selected)
- {
- Console.WriteLine(item + "\n");
- }
- Console.WriteLine(cubes.Any(x => x.Volume() >= 5));*/
- //5 task
- /*StreamWriter streamWriter = new StreamWriter("C:\\Users\\ПК\\Desktop\\OOP\\output.txt");
- List<Teacher> teachers = new List<Teacher>();
- teachers.Add(new Teacher());
- teachers.Add(new Teacher());
- teachers.Add(new Teacher());
- teachers[0].Surname = "Musin";
- teachers[1].Surname = "Habibi";
- teachers[2].Surname = "Garfiev";
- teachers[0].Kaf = "Kaifa";
- teachers[1].Kaf = "Ne Kaifa";
- teachers[2].Kaf = "Информационная безопасность";
- teachers[0].Rating = 7.0;
- teachers[1].Rating = 3.5;
- teachers[2].Rating = 6.0;
- var ashkerer = teachers.OrderBy(x => x.Rating);
- foreach (var item in ashkerer)
- {
- Console.WriteLine(item + "\t");
- streamWriter.WriteLine(item + "\t");
- }
- Console.WriteLine("Имеются ли среди преподавателей сотрудики кафедры Информационная безопасность: " + teachers.Any(x => x.Kaf == "Информационная безопасность"));
- streamWriter.Close();
- List<Theacher> theachers = new List<Theacher>() { new Theacher(), new Theacher() };
- theachers[0].Surname = "Garfiev";
- theachers[1].Surname = "Musin";
- theachers[0].Cathedra = "Высшая математика";
- theachers[1].Cathedra = "Информационная безопасность";
- theachers[0].Rating = 9;
- theachers[1].Rating = 8;
- var sorted = theachers.OrderByDescending(theacher => theacher.Rating); // linq1
- foreach (var item in sorted)
- WriteLine(item.ToString());
- var teachs = theachers.Where(theacher => theacher.Cathedra == "Информационная безопасность");
- if (teachs.Count() > 0)
- WriteLine("Имеются преподаватели кафедры Информационная безопасность");
- else
- WriteLine("Отсутствуют преподаватели кафедры Информационная безопасность");
- Theacher theacher = theachers[0].Clone() as Theacher;
- WriteLine(theacher.ToString());*/
- // 6 task
- /*List<Driver> drivers = new List<Driver>() { new Driver("Musin", "A", 12), new Driver("Garfiev", "B", 2), new Driver("Razjevalov", "C", 3), new Driver("Valiev", "B", 22) };
- var orderedbyexp = drivers.OrderBy(x => x.Experience);
- for (int i = 0; i < orderedbyexp.Count(); i++)
- {
- string s = drivers[i][i];
- Console.WriteLine(orderedbyexp + "\t" + s);
- }
- foreach (var item in orderedbyexp)
- {
- for (int i = 0; i < drivers.Count; i++)
- {
- Console.WriteLine(item + "\t" + item[i]);
- }
- }
- List<String> list1 = new List<String>() {"A", "B", "E"};
- List<String> list2 = new List<String>() { "B", "C", "D" };
- List<Driver> drivers = new List<Driver>() { new Driver("Garfiev", list1, 1), new Driver("Musin",list2, 2) };
- WriteLine("Первая категория Ильсафа: " + drivers[1].Category[0]);
- var sorted = drivers.OrderByDescending(driver => driver.Exper); // linq1
- foreach (var item in sorted)
- WriteLine(item.ToString());
- var filter = drivers.Where(driver => driver.Category.Any(x => x == "E")); // linq2
- foreach (var item in filter)
- WriteLine(item.ToString());*/
- //7 task
- /*List<TK> tKs = new List<TK>() { new TK("dada", 6, new List<string>(){"bdadda", "dadad", "dasdasdasdsad", "nurlat", "sdsadadasdsa", "OAE"}), new TK("dada", 5, new List<string>() { "bdsa", "dadadasdasdd", "dasda12sdasdsad", "dubai", "aseqs"}), new TK("aedd", 4, new List<string>() { "aoas", "fvs", "sdad", "nurlat" }), };
- var svs = tKs.Max(x => x.countries.Count);
- Console.WriteLine($"Max: {svs}");
- var selected = tKs.Where(x => x.countries.Count == svs);
- foreach (var item in selected)
- {
- Console.WriteLine(item + "\t");
- }
- Console.WriteLine("\nSorted by Name");
- var sorted = tKs.OrderBy(x => x.Name);
- foreach (var item in sorted)
- {
- Console.WriteLine(item + "\t");
- }*/
- // 9 task
- /*List<Creditka<int>> creditkas = new List<Creditka<int>>() { new Creditka<int>(1111, 100000), new Creditka<int>(1112, 10000), new Creditka<int>(1113, 20000), new Creditka<int>(1114, 200000), new Creditka<int>(1115, 14000) };
- creditkas[0].Date = new DateTime(2022, 12, 12);
- creditkas[1].Date = new DateTime(2022, 11, 22);
- creditkas[3].Date = new DateTime(2023, 05, 26);
- Console.WriteLine(creditkas[0] == creditkas[1]);
- Console.WriteLine(creditkas[0] != creditkas[1]);
- Console.WriteLine($"Количество карт с просроченной задолженностью: {creditkas.Count(x => x.CheckOverdue() == true)}");
- var l2 = creditkas.OrderByDescending(x => x.Date);
- Console.WriteLine("Отфильтровать кредитные карты по задолженности в порядке убывания:");
- foreach (var item in l2)
- {
- Console.WriteLine(item + "\t");
- }*/
- //10 task
- /*List<Picture> pictures = new List<Picture>() { new Picture("dasdasdsa", "Шишкин", "gallert"), new Picture("annbc", "Мусин", "kazanskii museum"), new Picture("салам", "Шишкин", "gallert"), new Picture("утро в сосновом бору", "Гарфиев", "kazanskii museum")};
- var clone1 = pictures[0].Clone();
- Console.WriteLine(clone1);
- Console.WriteLine();
- var pictures1 = pictures.GroupBy(x => x.Museum);
- foreach (var item in pictures1)
- {
- foreach (var elem in item)
- {
- Console.WriteLine(elem.ToString());
- }
- }
- Console.WriteLine();
- Console.WriteLine($"Сколько картин написаны Шишкиным: {pictures.Count(x => x.Artist == "Шишкин")}");*/
- //26 task
- /*Company[] companies = new Company[4] { new Company("Danone"), new Company("Logitech"), new Company("Nike"), new Company("Adidas")};
- companies[0].AddProd("dasdad", "kakaka", "qw12o1", "da31l1");
- companies[1].AddProd("ПО", "клавиатура", "naushniki", "kovrik");
- companies[2].AddProd("krossovki", "kedi", "толстовки", "noski");
- companies[3].AddProd("худи", "свитер", "джемпер", "обцыь");
- Console.WriteLine(companies[0].Productions[0]);
- Console.WriteLine();
- var pp = companies.Select(p => new
- {
- FName = p.Name,
- PCount = p.Productions.Count
- });
- foreach (var item in pp)
- {
- Console.WriteLine($"{item.FName} {item.PCount}");
- }
- bool check = false;
- foreach (var item in companies)
- {
- for (int i = 0; i < item.Productions.Count; i++)
- {
- check = companies.Any(c => c.Productions[i] == "клавиатура");
- if (check) break;
- }
- if (check) break;
- }
- if (check) Console.WriteLine("Есть предприятие, которое производит клавиатуры");
- else Console.WriteLine("Нет предприятия, которое производит клавиатуры");
- //Console.WriteLine(companies.Any(c => c.Productions == "клавиатура"));*/
- //8 task
- /*Ticket[] tickets = { new Ticket("Nickelodion", "OneDir", new DateTime(2023, 1, 20)), new Ticket("Muzloft", "OneDir", new DateTime(2023, 1, 19)) };
- var filter = tickets.Where(ticket => ticket.Date.Day == DateTime.Now.Day && ticket.Date.Month == DateTime.Now.Month && ticket.Date.Year == DateTime.Now.Year); // linq2
- //var filter = tickets.Where(t => t.Date == DateTime.Now);
- //Console.WriteLine(DateTime.Now);
- foreach (var item in filter)
- Console.WriteLine(item.ToString());
- //linq1
- var grouping = tickets.GroupBy(ticket => ticket.Group); // linq1
- foreach (IGrouping<string, Ticket> ticket in grouping)
- {
- Console.WriteLine("Группа: " + ticket.Key);
- foreach (var q in ticket)
- {
- Console.WriteLine($"Название: {q.Name}\t Дата: {q.Date.Day}.{q.Date.Month}.{q.Date.Year}");
- }
- Console.WriteLine();
- }// linq2
- if (tickets[0].CompareTo(tickets[1]) > 0) Console.WriteLine("Концерт еще не прошел");*/
- //27 task
- /*List<Flight> flights = new List<Flight>() { new Flight("Казань", "Дубай", new DateTime(2023, 01, 26)), new Flight("Москва", "Сингапур", new DateTime(2023, 02, 12)), new Flight("Москва", "Таиланд", new DateTime(2023, 01, 24)), new Flight("Дубай", "Москва", new DateTime(2023, 02, 26)) };
- flights.Sort(flights[2]);
- foreach (var item in flights)
- {
- Console.WriteLine(item + "\t");
- }
- Console.WriteLine();
- var s = flights.Where(x => x.Mesto_pr == "Москва");
- foreach (var item in s)
- {
- Console.WriteLine(item + "\t");
- }*/
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement