Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.34 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. namespace Prog_Tech_lab1
  6. {
  7.  
  8. interface INameAndCopy
  9. {
  10. string Name { get; set; }
  11. object DeepCopy();
  12. }
  13.  
  14. class Person : INameAndCopy
  15. {
  16. private string name;
  17. private string sname;
  18. private System.DateTime birthD;
  19.  
  20. public string Name { get => name; set => name = value; }
  21. public string Sname { get => sname; set => sname = value; }
  22.  
  23. public Person(string n, string sn, DateTime bD)
  24. {
  25. name = n;
  26. sname = sn;
  27. birthD = bD;
  28. }
  29.  
  30. public Person()
  31. {
  32. name = "*Person Name*";
  33. sname = "*Peron SName*";
  34. birthD = new DateTime(1, 1, 1);
  35. }
  36.  
  37. public DateTime BirthD => birthD;
  38.  
  39. public int BirthY
  40. {
  41. get => birthD.Year;
  42. set => birthD = new DateTime(value, birthD.Month, birthD.Day);
  43. }
  44.  
  45. public override string ToString()
  46. {
  47. return string.Format("{0} {1} {2}", Name, Sname, birthD.Year);
  48. }
  49.  
  50. public string ToShortString()
  51. {
  52. return Name + " " + Sname;
  53. }
  54.  
  55. public override bool Equals(Object obj)
  56. {
  57. Person person = (Person)obj;
  58.  
  59. if (Name == person.Name && Sname == person.Sname && BirthD == person.BirthD)
  60. return true;
  61. return false;
  62.  
  63. }
  64.  
  65. public static bool operator ==(Person p1, Person p2)
  66. {
  67. return p1.Equals(p2);
  68. }
  69. public static bool operator !=(Person p1, Person p2)
  70. {
  71. return p1.Equals(p2);
  72. }
  73.  
  74. public override int GetHashCode()
  75. {
  76. return Name.Length + Sname.Length + BirthD.Day + BirthD.Month + BirthD.Year;
  77. }
  78.  
  79. public object DeepCopy()
  80. {
  81. return new Person(Name, Sname, BirthD);
  82. }
  83.  
  84. }
  85.  
  86. class Team : INameAndCopy
  87. {
  88. protected string name;
  89. protected int regNum;
  90.  
  91. public Team()
  92. {
  93. name = "*Def organisation Name*";
  94. regNum = -1;
  95. }
  96.  
  97. public Team(string organisationName, int registrationNum)
  98. {
  99. name = organisationName;
  100. regNum = registrationNum;
  101.  
  102. }
  103.  
  104. public string Name { get => name; set { if (value.Length <= 48) name = value; }}
  105. public int RegNum { get => regNum; set { if (value >= 1 && value <= 100) regNum = value; }}
  106.  
  107. public virtual object DeepCopy()
  108. {
  109. return new Team(name, regNum);
  110. }
  111.  
  112. public override bool Equals(object obj)
  113. {
  114. Team team = (Team)obj;
  115. if (Name == team.Name && RegNum == team.RegNum)
  116. return true;
  117. return false;
  118. }
  119.  
  120. public static bool operator == (Team t1, Team t2)
  121. {
  122. return t1.Equals(t2);
  123. }
  124. public static bool operator !=(Team t1, Team t2)
  125. {
  126. return t1.Equals(t2);
  127. }
  128. public override int GetHashCode()
  129. {
  130. return Name.Length + RegNum;
  131. }
  132.  
  133. public override string ToString()
  134. {
  135. return string.Format("Название группы: {0} \nРегистрационный номер: {1}", Name, RegNum);
  136. }
  137. }
  138.  
  139. enum TimeFrame
  140. {
  141. Year = 1,
  142. TwoYear = 2,
  143. Long
  144. }
  145.  
  146. class Paper
  147. {
  148. public string Name { get; set; }
  149. private Person author = new Person();
  150. public Person Author { get => author; set => author = value; }
  151. public System.DateTime PubDate { get; set; }
  152.  
  153. public Paper()
  154. {
  155. Name = "*Name of Book*";
  156. Author.Name = "*Author Name*";
  157. Author.Sname = "*Author Sname*";
  158. Author.BirthY = -1;
  159. PubDate = new DateTime(1, 1, 1);
  160. }
  161.  
  162. public Paper(string name, Person person, DateTime date)
  163. //требуется наличия Person существующего
  164. {
  165. Name = name;
  166. Author = person;
  167. PubDate = date;
  168. }
  169.  
  170. public Paper(string name, string author_name, string author_sname, int author_birthY, DateTime publishing_date)
  171. // без создания отдельного Person
  172. {
  173. Name = name;
  174. Author.Name = author_name;
  175. Author.Sname = author_sname;
  176. Author.BirthY = author_birthY;
  177. PubDate = publishing_date;
  178. }
  179.  
  180. public override string ToString()
  181. {
  182. return string.Format("Название книги: {0} \nАвтор Книги: {1} {2}, {3} года рождения \nГод побликации: {4}",
  183. Name, Author.Name, Author.Sname, Author.BirthY, PubDate);
  184. }
  185.  
  186. public object DeepCopy()
  187. {
  188. return new Paper(Name, Author, PubDate);
  189. }
  190.  
  191. }
  192.  
  193. class ResearchTeam : Team, INameAndCopy
  194. {
  195. private string resName;
  196. private TimeFrame time;
  197. private List<Paper> pub = new List<Paper>();
  198. private List<Person> memb = new List<Person>();
  199.  
  200. public string ResName { get; set; }
  201. public List<Paper> Pub { get => pub; set => pub = value; }
  202. public List<Person> Memb { get => memb; set => memb = value; }
  203.  
  204. public TimeFrame Time
  205. {
  206. get => time;
  207. set
  208. {
  209. if (value >= TimeFrame.Year && value <= TimeFrame.Long)
  210. time = TimeFrame.Year;
  211. else
  212. Console.WriteLine("Ошибка");
  213. }
  214. }
  215.  
  216. public ResearchTeam()
  217. {
  218. ResName = "*Research Name";
  219. Name = "*Organisation Name";
  220. regNum = -1;
  221. time = TimeFrame.Year; // Дефолтное значение
  222. Pub = new List<Paper>();
  223. Memb = new List<Person>();
  224. }
  225.  
  226. public ResearchTeam(string researchName, string organisationName, int registrationNum, TimeFrame ResearchTime)
  227. // с инициализацией списка публикаций и участников автоматически
  228. {
  229. ResName = researchName;
  230. Name = organisationName;
  231. regNum = registrationNum;
  232. time = ResearchTime;
  233. Pub = new List<Paper>();
  234. Memb = new List<Person>();
  235. }
  236.  
  237. public ResearchTeam(string researchName, string organisationName, int registrationNum, TimeFrame ResearchTime, List<Paper> publications, List<Person> members)
  238. // требуется инициализированный список публикаций и участников
  239. {
  240. ResName = researchName;
  241. Name = organisationName;
  242. regNum = registrationNum;
  243. time = ResearchTime;
  244. Pub = publications;
  245. Memb = members;
  246. }
  247.  
  248. public Team Team
  249. {
  250. get { Team t = new Team { Name = this.Name, RegNum = this.RegNum }; return t; }
  251. }
  252.  
  253. public Paper LastPubs
  254. {
  255. get
  256. {
  257. if (Pub != null)
  258. {
  259. Paper max = Pub[0];
  260. for (int i = 1; i < Pub.Count; i++)
  261. if (Pub[i].PubDate >= max.PubDate)
  262. max = Pub[i];
  263. return max;
  264. }
  265. return null;
  266. }
  267. }
  268. public bool this[TimeFrame index]
  269. {
  270. get
  271. {
  272. if (Time == index)
  273. return true;
  274. else
  275. return false;
  276. }
  277. }
  278.  
  279. public IEnumerable GetPersons()
  280. {
  281.  
  282. }
  283.  
  284. public void AddPaper(Paper newPaper)
  285. {
  286. pub.Add(newPaper);
  287. }
  288. public void AddPerson(Person newPerson)
  289. {
  290. memb.Add(newPerson);
  291. }
  292.  
  293. public override string ToString()
  294. {
  295. string local_papers_list = "";
  296. foreach (Paper i in pub)
  297. local_papers_list = local_papers_list + i.Name + ", ";
  298.  
  299. string local_person_list = "";
  300. foreach(Person i in memb)
  301. local_person_list = local_person_list + i.Name + " " + i.Sname + ", ";
  302.  
  303. return string.Format("{0} \n{1} \n{2} \n{3} \n{4} \n{5}", ResName, Name, RegNum, Time, local_papers_list, local_person_list);
  304. }
  305.  
  306. public string ToShortString()
  307. {
  308. return ResName + ", " + Name + ", " + RegNum + ", " + Time;
  309. }
  310.  
  311. public override object DeepCopy()
  312. {
  313. List<Paper> new_paper_list = pub;
  314. List<Person> new_person_list = memb;
  315. return new ResearchTeam(ResName, Name, RegNum, Time, new_paper_list, new_person_list);
  316. }
  317. }
  318.  
  319. class MainClass
  320. {
  321. static object MakeCopy(INameAndCopy obj)
  322. {
  323. return obj.DeepCopy();
  324. }
  325.  
  326. public static void Main(string[] args)
  327. {
  328.  
  329. }
  330. }
  331. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement