Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- //Читатель класс
- public struct Reader
- {
- public string Name;
- public DateTime Date;
- public Reader(string name, DateTime date)
- {
- Name = name;
- Date = date;
- }
- }
- public abstract class Book
- {
- public string Title;
- public List<string> Authors;
- public int Year;
- public string Publisher;
- public int PagesCount;
- public Book(string title, List<string> authors, int year, string publisher, int pagesCount)
- {
- Title = title;
- Authors = authors;
- Year = year;
- Publisher = publisher;
- PagesCount = pagesCount;
- }
- public Book()
- {
- }
- }
- public class CatalogBook : Book
- {
- public int Id;
- public int Quantity;
- public int Instances;
- public List<Reader> Picked = new();
- public CatalogBook(int id, int quantity)
- {
- Id = id;
- Quantity = quantity;
- Instances = quantity;
- Picked = new List<Reader>();
- }
- 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)
- {
- Id = id;
- Quantity = quantity;
- Instances = instances;
- }
- //2
- public void AddBooks(int count)
- {
- Quantity += count;
- Instances += count;
- }
- public void RemoveBooks(int count)
- {
- if (Instances > count)
- {
- Quantity -= count;
- Instances -= count;
- // return;
- }
- else
- {
- Console.WriteLine("Книг нет в наличии");
- }
- }
- //5
- public void GiveBook(string name, DateTime time)
- {
- if (Instances > 0)
- {
- Instances -= 1;
- Picked.Add(new Reader(name, time));
- }
- }
- //6
- public void ReturnBook(string name)
- {
- for (var i = 0; i < Picked.Count; i++)
- if (Picked[i].Name == name)
- {
- Instances += 1;
- Picked.Remove(Picked[i]);
- break;
- }
- }
- //7
- public void NeVernul()
- {
- for (var i = 0; i < Picked.Count; i++)
- {
- var datePicked = Picked[i].Date;
- if (DateTime.Now > datePicked.AddDays(366))
- Console.WriteLine(Picked[i].Name + "не вернул книги в течение года");
- }
- }
- }
- public class Library
- {
- public List<CatalogBook> Catalog = new();
- //1
- public void AddBook(CatalogBook book)
- {
- Catalog.Add(book);
- }
- public void RemoveBook(CatalogBook book)
- {
- if (Catalog.Contains(book)) Catalog.Remove(book);
- }
- //3
- public void ShowInfo(int findX)
- {
- for (var i = 0; i < Catalog.Count; i++)
- if (Catalog[i].Id == findX)
- {
- Console.WriteLine("Название книги " + Catalog[i].Title
- + " Год выпуска " + Catalog[i].Year
- + " Издатель " + Catalog[i].Publisher);
- var b = Catalog[i];
- for (var j = 0; j < b.Picked.Count; j++)
- {
- Console.WriteLine("Имя читателя " + b.Picked[j].Name);
- Console.WriteLine("Дата получения " + b.Picked[j].Date);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement