4DM3M

18

Jan 3rd, 2022
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.  
  7.     public class School
  8.     {
  9.         //!!!
  10.         delegate void noParameters();
  11.         event noParameters notify;
  12.         //!!!
  13.  
  14.         int countOfPupils;
  15.         string schoolName, directorName;
  16.         List<string> awards;
  17.         bool hasCanteen;
  18.  
  19.         //!!!
  20.         private void NotifyHandler()
  21.         {
  22.             Console.WriteLine("Вызвано событие");
  23.         }
  24.         //!!!
  25.  
  26.         public School()
  27.         {
  28.             countOfPupils = 0;
  29.             schoolName = "some school";
  30.             directorName = "some director";
  31.             awards = new List<string>();
  32.             hasCanteen = false;
  33.             //!!!
  34.             this.notify += NotifyHandler;
  35.             //!!!
  36.         }
  37.  
  38.         public School(string schoolName, string directorName, int countOfPupils, bool hasCanteen)
  39.         {
  40.             this.schoolName = schoolName;
  41.             this.directorName = directorName;
  42.             this.countOfPupils = countOfPupils;
  43.             this.hasCanteen = hasCanteen;
  44.             this.awards = new List<string>();
  45.             //!!!
  46.             this.notify += NotifyHandler;
  47.             //!!!
  48.         }
  49.  
  50.         public void NewAward(string newAward)
  51.         {
  52.             this.awards.Add(newAward);
  53.         }
  54.  
  55.         public void GetAwards()
  56.         {
  57.             Console.WriteLine("Awards List:");
  58.             for (int i = 0; i < this.awards.Count; i++)
  59.             {
  60.                 Console.WriteLine(this.awards[i]);
  61.             }
  62.             notify.Invoke();
  63.         }
  64.  
  65.         public void ChangeDirector(string newDirectorName)
  66.         {
  67.             this.directorName = newDirectorName;
  68.         }
  69.  
  70.         public void BuildCanteen()
  71.         {
  72.             if (!this.hasCanteen)
  73.             {
  74.                 this.hasCanteen = true;
  75.                 Console.WriteLine("Была построенна столовая");
  76.             }
  77.             else
  78.             {
  79.                 Console.WriteLine("Столовая уже есть");
  80.             }
  81.         }
  82.  
  83.         public void AddPupil()
  84.         {
  85.             this.countOfPupils++;
  86.         }
  87.  
  88.         public void AddPupil(int count)
  89.         {
  90.             this.countOfPupils += count;
  91.         }
  92.  
  93.         public void ChangeSchoolName(string name)
  94.         {
  95.             this.schoolName = name;
  96.         }
  97.  
  98.         public void Info()
  99.         {
  100.             Console.WriteLine($"Название школы: {this.schoolName}\n" +
  101.                 $"Директор школы: {this.directorName}\n" +
  102.                 $"Количество учащихся: {this.countOfPupils}\n" +
  103.                 $"Количество наград: {this.awards.Count}\n" +
  104.                 $"Наличие столовой: {this.hasCanteen}");
  105.         }
  106.     }
  107.  
  108.     public class University
  109.     {
  110.         //!!!
  111.         delegate void noParameters();
  112.         event noParameters notify;
  113.         //!!!
  114.  
  115.         int CountOfStudents;
  116.         string UniversityName, RectorName;
  117.         List<string> awards;
  118.         bool hasCanteen;
  119.  
  120.         private void NotifyHandler()
  121.         {
  122.             Console.WriteLine("Вызвано событие");
  123.         }
  124.  
  125.         public University()
  126.         {
  127.             CountOfStudents = 0;
  128.             UniversityName = "some University";
  129.             RectorName = "some rector";
  130.             awards = new List<string>();
  131.             hasCanteen = false;
  132.             //!!!
  133.             this.notify += NotifyHandler;
  134.             //!!!
  135.         }
  136.  
  137.         public University(string schoolName, string directorName, int countOfPupils, bool hasCanteen)
  138.         {
  139.             this.UniversityName = schoolName;
  140.             this.RectorName = directorName;
  141.             this.CountOfStudents = countOfPupils;
  142.             this.hasCanteen = hasCanteen;
  143.             this.awards = new List<string>();
  144.             //!!!
  145.             this.notify += NotifyHandler;
  146.             //!!!
  147.         }
  148.  
  149.         public void NewAward(string newAward)
  150.         {
  151.             this.awards.Add(newAward);
  152.         }
  153.  
  154.         public void GetAwards()
  155.         {
  156.             Console.WriteLine("Awards List:");
  157.             for (int i = 0; i < this.awards.Count; i++)
  158.             {
  159.                 Console.WriteLine(this.awards[i]);
  160.             }
  161.         }
  162.  
  163.         public void ChangeDirector(string newDirectorName)
  164.         {
  165.             this.RectorName = newDirectorName;
  166.         }
  167.  
  168.         public void BuildCanteen()
  169.         {
  170.             if (!this.hasCanteen)
  171.             {
  172.                 this.hasCanteen = true;
  173.                 Console.WriteLine("Была построенна столовая");
  174.             }
  175.             else
  176.             {
  177.                 Console.WriteLine("Столовая уже есть");
  178.             }
  179.         }
  180.  
  181.         public void AddPupil()
  182.         {
  183.             this.CountOfStudents++;
  184.         }
  185.  
  186.         public void AddPupil(int count)
  187.         {
  188.             this.CountOfStudents += count;
  189.         }
  190.  
  191.         public void ChangeSchoolName(string name)
  192.         {
  193.             this.UniversityName = name;
  194.         }
  195.  
  196.         public void Info()
  197.         {
  198.             Console.WriteLine($"Название университета: {this.UniversityName}\n" +
  199.                 $"Директор университета: {this.RectorName}\n" +
  200.                 $"Количество учащихся: {this.CountOfStudents}\n" +
  201.                 $"Количество наград: {this.awards.Count}\n" +
  202.                 $"Наличие столовой: {this.hasCanteen}");
  203.         }
  204.     }
  205.  
  206.     public class College
  207.     {
  208.         int CountOfStudents;
  209.         string UniversityName, director;
  210.         List<string> awards;
  211.         bool hasCanteen;
  212.  
  213.         public College()
  214.         {
  215.             CountOfStudents = 0;
  216.             UniversityName = "some college";
  217.             director = "some director";
  218.             awards = new List<string>();
  219.             hasCanteen = false;
  220.         }
  221.  
  222.         public College(string schoolName, string directorName, int countOfPupils, bool hasCanteen)
  223.         {
  224.             this.UniversityName = schoolName;
  225.             this.director = directorName;
  226.             this.CountOfStudents = countOfPupils;
  227.             this.hasCanteen = hasCanteen;
  228.             this.awards = new List<string>();
  229.         }
  230.  
  231.         public void NewAward(string newAward)
  232.         {
  233.             this.awards.Add(newAward);
  234.         }
  235.  
  236.         public void GetAwards()
  237.         {
  238.             Console.WriteLine("Awards List:");
  239.             for (int i = 0; i < this.awards.Count; i++)
  240.             {
  241.                 Console.WriteLine(this.awards[i]);
  242.             }
  243.         }
  244.  
  245.         public void ChangeDirector(string newDirectorName)
  246.         {
  247.             this.director = newDirectorName;
  248.         }
  249.  
  250.         public void BuildCanteen()
  251.         {
  252.             if (!this.hasCanteen)
  253.             {
  254.                 this.hasCanteen = true;
  255.                 Console.WriteLine("Была построенна столовая");
  256.             }
  257.             else
  258.             {
  259.                 Console.WriteLine("Столовая уже есть");
  260.             }
  261.         }
  262.  
  263.         public void AddPupil()
  264.         {
  265.             this.CountOfStudents++;
  266.         }
  267.  
  268.         public void AddPupil(int count)
  269.         {
  270.             this.CountOfStudents += count;
  271.         }
  272.  
  273.         public void ChangeSchoolName(string name)
  274.         {
  275.             this.UniversityName = name;
  276.         }
  277.  
  278.         public void Info()
  279.         {
  280.             Console.WriteLine($"Название колледжа: {this.UniversityName}\n" +
  281.                 $"Директор колледжа: {this.director}\n" +
  282.                 $"Количество учащихся: {this.CountOfStudents}\n" +
  283.                 $"Количество наград: {this.awards.Count}\n" +
  284.                 $"Наличие столовой: {this.hasCanteen}");
  285.         }
  286.     }
  287.  
  288.     public class SpecSchool
  289.     {
  290.         int CountOfStudents;
  291.         string SpecSchoolName, director;
  292.         List<string> awards;
  293.         bool hasCanteen;
  294.  
  295.         public SpecSchool()
  296.         {
  297.             CountOfStudents = 0;
  298.             SpecSchoolName = "some specSchool";
  299.             director = "some director";
  300.             awards = new List<string>();
  301.             hasCanteen = false;
  302.         }
  303.  
  304.         public SpecSchool(string schoolName, string directorName, int countOfPupils, bool hasCanteen)
  305.         {
  306.             this.SpecSchoolName = schoolName;
  307.             this.director = directorName;
  308.             this.CountOfStudents = countOfPupils;
  309.             this.hasCanteen = hasCanteen;
  310.             this.awards = new List<string>();
  311.         }
  312.  
  313.         public void NewAward(string newAward)
  314.         {
  315.             this.awards.Add(newAward);
  316.         }
  317.  
  318.         public void GetAwards()
  319.         {
  320.             Console.WriteLine("Awards List:");
  321.             for (int i = 0; i < this.awards.Count; i++)
  322.             {
  323.                 Console.WriteLine(this.awards[i]);
  324.             }
  325.         }
  326.  
  327.         public void ChangeDirector(string newDirectorName)
  328.         {
  329.             this.director = newDirectorName;
  330.         }
  331.  
  332.         public void BuildCanteen()
  333.         {
  334.             if (!this.hasCanteen)
  335.             {
  336.                 this.hasCanteen = true;
  337.                 Console.WriteLine("Была построенна столовая");
  338.             }
  339.             else
  340.             {
  341.                 Console.WriteLine("Столовая уже есть");
  342.             }
  343.         }
  344.  
  345.         public void AddPupil()
  346.         {
  347.             this.CountOfStudents++;
  348.         }
  349.  
  350.         public void AddPupil(int count)
  351.         {
  352.             this.CountOfStudents += count;
  353.         }
  354.  
  355.         public void ChangeSchoolName(string name)
  356.         {
  357.             this.SpecSchoolName = name;
  358.         }
  359.  
  360.         public void Info()
  361.         {
  362.             Console.WriteLine($"Название училища: {this.SpecSchoolName}\n" +
  363.                 $"Директор училища: {this.director}\n" +
  364.                 $"Количество учащихся: {this.CountOfStudents}\n" +
  365.                 $"Количество наград: {this.awards.Count}\n" +
  366.                 $"Наличие столовой: {this.hasCanteen}");
  367.         }
  368.     }
  369.  
  370.     public class Office
  371.     {
  372.         string officeName;
  373.         int countOfOrders, countOfWorkers;
  374.         List<string> assortiment;
  375.         bool hasFood;
  376.  
  377.         public Office()
  378.         {
  379.             this.officeName = "some Office";
  380.             this.hasFood = false;
  381.             this.countOfOrders = 0;
  382.             this.countOfOrders = 0;
  383.             this.assortiment = new List<string>();
  384.         }
  385.  
  386.         public Office(string officeName, int countOfWorkers, bool hasFood)
  387.         {
  388.             this.officeName = officeName;
  389.             this.countOfWorkers = countOfWorkers;
  390.             this.hasFood = hasFood;
  391.             this.assortiment = new List<string>();
  392.             this.countOfOrders = 0;
  393.         }
  394.  
  395.         public void GetOrder(int count)
  396.         {
  397.             this.countOfOrders += count;
  398.         }
  399.  
  400.         public void ServeOrders()
  401.         {
  402.             Console.WriteLine($"Заказов в очереди: {this.countOfOrders}");
  403.             this.countOfOrders -= this.countOfWorkers;
  404.  
  405.             if (countOfOrders <= 0)
  406.             {
  407.                 Console.WriteLine("Все заказы выполенны");
  408.                 this.countOfOrders = 0;
  409.             }
  410.             else
  411.             {
  412.                 Console.WriteLine($"Осталось заказов: {this.countOfOrders}");
  413.             }
  414.         }
  415.  
  416.         public void AddAssortiment(string someProduct, bool isFood)
  417.         {
  418.             this.assortiment.Add(someProduct);
  419.             if (!this.hasFood && isFood)
  420.             {
  421.                 this.hasFood = true;
  422.             }
  423.         }
  424.  
  425.         public void PrintAssortiment()
  426.         {
  427.             Console.WriteLine("Assortiment:");
  428.  
  429.             if (this.assortiment.Count == 0)
  430.             {
  431.                 Console.WriteLine("Empty");
  432.             }
  433.  
  434.             for (int i = 0; i < this.assortiment.Count; i++)
  435.             {
  436.                 Console.WriteLine(this.assortiment[i]);
  437.             }
  438.         }
  439.  
  440.         public void HireMan(int count)
  441.         {
  442.             this.countOfWorkers += count;
  443.         }
  444.  
  445.         public void HireMan()
  446.         {
  447.             this.countOfWorkers++;
  448.         }
  449.  
  450.         public void Info()
  451.         {
  452.             Console.WriteLine($"Название канцелярской: {this.officeName}\n" +
  453.                 $"Количество работников: {this.countOfWorkers}\n" +
  454.                 $"Товаров в ассортименте: {this.assortiment.Count}\n" +
  455.                 $"Активных заказов: {this.countOfOrders}\n" +
  456.                 $"Еда в ассортименте: {this.hasFood}");
  457.         }
  458.  
  459.     }
  460.  
  461.     delegate void voidDelegateNoParams();
  462.     delegate void voidDelegateStringParams(string source);
  463.  
  464.     static void Main()
  465.     {
  466.         School school = new("Школа", "Абрамов", 10, false);
  467.         voidDelegateNoParams delegate1 = new voidDelegateNoParams(school.GetAwards);
  468.         delegate1 += school.BuildCanteen;
  469.         delegate1 += school.BuildCanteen;
  470.         delegate1 += school.Info;
  471.         school.NewAward("молодцы");
  472.         delegate1.Invoke();
  473.         Console.WriteLine();
  474.  
  475.         University university = new("БГТУ", "Наумов", 200, true);
  476.         voidDelegateNoParams delegate2 = new voidDelegateNoParams(university.GetAwards);
  477.         delegate2 += university.Info;
  478.         university.NewAward("Лучший университет");
  479.         university.NewAward("Самый лучий университет");
  480.         university.NewAward("Ну правда самый лучший университет");
  481.         delegate2.Invoke();
  482.         Console.WriteLine();
  483.  
  484.         College mrk = new("Минский радиотехнический колледж", "кто-то новый", 1000, true);
  485.         mrk.NewAward("молодцы");
  486.         mrk.GetAwards();
  487.         Console.WriteLine();
  488.         mrk.BuildCanteen();
  489.         mrk.Info();
  490.         Console.WriteLine();
  491.  
  492.         SpecSchool PTU = new("Училище имени ______", "Иванов", 2, false);
  493.         PTU.NewAward("молодцы");
  494.         PTU.GetAwards();
  495.         Console.WriteLine();
  496.         PTU.Info();
  497.         Console.WriteLine();
  498.  
  499.         Office office = new Office("Печатная", 4, false);
  500.         office.AddAssortiment("Апельсинки", true);
  501.         office.HireMan();
  502.         office.GetOrder(3);
  503.         office.ServeOrders();
  504.         office.PrintAssortiment();
  505.         office.Info();
  506.     }
  507. }
  508.  
Advertisement
Add Comment
Please, Sign In to add comment