Advertisement
kasper_k

10taskunderto1

Jan 19th, 2023
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. namespace TasksOOP
  8. {
  9.     // 1 task
  10.     /*class Weather: ICloneable
  11.     {
  12.         private string city;
  13.         private int temperature;
  14.         private DateTime data = new DateTime();    
  15.         public string City { get => city;}
  16.         public int Temperature { get => temperature; set => temperature = value; }
  17.         public DateTime Data { get => data; set => data = value; }
  18.         public Weather(string city, int temperature, DateTime dateTime)
  19.         {
  20.             this.city = city;
  21.             Temperature = Converse(temperature);
  22.             Data = dateTime;
  23.         }
  24.         public int Converse(int t)
  25.         {
  26.             return t * (9 / 5) + 32;
  27.         }
  28.         public object Clone()
  29.         {
  30.             //return new Weather(City, Temperature, Data);
  31.             return MemberwiseClone();
  32.         }
  33.     }*/
  34.     // 2 task
  35.     /*class Tourist
  36.     {
  37.         private string name;
  38.         private string direction;
  39.         private int duration;
  40.         //public string Name { get => name; }
  41.         public string Direction { get => direction; set => direction = value; }
  42.         public int Duration { get => duration; set => duration = value; }
  43.         public string Name { get => name; set => name = value; }
  44.  
  45.         public Tourist(string name, string direction)
  46.         {
  47.             this.Name = name;
  48.             Direction = direction;
  49.         }
  50.         public override string ToString()
  51.         {
  52.             return $"Турист: Имя {Name} Направление {Direction} Продолжительность {Duration} дней";
  53.         }
  54.         public static int operator +(Tourist tourist, int val)
  55.         {
  56.             return tourist.Duration + val;
  57.         }
  58.     }*/
  59.     //3 task
  60.     /*class Meropriyatie: IComparable
  61.     {
  62.         private string name;
  63.         private DateTime date;
  64.         private string mesto;
  65.  
  66.         public Meropriyatie(string name, DateTime dateTime, string mesto)
  67.         {
  68.             this.name = name;
  69.             Date = dateTime;
  70.             Mesto = mesto;
  71.         }
  72.  
  73.         public string Name { get => name; }
  74.         public DateTime Date { get => date; set => date = value; }
  75.         public string Mesto { get => mesto; set => mesto = value; }
  76.         public bool Check()
  77.         {
  78.             if (Date >= DateTime.Now) return true;
  79.             else return false;
  80.         }
  81.         public int CompareTo(object o)
  82.         {
  83.             if (o is Meropriyatie os)
  84.             {
  85.                 if (os != null)
  86.                 {
  87.                     return DateTime.Compare(this.date, os.Date);
  88.                 }
  89.                 else throw new ArgumentNullException("Нулевой элемент");
  90.             }
  91.             else
  92.             {
  93.                 throw new ArgumentException("Аргумент неправильного типа!");
  94.             }
  95.         }
  96.     }*/
  97.     //4 task
  98.     /*class Cube
  99.     {
  100.         private int riblength;
  101.  
  102.         public Cube(int rl)
  103.         {
  104.             Riblength = rl;
  105.         }
  106.  
  107.         public int Riblength { get => riblength; set => riblength = value; }
  108.         public int Volume()
  109.         {
  110.             return riblength * riblength * riblength;
  111.         }
  112.         public static int operator +(Cube c1, Cube c2)
  113.         {
  114.             return c1.Volume() + c2.Volume();
  115.         }
  116.         public override string ToString()
  117.         {
  118.             return $"Куб с ребрами = {Riblength} и  объемом = {Volume()}";
  119.         }
  120.     }*/
  121.     //5 task
  122.     /*class Teacher
  123.     {
  124.         private string surname;
  125.         private string kaf;
  126.         private double rating;
  127.         public string Surname { get => surname; set => surname = value; }
  128.         public string Kaf { get => kaf; set => kaf = value; }
  129.         public double Rating { get => rating; set => rating = value; }
  130.         public override string ToString()
  131.         {
  132.             return $"Учитель - {Surname} с кафедры - {Kaf} с рейтингом - {Rating}";
  133.         }
  134.     }*/
  135.     //6 task
  136.     /*class Driver
  137.     {
  138.         private string surname;
  139.         private List<string> categories = new List<string>();
  140.         private int experience;
  141.  
  142.         public Driver(string surname, string category, int experience)
  143.         {
  144.             Surname = surname;
  145.             categories.Add(category);
  146.             Experience = experience;
  147.         }
  148.  
  149.         public string Surname { get => surname; set => surname = value; }
  150.         public int Experience { get => experience; set => experience = value; }
  151.         public override int GetHashCode()
  152.         {
  153.             return surname.Length + experience;
  154.         }
  155.         public string this[int i]
  156.         {
  157.             get => categories[0];
  158.         }
  159.         public override string ToString()
  160.         {
  161.             return $"{Surname}  {Experience}";
  162.         }
  163.     }*/
  164.     //7 task
  165.     /*class TK
  166.     {
  167.         private string name;
  168.         private int count;
  169.         public List<string> countries = new List<string>();
  170.         public string Name { get => name; }
  171.         public int Count { get => count; set => count = value; }
  172.         public string this[int index]
  173.         {
  174.             get => countries[index];
  175.         }
  176.         public TK(string name, int count, List<string> vs)
  177.         {
  178.             this.name = name;
  179.             Count = count;
  180.             countries.AddRange(vs);
  181.         }
  182.         public override string ToString()
  183.         {
  184.             return $"Транспортная компания - {Name} с автопарком в {Count} машин, который сотрудничает с такими странами, как {string.Join(", ", countries)}";
  185.         }
  186.     }*/
  187.     //9 task
  188.     /*class Creditka<T>
  189.     {
  190.         private T number;
  191.         private int dolg;
  192.         private DateTime date = DateTime.Now;
  193.  
  194.         public Creditka(T number, int dolg)
  195.         {
  196.             Number = number;
  197.             Dolg = dolg;
  198.         }
  199.         public bool CheckOverdue()
  200.         {
  201.             if (Date > DateTime.Now) return true;
  202.             else return false;
  203.         }
  204.         public static bool operator ==(Creditka<T> c1, Creditka<T> c2)
  205.         {
  206.             if (ReferenceEquals(c1, c2)) return true;
  207.             if ((((object)c1) == null) || (((object)c2) == null)) return false;
  208.             return false;
  209.         }
  210.         static public bool operator !=(Creditka<T> c1, Creditka<T> c2)
  211.         {
  212.             return !(c1 == c2);
  213.         }
  214.         public T Number { get => number; set => number = value; }
  215.         public int Dolg { get => dolg; set => dolg = value; }
  216.         public DateTime Date { get => date; set => date = value; }
  217.         public override string ToString()
  218.         {
  219.             return $"Номер счета: {Number}; Дата задолженности: {Date}";
  220.         }
  221.  
  222.     }*/
  223.     //10 task
  224.     class Picture: ICloneable
  225.     {
  226.         private string name;
  227.         private string artist;
  228.         private string museum;
  229.  
  230.         public Picture(string name, string artist, string museum)
  231.         {
  232.             this.name = name;
  233.             this.artist = artist;
  234.             Museum = museum;
  235.         }
  236.  
  237.         public string Name { get => name;}
  238.         public string Artist { get => artist;}
  239.         public string Museum { get => museum; set => museum = value; }
  240.         public override string ToString()
  241.         {
  242.             return $"Картина: {Name}; Художника: {Artist}; Хранится в музее: {Museum}";
  243.         }
  244.         public object Clone()
  245.         {
  246.             return MemberwiseClone();
  247.         }
  248.     }
  249.  
  250.     class Program
  251.     {
  252.         static void Main(string[] args)
  253.         {
  254.             //1 task
  255.             /*List<Weather> weathers = new List<Weather>();
  256.             Weather weather1 = new Weather("Nurlat", 37, new DateTime(2023, 01, 17));
  257.             Weather weather2 = new Weather("Kazan", 10, new DateTime(2023, 03, 15));
  258.             Weather weather3 = new Weather("Nurlat", -78, new DateTime(2023, 05, 27));
  259.             weathers.Add(weather1);
  260.             weathers.Add(weather2);
  261.             weathers.Add(weather3);
  262.             var linqweathers = weathers.GroupBy(c => c.Data);
  263.             foreach (var weathers1 in linqweathers)
  264.             {
  265.                 foreach (var item in weathers1)
  266.                 {
  267.                     Console.WriteLine($"{item.City} \t {item.Temperature} \t {item.Data}");
  268.                 }
  269.             }*/
  270.             // 2 task
  271.             /*int n = 0;
  272.             Console.Write("Введите кол-во туристов: ");
  273.             n = Int32.Parse(Console.ReadLine());
  274.             Tourist[] tourists = new Tourist[n];
  275.             for (int i = 0; i < tourists.Length; i++)
  276.             {
  277.                 Console.Write($"Введите имя для {i + 1}-го туриста: ");
  278.                 string tname = (string)(Console.ReadLine());
  279.                 Console.Write($"Введите направление для {i + 1}-го туриста: ");
  280.                 string tdirection = (string)(Console.ReadLine());
  281.                 tourists[i] = new Tourist(tname, tdirection);
  282.             }
  283.             for (int i = 0; i < tourists.Length; i++)
  284.             {
  285.                 Console.Write($"Введите продолжительность отдыха для {tourists[i].Name}: ");
  286.                 int d = Int32.Parse(Console.ReadLine());
  287.                 tourists[i].Duration += d;
  288.             }
  289.             var selectedtourusts = tourists.Where(t => t.Duration < 7);
  290.             foreach (var item in selectedtourusts)
  291.             {
  292.                 Console.WriteLine(item.ToString());
  293.             }
  294.             Console.WriteLine($"Минимальная продолжительность отдыха: {tourists.Min(x => x.Duration)}");*/
  295.             // 3 task
  296.             /*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") };
  297.             var groupMP = meropriyaties.GroupBy(x => x.Mesto);
  298.             foreach (var item in groupMP)
  299.             {
  300.                 foreach (var elem in item)
  301.                 {
  302.                     Console.WriteLine($"{elem.Name} - {elem.Date} - {elem.Mesto}");
  303.                 }
  304.             }
  305.             var cs = meropriyaties.Where(x => x.Check() == false);
  306.             //meropriyaties
  307.             Console.WriteLine($"Количество прошедних мероприятий {cs.Count()}");*/
  308.             // 4 task
  309.             /*List<Cube> cubes = new List<Cube>() { new Cube(3), new Cube(5), new Cube(4), new Cube(2), new Cube(7) };
  310.             cubes.Add(new Cube(cubes[0] + cubes[1]));
  311.             var selected = cubes.OrderByDescending(x => x.Riblength);
  312.             foreach (var item in selected)
  313.             {
  314.                 Console.WriteLine(item + "\n");
  315.             }
  316.             Console.WriteLine(cubes.Any(x => x.Volume() >= 5));*/
  317.             //5 task
  318.             /*StreamWriter streamWriter = new StreamWriter("C:\\Users\\ПК\\Desktop\\OOP\\output.txt");
  319.             List<Teacher> teachers = new List<Teacher>();
  320.             teachers.Add(new Teacher());
  321.             teachers.Add(new Teacher());
  322.             teachers.Add(new Teacher());
  323.             teachers[0].Surname = "Musin";
  324.             teachers[1].Surname = "Habibi";
  325.             teachers[2].Surname = "Garfiev";
  326.             teachers[0].Kaf = "Kaifa";
  327.             teachers[1].Kaf = "Ne Kaifa";
  328.             teachers[2].Kaf = "Информационная безопасность";
  329.             teachers[0].Rating = 7.0;
  330.             teachers[1].Rating = 3.5;
  331.             teachers[2].Rating = 6.0;
  332.             var ashkerer = teachers.OrderBy(x => x.Rating);
  333.             foreach (var item in ashkerer)
  334.             {
  335.                 Console.WriteLine(item + "\t");
  336.                 streamWriter.WriteLine(item + "\t");
  337.             }
  338.             Console.WriteLine("Имеются ли среди преподавателей сотрудики кафедры Информационная безопасность: " + teachers.Any(x => x.Kaf == "Информационная безопасность"));
  339.             streamWriter.Close();*/
  340.             // 6 task
  341.             /*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) };
  342.             var orderedbyexp = drivers.OrderBy(x => x.Experience);
  343.             for (int i = 0; i < orderedbyexp.Count(); i++)
  344.             {
  345.                 string s = drivers[i][i];
  346.                 Console.WriteLine(orderedbyexp + "\t" + s);
  347.             }
  348.             foreach (var item in orderedbyexp)
  349.             {
  350.                 for (int i = 0; i < drivers.Count; i++)
  351.                 {
  352.                     Console.WriteLine(item + "\t" + item[i]);
  353.                 }
  354.                
  355.             }*/
  356.             //7 task
  357.             /*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" }), };
  358.             var svs = tKs.Max(x => x.countries.Count);
  359.             Console.WriteLine($"Max: {svs}");
  360.             var selected = tKs.Where(x => x.countries.Count == svs);
  361.             foreach (var item in selected)
  362.             {
  363.                 Console.WriteLine(item + "\t");
  364.             }
  365.             Console.WriteLine("\nSorted by Name");
  366.             var sorted = tKs.OrderBy(x => x.Name);
  367.             foreach (var item in sorted)
  368.             {
  369.                 Console.WriteLine(item + "\t");
  370.             }*/
  371.             // 9 task
  372.             /*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) };
  373.             creditkas[0].Date = new DateTime(2022, 12, 12);
  374.             creditkas[1].Date = new DateTime(2022, 11, 22);
  375.             creditkas[3].Date = new DateTime(2023, 05, 26);
  376.             Console.WriteLine(creditkas[0] == creditkas[1]);
  377.             Console.WriteLine(creditkas[0] != creditkas[1]);
  378.             Console.WriteLine($"Количество карт с просроченной задолженностью: {creditkas.Count(x => x.CheckOverdue() == true)}");
  379.             var l2 = creditkas.OrderByDescending(x => x.Date);
  380.             Console.WriteLine("Отфильтровать кредитные карты по задолженности в порядке убывания:");
  381.             foreach (var item in l2)
  382.             {
  383.                 Console.WriteLine(item + "\t");
  384.             }*/
  385.             //10 task
  386.             List<Picture> pictures = new List<Picture>() { new Picture("dasdasdsa", "Шишкин", "gallert"), new Picture("annbc", "Мусин", "kazanskii museum"), new Picture("салам", "Шишкин", "gallert"), new Picture("утро в сосновом бору", "Гарфиев", "kazanskii museum")};
  387.             var clone1 = pictures[0].Clone();
  388.             Console.WriteLine(clone1);
  389.             Console.WriteLine();
  390.             var pictures1 = pictures.GroupBy(x => x.Museum);
  391.             foreach (var item in pictures1)
  392.             {
  393.                 foreach (var elem in item)
  394.                 {
  395.                     Console.WriteLine(elem.ToString());
  396.                 }
  397.             }
  398.             Console.WriteLine();
  399.             Console.WriteLine($"Сколько картин написаны Шишкиным: {pictures.Count(x => x.Artist == "Шишкин")}");
  400.             Console.ReadKey();
  401.         }
  402.     }
  403. }
  404.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement