Advertisement
kasper_k

9 task

Jan 19th, 2023
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.35 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.  
  224.     class Program
  225.     {
  226.         static void Main(string[] args)
  227.         {
  228.             //1 task
  229.             /*List<Weather> weathers = new List<Weather>();
  230.             Weather weather1 = new Weather("Nurlat", 37, new DateTime(2023, 01, 17));
  231.             Weather weather2 = new Weather("Kazan", 10, new DateTime(2023, 03, 15));
  232.             Weather weather3 = new Weather("Nurlat", -78, new DateTime(2023, 05, 27));
  233.             weathers.Add(weather1);
  234.             weathers.Add(weather2);
  235.             weathers.Add(weather3);
  236.             var linqweathers = weathers.GroupBy(c => c.Data);
  237.             foreach (var weathers1 in linqweathers)
  238.             {
  239.                 foreach (var item in weathers1)
  240.                 {
  241.                     Console.WriteLine($"{item.City} \t {item.Temperature} \t {item.Data}");
  242.                 }
  243.             }*/
  244.             // 2 task
  245.             /*int n = 0;
  246.             Console.Write("Введите кол-во туристов: ");
  247.             n = Int32.Parse(Console.ReadLine());
  248.             Tourist[] tourists = new Tourist[n];
  249.             for (int i = 0; i < tourists.Length; i++)
  250.             {
  251.                 Console.Write($"Введите имя для {i + 1}-го туриста: ");
  252.                 string tname = (string)(Console.ReadLine());
  253.                 Console.Write($"Введите направление для {i + 1}-го туриста: ");
  254.                 string tdirection = (string)(Console.ReadLine());
  255.                 tourists[i] = new Tourist(tname, tdirection);
  256.             }
  257.             for (int i = 0; i < tourists.Length; i++)
  258.             {
  259.                 Console.Write($"Введите продолжительность отдыха для {tourists[i].Name}: ");
  260.                 int d = Int32.Parse(Console.ReadLine());
  261.                 tourists[i].Duration += d;
  262.             }
  263.             var selectedtourusts = tourists.Where(t => t.Duration < 7);
  264.             foreach (var item in selectedtourusts)
  265.             {
  266.                 Console.WriteLine(item.ToString());
  267.             }
  268.             Console.WriteLine($"Минимальная продолжительность отдыха: {tourists.Min(x => x.Duration)}");*/
  269.             // 3 task
  270.             /*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") };
  271.             var groupMP = meropriyaties.GroupBy(x => x.Mesto);
  272.             foreach (var item in groupMP)
  273.             {
  274.                 foreach (var elem in item)
  275.                 {
  276.                     Console.WriteLine($"{elem.Name} - {elem.Date} - {elem.Mesto}");
  277.                 }
  278.             }
  279.             var cs = meropriyaties.Where(x => x.Check() == false);
  280.             //meropriyaties
  281.             Console.WriteLine($"Количество прошедних мероприятий {cs.Count()}");*/
  282.             // 4 task
  283.             /*List<Cube> cubes = new List<Cube>() { new Cube(3), new Cube(5), new Cube(4), new Cube(2), new Cube(7) };
  284.             cubes.Add(new Cube(cubes[0] + cubes[1]));
  285.             var selected = cubes.OrderByDescending(x => x.Riblength);
  286.             foreach (var item in selected)
  287.             {
  288.                 Console.WriteLine(item + "\n");
  289.             }
  290.             Console.WriteLine(cubes.Any(x => x.Volume() >= 5));*/
  291.             //5 task
  292.             /*StreamWriter streamWriter = new StreamWriter("C:\\Users\\ПК\\Desktop\\OOP\\output.txt");
  293.             List<Teacher> teachers = new List<Teacher>();
  294.             teachers.Add(new Teacher());
  295.             teachers.Add(new Teacher());
  296.             teachers.Add(new Teacher());
  297.             teachers[0].Surname = "Musin";
  298.             teachers[1].Surname = "Habibi";
  299.             teachers[2].Surname = "Garfiev";
  300.             teachers[0].Kaf = "Kaifa";
  301.             teachers[1].Kaf = "Ne Kaifa";
  302.             teachers[2].Kaf = "Информационная безопасность";
  303.             teachers[0].Rating = 7.0;
  304.             teachers[1].Rating = 3.5;
  305.             teachers[2].Rating = 6.0;
  306.             var ashkerer = teachers.OrderBy(x => x.Rating);
  307.             foreach (var item in ashkerer)
  308.             {
  309.                 Console.WriteLine(item + "\t");
  310.                 streamWriter.WriteLine(item + "\t");
  311.             }
  312.             Console.WriteLine("Имеются ли среди преподавателей сотрудики кафедры Информационная безопасность: " + teachers.Any(x => x.Kaf == "Информационная безопасность"));
  313.             streamWriter.Close();*/
  314.             // 6 task
  315.             /*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) };
  316.             var orderedbyexp = drivers.OrderBy(x => x.Experience);
  317.             for (int i = 0; i < orderedbyexp.Count(); i++)
  318.             {
  319.                 string s = drivers[i][i];
  320.                 Console.WriteLine(orderedbyexp + "\t" + s);
  321.             }
  322.             foreach (var item in orderedbyexp)
  323.             {
  324.                 for (int i = 0; i < drivers.Count; i++)
  325.                 {
  326.                     Console.WriteLine(item + "\t" + item[i]);
  327.                 }
  328.                
  329.             }*/
  330.             //7 task
  331.             /*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" }), };
  332.             var svs = tKs.Max(x => x.countries.Count);
  333.             Console.WriteLine($"Max: {svs}");
  334.             var selected = tKs.Where(x => x.countries.Count == svs);
  335.             foreach (var item in selected)
  336.             {
  337.                 Console.WriteLine(item + "\t");
  338.             }
  339.             Console.WriteLine("\nSorted by Name");
  340.             var sorted = tKs.OrderBy(x => x.Name);
  341.             foreach (var item in sorted)
  342.             {
  343.                 Console.WriteLine(item + "\t");
  344.             }*/
  345.             // 9 task
  346.             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) };
  347.             creditkas[0].Date = new DateTime(2022, 12, 12);
  348.             creditkas[1].Date = new DateTime(2022, 11, 22);
  349.             creditkas[3].Date = new DateTime(2023, 05, 26);
  350.             Console.WriteLine(creditkas[0] == creditkas[1]);
  351.             Console.WriteLine(creditkas[0] != creditkas[1]);
  352.             Console.WriteLine($"Количество карт с просроченной задолженностью: {creditkas.Count(x => x.CheckOverdue() == true)}");
  353.             var l2 = creditkas.OrderByDescending(x => x.Date);
  354.             Console.WriteLine("Отфильтровать кредитные карты по задолженности в порядке убывания:");
  355.             foreach (var item in l2)
  356.             {
  357.                 Console.WriteLine(item + "\t");
  358.             }
  359.             Console.ReadKey();
  360.         }
  361.     }
  362. }
  363.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement