Advertisement
Ochkasty_Dino

Practicum-18-19-3

Dec 23rd, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.49 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4. using System.IO;
  5. using System.Collections.Generic;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     abstract class Edition : IComparable<Edition>
  10.     {
  11.         protected string famaut;
  12.         protected string name;
  13.         protected string type;
  14.  
  15.         protected Edition(string name, string famaut)
  16.         {
  17.             this.name = name;
  18.             this.famaut = famaut;
  19.         }
  20.  
  21.         abstract public void Show();
  22.  
  23.         // метод проверки типа
  24.         public bool CheckFam(string val)
  25.         {
  26.             string fam = famaut.ToLower();
  27.             if (fam == val)
  28.             {
  29.                 return true;
  30.             }
  31.             else
  32.             {
  33.                 return false;
  34.             }
  35.         }
  36.  
  37.         public int CompareTo(Edition x)
  38.         {
  39.             if (string.Compare(this.famaut, x.famaut) > 0) return 1;
  40.             else if (string.Compare(this.famaut, x.famaut) < 0) return -1;
  41.             else return 0;
  42.         }
  43.  
  44.     }
  45.  
  46.     class Book : Edition
  47.     {
  48.         int godis;
  49.         string izda;
  50.  
  51.         public Book(string name, string famaut, int godis, string izda)
  52.             : base(name, famaut)
  53.         {
  54.             this.godis = godis;
  55.             this.izda = izda;
  56.             type = "Книга";
  57.         }
  58.  
  59.         public override void Show()
  60.         {
  61.             Console.WriteLine("*{0}: Название - {1}, Автор - {2},\n Год издания - {3}, Издательство - {4}", type, name, famaut, godis, izda);
  62.             Console.WriteLine("________________________________");
  63.         }
  64.     }
  65.  
  66.     class Article : Edition
  67.     {
  68.         string nazzhu;
  69.         int nomzhu;
  70.         int godiz;
  71.  
  72.         public Article(string name, string famaut, string nazzhu, int nomzhu, int godiz)
  73.             : base(name, famaut)
  74.         {
  75.             this.nazzhu = nazzhu;
  76.             this.nomzhu = nomzhu;
  77.             this.godiz = godiz;
  78.             type = "Статья";
  79.         }
  80.  
  81.         public override void Show()
  82.         {
  83.             Console.WriteLine("*{0}: Название - {1}, Автор - {2},\n Название журнала - {3},\n Номер журнала - {4}, Год издания - {5}",
  84.                 type, name, famaut, nazzhu, nomzhu, godiz);
  85.             Console.WriteLine("________________________________");
  86.         }
  87.     }
  88.     class Electro : Edition
  89.     {
  90.         string ssil;
  91.         string annot;
  92.  
  93.         public Electro(string name, string famaut, string ssil, string annot)
  94.            : base(name, famaut)
  95.         {
  96.             this.ssil = ssil;
  97.             this.annot = annot;
  98.             type = "Электронный ресурс";
  99.         }
  100.  
  101.         public override void Show()
  102.         {
  103.             Console.WriteLine("*{0}: Название - {1}, Автор - {2}, \n Ссылка - {3}, Аннотация - {4}", type, name, famaut, ssil, annot);
  104.             Console.WriteLine("________________________________");
  105.         }
  106.     }
  107.  
  108.  
  109.     class Program
  110.     {
  111.  
  112.         static List<Edition> Input()
  113.         {
  114.             List<Edition> editions = new List<Edition>();
  115.             using (StreamReader input = new StreamReader("C:/Users/Belous/source/repos/ConsoleApp11/input.txt", Encoding.GetEncoding(1251)))
  116.             {
  117.                 string str;
  118.                 while ((str = input.ReadLine()) != null)
  119.                 {
  120.                     string[] line = str.Split(' ');
  121.                     switch (line[0])
  122.                     {
  123.                         case "книга":
  124.                             editions.Add(new Book(line[1], line[2], int.Parse(line[3]), line[4]));
  125.                             break;
  126.                         case "статья":
  127.                             editions.Add(new Article(line[1], line[2], line[3], int.Parse(line[4]), int.Parse(line[5])));
  128.                             break;
  129.                         case "электронный":
  130.                             editions.Add(new Electro(line[2], line[3], line[4], line[5]));
  131.                             break;
  132.                     }
  133.                 }
  134.             }
  135.             return editions;
  136.         }
  137.  
  138.         static void Output(List<Edition> editions)
  139.         {
  140.             foreach (var item in editions)
  141.             {
  142.                 item.Show();
  143.             }
  144.             Console.WriteLine();
  145.         }
  146.  
  147.         static void Searchfamaut(List<Edition> editions, string famaut)
  148.         {
  149.             string searchfamaut = famaut.ToLower();
  150.             var search = editions.Where(n => n.CheckFam(searchfamaut));
  151.             foreach (var item in search)
  152.             {
  153.                 item.Show();
  154.             }
  155.  
  156.  
  157.             Console.WriteLine();
  158.         }
  159.  
  160.         static void Main(string[] args)
  161.         {
  162.             List<Edition> editions = Input();
  163.             editions.Sort();
  164.             Output(editions);
  165.             //поиск по фамилии автора
  166.             string famaut;
  167.  
  168.             do
  169.             {
  170.                 Console.Write("Нужный автор - ");
  171.                 famaut = Console.ReadLine();
  172.                 Searchfamaut(editions, famaut);
  173.             } while (famaut != "");
  174.         }
  175.     }
  176. }
  177. /*
  178. книга Трое Белоус 2001 Москва
  179. статья Любимый Камышова Жизнь 13 2019
  180. электронный ресурс Немцы Кондрашова god.izd/nemci Фюрер
  181. статья Французы Хохлова Наше 10 2004
  182. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement