Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace Prog_Tech_lab1
- {
- interface INameAndCopy
- {
- string Name { get; set; }
- object DeepCopy();
- }
- class Person : INameAndCopy
- {
- private string name;
- private string sname;
- private System.DateTime birthD;
- public string Name { get => name; set => name = value; }
- public string Sname { get => sname; set => sname = value; }
- public Person(string n, string sn, DateTime bD)
- {
- name = n;
- sname = sn;
- birthD = bD;
- }
- public Person()
- {
- name = "*Person Name*";
- sname = "*Peron SName*";
- birthD = new DateTime(1, 1, 1);
- }
- public DateTime BirthD => birthD;
- public int BirthY
- {
- get => birthD.Year;
- set => birthD = new DateTime(value, birthD.Month, birthD.Day);
- }
- public override string ToString()
- {
- return string.Format("{0} {1} {2}", Name, Sname, birthD.Year);
- }
- public string ToShortString()
- {
- return Name + " " + Sname;
- }
- public override bool Equals(Object obj)
- {
- Person person = (Person)obj;
- if (Name == person.Name && Sname == person.Sname && BirthD == person.BirthD)
- return true;
- return false;
- }
- public static bool operator ==(Person p1, Person p2)
- {
- return p1.Equals(p2);
- }
- public static bool operator !=(Person p1, Person p2)
- {
- return p1.Equals(p2);
- }
- public override int GetHashCode()
- {
- return Name.Length + Sname.Length + BirthD.Day + BirthD.Month + BirthD.Year;
- }
- public object DeepCopy()
- {
- return new Person(Name, Sname, BirthD);
- }
- }
- class Team : INameAndCopy
- {
- protected string name;
- protected int regNum;
- public Team()
- {
- name = "*Def organisation Name*";
- regNum = -1;
- }
- public Team(string organisationName, int registrationNum)
- {
- name = organisationName;
- regNum = registrationNum;
- }
- public string Name { get => name; set { if (value.Length <= 48) name = value; }}
- public int RegNum { get => regNum; set { if (value >= 1 && value <= 100) regNum = value; }}
- public virtual object DeepCopy()
- {
- return new Team(name, regNum);
- }
- public override bool Equals(object obj)
- {
- Team team = (Team)obj;
- if (Name == team.Name && RegNum == team.RegNum)
- return true;
- return false;
- }
- public static bool operator == (Team t1, Team t2)
- {
- return t1.Equals(t2);
- }
- public static bool operator !=(Team t1, Team t2)
- {
- return t1.Equals(t2);
- }
- public override int GetHashCode()
- {
- return Name.Length + RegNum;
- }
- public override string ToString()
- {
- return string.Format("Название группы: {0} \nРегистрационный номер: {1}", Name, RegNum);
- }
- }
- enum TimeFrame
- {
- Year = 1,
- TwoYear = 2,
- Long
- }
- class Paper
- {
- public string Name { get; set; }
- private Person author = new Person();
- public Person Author { get => author; set => author = value; }
- public System.DateTime PubDate { get; set; }
- public Paper()
- {
- Name = "*Name of Book*";
- Author.Name = "*Author Name*";
- Author.Sname = "*Author Sname*";
- Author.BirthY = -1;
- PubDate = new DateTime(1, 1, 1);
- }
- public Paper(string name, Person person, DateTime date)
- //требуется наличия Person существующего
- {
- Name = name;
- Author = person;
- PubDate = date;
- }
- public Paper(string name, string author_name, string author_sname, int author_birthY, DateTime publishing_date)
- // без создания отдельного Person
- {
- Name = name;
- Author.Name = author_name;
- Author.Sname = author_sname;
- Author.BirthY = author_birthY;
- PubDate = publishing_date;
- }
- public override string ToString()
- {
- return string.Format("Название книги: {0} \nАвтор Книги: {1} {2}, {3} года рождения \nГод побликации: {4}",
- Name, Author.Name, Author.Sname, Author.BirthY, PubDate);
- }
- public object DeepCopy()
- {
- return new Paper(Name, Author, PubDate);
- }
- }
- class ResearchTeam : Team, INameAndCopy
- {
- private string resName;
- private TimeFrame time;
- private List<Paper> pub = new List<Paper>();
- private List<Person> memb = new List<Person>();
- public string ResName { get; set; }
- public List<Paper> Pub { get => pub; set => pub = value; }
- public List<Person> Memb { get => memb; set => memb = value; }
- public TimeFrame Time
- {
- get => time;
- set
- {
- if (value >= TimeFrame.Year && value <= TimeFrame.Long)
- time = TimeFrame.Year;
- else
- Console.WriteLine("Ошибка");
- }
- }
- public ResearchTeam()
- {
- ResName = "*Research Name";
- Name = "*Organisation Name";
- regNum = -1;
- time = TimeFrame.Year; // Дефолтное значение
- Pub = new List<Paper>();
- Memb = new List<Person>();
- }
- public ResearchTeam(string researchName, string organisationName, int registrationNum, TimeFrame ResearchTime)
- // с инициализацией списка публикаций и участников автоматически
- {
- ResName = researchName;
- Name = organisationName;
- regNum = registrationNum;
- time = ResearchTime;
- Pub = new List<Paper>();
- Memb = new List<Person>();
- }
- public ResearchTeam(string researchName, string organisationName, int registrationNum, TimeFrame ResearchTime, List<Paper> publications, List<Person> members)
- // требуется инициализированный список публикаций и участников
- {
- ResName = researchName;
- Name = organisationName;
- regNum = registrationNum;
- time = ResearchTime;
- Pub = publications;
- Memb = members;
- }
- public Team Team
- {
- get { Team t = new Team { Name = this.Name, RegNum = this.RegNum }; return t; }
- }
- public Paper LastPubs
- {
- get
- {
- if (Pub != null)
- {
- Paper max = Pub[0];
- for (int i = 1; i < Pub.Count; i++)
- if (Pub[i].PubDate >= max.PubDate)
- max = Pub[i];
- return max;
- }
- return null;
- }
- }
- public bool this[TimeFrame index]
- {
- get
- {
- if (Time == index)
- return true;
- else
- return false;
- }
- }
- public IEnumerable GetPersons()
- {
- }
- public void AddPaper(Paper newPaper)
- {
- pub.Add(newPaper);
- }
- public void AddPerson(Person newPerson)
- {
- memb.Add(newPerson);
- }
- public override string ToString()
- {
- string local_papers_list = "";
- foreach (Paper i in pub)
- local_papers_list = local_papers_list + i.Name + ", ";
- string local_person_list = "";
- foreach(Person i in memb)
- local_person_list = local_person_list + i.Name + " " + i.Sname + ", ";
- return string.Format("{0} \n{1} \n{2} \n{3} \n{4} \n{5}", ResName, Name, RegNum, Time, local_papers_list, local_person_list);
- }
- public string ToShortString()
- {
- return ResName + ", " + Name + ", " + RegNum + ", " + Time;
- }
- public override object DeepCopy()
- {
- List<Paper> new_paper_list = pub;
- List<Person> new_person_list = memb;
- return new ResearchTeam(ResName, Name, RegNum, Time, new_paper_list, new_person_list);
- }
- }
- class MainClass
- {
- static object MakeCopy(INameAndCopy obj)
- {
- return obj.DeepCopy();
- }
- public static void Main(string[] args)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement