Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.29 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Prog_Tech_lab1
  4. {
  5. class Person
  6. {
  7. private string name;
  8. private string sname;
  9. private System.DateTime birthD;
  10.  
  11. public string Name { get=>name; set=> name = value; }
  12. public string Sname { get=>sname; set=> sname = value; }
  13.  
  14. public Person(string n, string sn, DateTime bD)
  15. {
  16. name = n;
  17. sname = sn;
  18. birthD = bD;
  19. }
  20.  
  21. public Person()
  22. {
  23. name = "Михаил";
  24. sname = "Булгаков";
  25. birthD = new DateTime(1891, 5, 15);
  26. }
  27.  
  28. public DateTime BirthD => birthD;
  29.  
  30. public int BirthY
  31. {
  32. get => birthD.Year;
  33. set => birthD = new DateTime(value, birthD.Month, birthD.Day);
  34. }
  35.  
  36. public override string ToString()
  37. {
  38. return string.Format("{0} {1} {2}", Name, Sname, birthD.Year);
  39. }
  40.  
  41. public string ToShortString()
  42. {
  43. return Name + " " + Sname;
  44. }
  45. }
  46.  
  47. enum TimeFrame
  48. {
  49. Year = 1,
  50. TwoYear = 2,
  51. Long
  52. }
  53.  
  54. class Paper
  55. {
  56. public string Name { get; set; }
  57. private Person author = new Person();
  58. public Person Author { get=>author; set=> author = value; }
  59. public System.DateTime PubDate { get; set; }
  60.  
  61. public Paper()
  62. {
  63. Name = "Тихий Дон";
  64. Author.Name = "Михаил";
  65. Author.Sname = "Шолохов";
  66. Author.BirthY = 1905;
  67. PubDate = new DateTime(1940, 1, 1);
  68. }
  69.  
  70. public Paper(string name, Person person, DateTime date) //требуется наличия Person существующего
  71. {
  72. Name = name;
  73. Author = person;
  74. PubDate = date;
  75. }
  76.  
  77. public Paper(string name, string author_name, string author_sname, int author_birthY, DateTime publishing_date) // без создания отдельного Person
  78. {
  79. Name = name;
  80. Author.Name = author_name;
  81. Author.Sname = author_sname;
  82. Author.BirthY = author_birthY;
  83. PubDate = publishing_date;
  84. }
  85.  
  86. public override string ToString()
  87. {
  88. return string.Format("Название книги: {0} \nАвтор Книги: {1} {2}, {3} года рождения \nГод побликации: {4}", Name, Author.Name, Author.Sname, Author.BirthY, PubDate);
  89. }
  90.  
  91. }
  92.  
  93. class ResearchTeam
  94. {
  95. private string resName;
  96. private string orgName;
  97. private int regNum;
  98. private TimeFrame time;
  99. private Paper[] pubs = new Paper[100];
  100.  
  101. public ResearchTeam()
  102. {
  103. resName = "Школьный курс";
  104. orgName = "Школа №29";
  105. regNum = 29;
  106. time = TimeFrame.Year;
  107. pubs[0] = new Paper();
  108. }
  109.  
  110. public ResearchTeam(string researchName, string organisationName, int registrationNum, TimeFrame ResearchTime)
  111. {
  112. resName = researchName;
  113. orgName = organisationName;
  114. regNum = registrationNum;
  115. time = ResearchTime;
  116. }
  117. public string ResName { get=> resName; set=> resName = value; }
  118. public string OrgName { get=> orgName; set=> orgName = value; }
  119. public int RegNum
  120. {
  121. get => regNum;
  122. set
  123. {
  124. if(value > 0 && value <=99)
  125. {
  126. regNum = value;
  127. }
  128. }
  129. }
  130. public TimeFrame Time
  131. {
  132. get => time;
  133. set
  134. {
  135. if(value >=TimeFrame.Year && value <= TimeFrame.Long)
  136. time = TimeFrame.Year;
  137. else
  138. Console.WriteLine("Ошибка");
  139. }
  140. }
  141. public Paper[] Pubs { get=>pubs; set=>pubs = value; }
  142. public Paper LastPubs
  143. {
  144. get
  145. {
  146. Paper max = pubs[0];
  147. bool f = true;
  148. for (int i = 1; i < pubs.Length && f; i++)
  149. {
  150. if (pubs[i] == null)
  151. f = false;
  152. else if (pubs[i].PubDate >= max.PubDate)
  153. max = pubs[i];
  154. }
  155. return max;
  156. }
  157. }
  158. public bool this [TimeFrame index]
  159. {
  160. get
  161. {
  162. if (Time == index)
  163. return true;
  164. else
  165. return false;
  166. }
  167. }
  168.  
  169. public void AddPaper (Paper newPaper)
  170. {
  171. bool f = true;
  172. for (int i = 0; i < Pubs.Length && f; i++)
  173. if (Pubs[i] == null)
  174. {
  175. Pubs[i] = newPaper;
  176. f = false;
  177. }
  178. if (f)
  179. Console.WriteLine("Список переполнен!");
  180. }
  181.  
  182. public override string ToString()
  183. {
  184. string local_papers_list = "";
  185. for (int i = 0; i < pubs.Length && pubs[i] != null; i++)
  186. {
  187. local_papers_list += pubs[i].Name;
  188. local_papers_list += ", ";
  189. }
  190.  
  191. return string.Format("{0} \n{1} \n{2} \n{3} \n{4}", ResName, OrgName, RegNum, Time, local_papers_list);
  192. }
  193.  
  194. public string ToShortString()
  195. {
  196. return ResName + ", " + OrgName + ", " + RegNum + ", " + Time;
  197. }
  198. }
  199.  
  200.  
  201. class MainClass
  202. {
  203. public static void Main(string[] args)
  204. {
  205. var startTime = System.Diagnostics.Stopwatch.StartNew();
  206.  
  207. ResearchTeam org1 = new ResearchTeam();
  208. org1.AddPaper(new Paper());
  209. Paper book1 = new Paper("Отцы и дети", "Иван", "Тургенеев", 1818, new DateTime(1865, 1, 1));
  210. org1.AddPaper(book1);
  211. Person man1 = new Person();
  212. org1.AddPaper(new Paper("Морфий", man1, new DateTime(1926, 1, 1)));
  213. Console.WriteLine(org1.ToShortString() + "\n _____________");
  214.  
  215. if (org1[TimeFrame.Year])
  216. Console.WriteLine("Year" + "\n _____________");
  217. if (org1[TimeFrame.TwoYear])
  218. Console.WriteLine("Two Years" + "\n _____________");
  219. if(org1[TimeFrame.Long])
  220. Console.WriteLine("Long time" + "\n _____________");
  221.  
  222. Console.WriteLine(org1.ToString() + "\n _____________");
  223. org1.AddPaper(new Paper("Мастер и Маргарита", man1, new DateTime(1967, 1, 1)));
  224. Console.WriteLine(org1.ToString() + "\n _____________");
  225.  
  226. Console.WriteLine(org1.LastPubs+"\n _____________");
  227.  
  228. startTime.Stop();
  229. var resultTime = startTime.Elapsed;
  230. Console.WriteLine("Время выполнения программы: {0:00}:{1:00}.{2:00}.{3:00}",
  231. resultTime.Hours,
  232. resultTime.Minutes,
  233. resultTime.Seconds,
  234. resultTime.Milliseconds);
  235. }
  236. }
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement