Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Linq;
- using System.IO;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- abstract class Edition : IComparable<Edition>
- {
- protected string famaut;
- protected string name;
- protected string type;
- protected Edition(string name, string famaut)
- {
- this.name = name;
- this.famaut = famaut;
- }
- abstract public void Show();
- // метод проверки типа
- public bool CheckFam(string val)
- {
- string fam = famaut.ToLower();
- if (fam == val)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public int CompareTo(Edition x)
- {
- if (string.Compare(this.famaut, x.famaut) > 0) return 1;
- else if (string.Compare(this.famaut, x.famaut) < 0) return -1;
- else return 0;
- }
- }
- class Book : Edition
- {
- int godis;
- string izda;
- public Book(string name, string famaut, int godis, string izda)
- : base(name, famaut)
- {
- this.godis = godis;
- this.izda = izda;
- type = "Книга";
- }
- public override void Show()
- {
- Console.WriteLine("*{0}: Название - {1}, Автор - {2},\n Год издания - {3}, Издательство - {4}", type, name, famaut, godis, izda);
- Console.WriteLine("________________________________");
- }
- }
- class Article : Edition
- {
- string nazzhu;
- int nomzhu;
- int godiz;
- public Article(string name, string famaut, string nazzhu, int nomzhu, int godiz)
- : base(name, famaut)
- {
- this.nazzhu = nazzhu;
- this.nomzhu = nomzhu;
- this.godiz = godiz;
- type = "Статья";
- }
- public override void Show()
- {
- Console.WriteLine("*{0}: Название - {1}, Автор - {2},\n Название журнала - {3},\n Номер журнала - {4}, Год издания - {5}",
- type, name, famaut, nazzhu, nomzhu, godiz);
- Console.WriteLine("________________________________");
- }
- }
- class Electro : Edition
- {
- string ssil;
- string annot;
- public Electro(string name, string famaut, string ssil, string annot)
- : base(name, famaut)
- {
- this.ssil = ssil;
- this.annot = annot;
- type = "Электронный ресурс";
- }
- public override void Show()
- {
- Console.WriteLine("*{0}: Название - {1}, Автор - {2}, \n Ссылка - {3}, Аннотация - {4}", type, name, famaut, ssil, annot);
- Console.WriteLine("________________________________");
- }
- }
- class Program
- {
- static List<Edition> Input()
- {
- List<Edition> editions = new List<Edition>();
- using (StreamReader input = new StreamReader("C:/Users/Belous/source/repos/ConsoleApp11/input.txt", Encoding.GetEncoding(1251)))
- {
- string str;
- while ((str = input.ReadLine()) != null)
- {
- string[] line = str.Split(' ');
- switch (line[0])
- {
- case "книга":
- editions.Add(new Book(line[1], line[2], int.Parse(line[3]), line[4]));
- break;
- case "статья":
- editions.Add(new Article(line[1], line[2], line[3], int.Parse(line[4]), int.Parse(line[5])));
- break;
- case "электронный":
- editions.Add(new Electro(line[2], line[3], line[4], line[5]));
- break;
- }
- }
- }
- return editions;
- }
- static void Output(List<Edition> editions)
- {
- foreach (var item in editions)
- {
- item.Show();
- }
- Console.WriteLine();
- }
- static void Searchfamaut(List<Edition> editions, string famaut)
- {
- string searchfamaut = famaut.ToLower();
- var search = editions.Where(n => n.CheckFam(searchfamaut));
- foreach (var item in search)
- {
- item.Show();
- }
- Console.WriteLine();
- }
- static void Main(string[] args)
- {
- List<Edition> editions = Input();
- editions.Sort();
- Output(editions);
- //поиск по фамилии автора
- string famaut;
- do
- {
- Console.Write("Нужный автор - ");
- famaut = Console.ReadLine();
- Searchfamaut(editions, famaut);
- } while (famaut != "");
- }
- }
- }
- /*
- книга Трое Белоус 2001 Москва
- статья Любимый Камышова Жизнь 13 2019
- электронный ресурс Немцы Кондрашова god.izd/nemci Фюрер
- статья Французы Хохлова Наше 10 2004
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement