Advertisement
kadyr

Untitled

Oct 21st, 2022
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4.  
  5. //Читатель класс
  6.     public struct Reader
  7.     {
  8.         public string Name;
  9.         public DateTime Date;
  10.  
  11.         public Reader(string name, DateTime date)
  12.         {
  13.             Name = name;
  14.             Date = date;
  15.         }
  16.     }
  17.  
  18.     public abstract class Book
  19.     {
  20.         public string Title;
  21.         public List<string> Authors;
  22.         public int Year;
  23.         public string Publisher;
  24.         public int PagesCount;
  25.  
  26.         public Book(string title, List<string> authors, int year, string publisher, int pagesCount)
  27.         {
  28.             Title = title;
  29.             Authors = authors;
  30.             Year = year;
  31.             Publisher = publisher;
  32.             PagesCount = pagesCount;
  33.         }
  34.  
  35.         public Book()
  36.         {
  37.         }
  38.     }
  39.  
  40.     public class CatalogBook : Book
  41.     {
  42.         public int Id;
  43.         public int Quantity;
  44.         public int Instances;
  45.         public List<Reader> Picked = new();
  46.  
  47.         public CatalogBook(int id, int quantity)
  48.         {
  49.             Id = id;
  50.             Quantity = quantity;
  51.             Instances = quantity;
  52.             Picked = new List<Reader>();
  53.         }
  54.  
  55.         public CatalogBook(string title, List<string> authors, int year, string publisher, int pagesCount, int id, int quantity, int instances) : base(title, authors, year, publisher, pagesCount)
  56.         {
  57.             Id = id;
  58.             Quantity = quantity;
  59.             Instances = instances;
  60.         }
  61.  
  62. //2
  63.         public void AddBooks(int count)
  64.         {
  65.             Quantity += count;
  66.             Instances += count;
  67.         }
  68.  
  69.         public void RemoveBooks(int count)
  70.         {
  71.             if (Instances > count)
  72.             {
  73.                 Quantity -= count;
  74.                 Instances -= count;
  75.                 // return;
  76.             }
  77.             else
  78.             {
  79.                 Console.WriteLine("Книг нет в наличии");
  80.             }
  81.         }
  82.  
  83. //5
  84.         public void GiveBook(string name, DateTime time)
  85.         {
  86.             if (Instances > 0)
  87.             {
  88.                 Instances -= 1;
  89.                 Picked.Add(new Reader(name, time));
  90.             }
  91.         }
  92.  
  93. //6
  94.         public void ReturnBook(string name)
  95.         {
  96.             for (var i = 0; i < Picked.Count; i++)
  97.                 if (Picked[i].Name == name)
  98.                 {
  99.                     Instances += 1;
  100.                     Picked.Remove(Picked[i]);
  101.                     break;
  102.                 }
  103.         }
  104.  
  105. //7
  106.         public void NeVernul()
  107.         {
  108.             for (var i = 0; i < Picked.Count; i++)
  109.             {
  110.                 var datePicked = Picked[i].Date;
  111.                 if (DateTime.Now > datePicked.AddDays(366))
  112.                     Console.WriteLine(Picked[i].Name + "не вернул книги в течение года");
  113.             }
  114.         }
  115.     }
  116.  
  117.     public class Library
  118.     {
  119.         public List<CatalogBook> Catalog = new();
  120.  
  121. //1
  122.         public void AddBook(CatalogBook book)
  123.         {
  124.             Catalog.Add(book);
  125.         }
  126.  
  127.         public void RemoveBook(CatalogBook book)
  128.         {
  129.             if (Catalog.Contains(book)) Catalog.Remove(book);
  130.         }
  131.  
  132. //3
  133.         public void ShowInfo(int findX)
  134.         {
  135.             for (var i = 0; i < Catalog.Count; i++)
  136.                 if (Catalog[i].Id == findX)
  137.                 {
  138.                     Console.WriteLine("Название книги " + Catalog[i].Title
  139.                                                         + " Год выпуска " + Catalog[i].Year
  140.                                                         + " Издатель " + Catalog[i].Publisher);
  141.                     var b = Catalog[i];
  142.                     for (var j = 0; j < b.Picked.Count; j++)
  143.                     {
  144.                         Console.WriteLine("Имя читателя " + b.Picked[j].Name);
  145.                         Console.WriteLine("Дата получения " + b.Picked[j].Date);
  146.                     }
  147.                 }
  148.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement