Ochkasty_Dino

Practicum14-II-5

Nov 25th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.55 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.  
  8. namespace ConsoleApp2
  9. {
  10.  
  11.     struct Sauri : IComparable<Sauri>
  12.     {
  13.  
  14.         public string name, sur, patr;
  15.         public int year;
  16.         public string pos;
  17.         public int salary;
  18.         public int exp;
  19.         public Sauri(string sur, string name, string patr, int year, string pos, int salary, int exp)
  20.         {
  21.             this.name = name;
  22.             this.sur = sur;
  23.             this.patr = patr;
  24.             this.pos = pos;
  25.             this.year = year;
  26.             this.salary = salary;
  27.             this.exp = exp;
  28.         }
  29.  
  30.         public void Show()
  31.         {
  32.             Console.WriteLine("* {0} {1} {2}, принят на работу в {3} году, должность - {4}, зарплата - {5} руб, стаж - {6} месяцев", sur, name, patr, year, pos, salary, exp);
  33.         }
  34.         public int CompareTo(Sauri obj) //проводим переопределением метода
  35.         { // CompareTo(T) так, чтобы сравнение элементов
  36.             if ( this.exp == obj.exp ) // типа SPoint проводилось по возрастанию
  37.             { ///расстоянию от точки до начала координат
  38.                 return 0;
  39.             }
  40.             else
  41.             {
  42.                 if (this.exp > obj.exp)
  43.                 {
  44.                     return 1;
  45.                 }
  46.                
  47.             else
  48.                 {
  49.                     return -1;
  50.                 }
  51.             }
  52.         }
  53.  
  54.     }
  55.     class Program
  56.     {
  57.         static public Sauri[] Input()
  58.         {
  59.             using (StreamReader fileIn = new StreamReader(@"C:/Users/belousaa/Documents/in2.txt", Encoding.GetEncoding(1251)))
  60.             {
  61.                 int n = int.Parse(fileIn.ReadLine());
  62.                 Sauri[] ar = new Sauri[n]; //описание массива структур
  63.                 for (int i = 0; i < n; i++)
  64.                 {
  65.                     string[] text = fileIn.ReadLine().Split(' ');
  66.                     ar[i] = new Sauri(text[0], text[1], text[2], int.Parse(text[3]), text[4], int.Parse(text[5]), int.Parse(text[6])); //вызов конструктора структуры
  67.                 }
  68.                 return ar; //в качестве результата метод возвращает ссылку на массив структур
  69.             }
  70.  
  71.         }
  72.  
  73.        
  74.  
  75.         static void Print(Sauri[] array, int zar) //выводим данные на экран
  76.         {
  77.             for(int i=0;i<array.Length;i++)
  78.             {
  79.                 if (array[i].salary < zar)
  80.                 {
  81.                     array[i].Show(); //обращается к методу экземпляра структуры
  82.                 }
  83.             }
  84.         }
  85.         static void Main(string[] args)
  86.         {
  87.             Sauri[] array = Input();
  88.             Console.WriteLine("Введите пожалуйста порог зарплаты: ");
  89.             int zar = int.Parse(Console.ReadLine());
  90.             Array.Sort(array);
  91.             Print(array,zar);
  92.         }
  93.     }
  94. }
  95. /*
  96. 4
  97. Белоус Алексей Андреевич 2019 СПД 31000 5
  98. Ножов Александр Михайлович 2019 СПД 44000 8
  99. Герцог Александра Сергеевна 2018 Кассир 22500 13
  100. Алукаев Тимур Александрович 2019 СПД 27000 3
  101. */
Add Comment
Please, Sign In to add comment