x3c2c5

Untitled

Mar 21st, 2023 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.60 KB | None | 0 0
  1. public class DATE
  2. {
  3.     private int year;
  4.     private int month;
  5.     private int day;
  6.  
  7.    
  8.     public DATE(int year, int month, int day)
  9.     {
  10.         this.year = year;
  11.         this.month = month;
  12.         this.day = day;
  13.     }
  14.  
  15.  
  16.     public DATE(DATE other)
  17.     {
  18.         this.year = other.year;
  19.         this.month = other.month;
  20.         this.day = other.day;
  21.     }
  22.  
  23.  
  24.     ~DATE()
  25.     {
  26.        
  27.     }
  28.  
  29.  
  30.     public int GetYear()
  31.     {
  32.         return year;
  33.     }
  34.  
  35.     public void SetYear(int year)
  36.     {
  37.         this.year = year;
  38.     }
  39.  
  40.     public int GetMonth()
  41.     {
  42.         return month;
  43.     }
  44.  
  45.     public void SetMonth(int month)
  46.     {
  47.         this.month = month;
  48.     }
  49.  
  50.     public int GetDay()
  51.     {
  52.         return day;
  53.     }
  54.  
  55.     public void SetDay(int day)
  56.     {
  57.         this.day = day;
  58.     }
  59.  
  60.    
  61.     public void Load(int year, int month, int day)
  62.     {
  63.         this.year = year;
  64.         this.month = month;
  65.         this.day = day;
  66.     }
  67.  
  68.     // Overload assignment operator
  69.     public static DATE operator =(DATE a, DATE b)
  70.     {
  71.         a.year = b.year;
  72.         a.month = b.month;
  73.         a.day = b.day;
  74.         return a;
  75.     }
  76.  
  77.    
  78.     public static void Input(DATE d)
  79.     {
  80.         Console.WriteLine("Enter year:");
  81.         d.year = Convert.ToInt32(Console.ReadLine());
  82.         Console.WriteLine("Enter month:");
  83.         d.month = Convert.ToInt32(Console.ReadLine());
  84.         Console.WriteLine("Enter day:");
  85.         d.day = Convert.ToInt32(Console.ReadLine());
  86.     }
  87.  
  88.     public static void Output(DATE d)
  89.     {
  90.         Console.WriteLine("{0}/{1}/{2}", d.month, d.day, d.year);
  91.     }
  92.     }
  93.     public class BOOK : DATE
  94.     {
  95.     private string authorName;
  96.     private string title;
  97.     private string publisher;
  98.     private int numPages;
  99.  
  100.     // Constructor
  101.     public BOOK(string authorName, string title, string publisher, int numPages, int year, int month, int day) : base(year, month, day)
  102.     {
  103.         this.authorName = authorName;
  104.         this.title = title;
  105.         this.publisher = publisher;
  106.         this.numPages = numPages;
  107.     }
  108.  
  109.     /
  110.     public BOOK(BOOK other) : base(other)
  111.     {
  112.         this.authorName = other.authorName;
  113.         this.title = other.title;
  114.         this.publisher = other.publisher;
  115.         this.numPages = other.numPages;
  116.     }
  117.  
  118.    
  119.     ~BOOK()
  120.     {
  121.        
  122.     }
  123.  
  124.    
  125.     public string GetAuthorName()
  126.     {
  127.         return authorName;
  128.     }
  129.  
  130.     public void SetAuthorName(string authorName)
  131.     {
  132.         this.authorName = authorName;
  133.     }
  134.  
  135.     public string GetTitle()
  136.     {
  137.         return title;
  138.     }
  139.  
  140.     public void SetTitle(string title)
  141.     {
  142.         this.title = title;
  143.     }
  144.  
  145.     public string GetPublisher()
  146.     {
  147.         return publisher;
  148.     }
  149.  
  150.     public void SetPublisher(string publisher)
  151.     {
  152.     this.publisher = publisher;
  153.     }
  154.     public int GetNumPages()
  155.     {
  156.     return numPages;
  157.     }
  158.  
  159.     public void SetNumPages(int numPages)
  160.     {
  161.     this.numPages = numPages;
  162.     }
  163.  
  164.  
  165. public virtual string ReadInfo()
  166. {
  167.     return GetYear().ToString();
  168. }
  169. public class LIBRARY
  170. {
  171.     private BOOK[] books;
  172.  
  173.    
  174.     public LIBRARY(int numBooks)
  175.     {
  176.         books = new BOOK[numBooks];
  177.     }
  178.  
  179.    
  180.     ~LIBRARY()
  181.     {
  182.        
  183.     }
  184.  
  185.     // Indexer to access books array
  186.     public BOOK this[int index]
  187.     {
  188.         get { return books[index]; }
  189.         set { books[index] = value; }
  190.     }
  191.  
  192.     public class Tertiary
  193.     {
  194.         private BOOK[] books;
  195.         private int currentIndex;
  196.  
  197.      
  198.         public Tertiary(BOOK[] books)
  199.         {
  200.             this.books = books;
  201.             currentIndex = 0;
  202.         }
  203.  
  204.      
  205.         public BOOK GetCurrentBook()
  206.         {
  207.             return books[currentIndex];
  208.         }
  209.  
  210.    
  211.         public void MoveNext()
  212.         {
  213.             currentIndex++;
  214.         }
  215.  
  216.        
  217.         public void Reset()
  218.         {
  219.             currentIndex = 0;
  220.         }
  221.  
  222.        
  223.         public bool HasNext()
  224.         {
  225.             return currentIndex < books.Length;
  226.         }
  227.     }
  228.  
  229.    
  230.     public class Iterator : IEnumerable<BOOK>
  231.     {
  232.         private BOOK[] books;
  233.  
  234.         // Constructor
  235.         public Iterator(BOOK[] books)
  236.         {
  237.             this.books = books;
  238.         }
  239.  
  240.        
  241.         public IEnumerator<BOOK> GetEnumerator()
  242.         {
  243.             for (int i = 0; i < books.Length; i++)
  244.             {
  245.                 yield return books[i];
  246.             }
  247.         }
  248.  
  249.        
  250.         IEnumerator IEnumerable.GetEnumerator()
  251.         {
  252.             return GetEnumerator();
  253.         }
  254.     }
  255. }
  256.  
Advertisement
Add Comment
Please, Sign In to add comment