Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Prog_Tech_lab1
- {
- class Person
- {
- 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 = "Михаил";
- sname = "Булгаков";
- birthD = new DateTime(1891, 5, 15);
- }
- 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;
- }
- }
- 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 = "Тихий Дон";
- Author.Name = "Михаил";
- Author.Sname = "Шолохов";
- Author.BirthY = 1905;
- PubDate = new DateTime(1940, 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);
- }
- }
- class ResearchTeam
- {
- private string resName;
- private string orgName;
- private int regNum;
- private TimeFrame time;
- private Paper[] pubs = new Paper[100];
- public ResearchTeam()
- {
- resName = "Школьный курс";
- orgName = "Школа №29";
- regNum = 29;
- time = TimeFrame.Year;
- pubs[0] = new Paper();
- }
- public ResearchTeam(string researchName, string organisationName, int registrationNum, TimeFrame ResearchTime)
- {
- resName = researchName;
- orgName = organisationName;
- regNum = registrationNum;
- time = ResearchTime;
- }
- public string ResName { get=> resName; set=> resName = value; }
- public string OrgName { get=> orgName; set=> orgName = value; }
- public int RegNum
- {
- get => regNum;
- set
- {
- if(value > 0 && value <=99)
- {
- regNum = value;
- }
- }
- }
- public TimeFrame Time
- {
- get => time;
- set
- {
- if(value >=TimeFrame.Year && value <= TimeFrame.Long)
- time = TimeFrame.Year;
- else
- Console.WriteLine("Ошибка");
- }
- }
- public Paper[] Pubs { get=>pubs; set=>pubs = value; }
- public Paper LastPubs
- {
- get
- {
- Paper max = pubs[0];
- bool f = true;
- for (int i = 1; i < pubs.Length && f; i++)
- {
- if (pubs[i] == null)
- f = false;
- else if (pubs[i].PubDate >= max.PubDate)
- max = pubs[i];
- }
- return max;
- }
- }
- public bool this [TimeFrame index]
- {
- get
- {
- if (Time == index)
- return true;
- else
- return false;
- }
- }
- public void AddPaper (Paper newPaper)
- {
- bool f = true;
- for (int i = 0; i < Pubs.Length && f; i++)
- if (Pubs[i] == null)
- {
- Pubs[i] = newPaper;
- f = false;
- }
- if (f)
- Console.WriteLine("Список переполнен!");
- }
- public override string ToString()
- {
- string local_papers_list = "";
- for (int i = 0; i < pubs.Length && pubs[i] != null; i++)
- {
- local_papers_list += pubs[i].Name;
- local_papers_list += ", ";
- }
- return string.Format("{0} \n{1} \n{2} \n{3} \n{4}", ResName, OrgName, RegNum, Time, local_papers_list);
- }
- public string ToShortString()
- {
- return ResName + ", " + OrgName + ", " + RegNum + ", " + Time;
- }
- }
- class MainClass
- {
- public static void Main(string[] args)
- {
- var startTime = System.Diagnostics.Stopwatch.StartNew();
- ResearchTeam org1 = new ResearchTeam();
- org1.AddPaper(new Paper());
- Paper book1 = new Paper("Отцы и дети", "Иван", "Тургенеев", 1818, new DateTime(1865, 1, 1));
- org1.AddPaper(book1);
- Person man1 = new Person();
- org1.AddPaper(new Paper("Морфий", man1, new DateTime(1926, 1, 1)));
- Console.WriteLine(org1.ToShortString() + "\n _____________");
- if (org1[TimeFrame.Year])
- Console.WriteLine("Year" + "\n _____________");
- if (org1[TimeFrame.TwoYear])
- Console.WriteLine("Two Years" + "\n _____________");
- if(org1[TimeFrame.Long])
- Console.WriteLine("Long time" + "\n _____________");
- Console.WriteLine(org1.ToString() + "\n _____________");
- org1.AddPaper(new Paper("Мастер и Маргарита", man1, new DateTime(1967, 1, 1)));
- Console.WriteLine(org1.ToString() + "\n _____________");
- Console.WriteLine(org1.LastPubs+"\n _____________");
- startTime.Stop();
- var resultTime = startTime.Elapsed;
- Console.WriteLine("Время выполнения программы: {0:00}:{1:00}.{2:00}.{3:00}",
- resultTime.Hours,
- resultTime.Minutes,
- resultTime.Seconds,
- resultTime.Milliseconds);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement