Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TPhome
- {
- class Person
- {
- string name;
- string familia;
- DateTime birthday;
- public Person()
- {
- birthday = new DateTime(2000, 10, 10);
- name = "Иван";
- familia = "Иванов";
- }
- public Person(string name, string familia, DateTime date)
- {
- this.name = name;
- this.familia = familia;
- this.birthday = date;
- }
- public string Name
- {
- set { name = value; }
- get { return name; }
- }
- public string Familia
- {
- set { familia = value; }
- get { return familia; }
- }
- public DateTime Birthday
- {
- set { birthday = value; }
- get { return birthday; }
- }
- public int Year
- {
- set { birthday = birthday.AddYears(value - birthday.Year); }
- get { return birthday.Year; }
- }
- public override string ToString() { return "Имя " + this.name + "\nФамилия " + this.familia + "\nДата рождения " + birthday.ToString("D"); }
- public string ToShortString() { return "Имя " + this.name + "\nФамилия " + this.familia; }
- }
- enum Frequency
- {
- weekly,monthly,yearly
- }
- class Article
- {
- public Person avtor;
- public string title;
- public double rait;
- public Article()
- {
- avtor = new Person();
- title = "Статья по программированию";
- rait = 5;
- }
- public Article(Person avtor, string title, double raiting)
- {
- this.avtor = avtor;
- this.title = title;
- this.rait = raiting;
- }
- public double Raiting
- {
- set { rait = value; }
- get { return rait; }
- }
- public override string ToString() { return this.avtor.ToString() + "\nНазвание статьи " + this.title + "\nРейтинг статьи " + this.rait + "\n"; }
- }
- class Magazine
- {
- string titlemag;
- Frequency pereodichnost;
- DateTime datavihoda;
- int tiraj;
- private readonly List<Article> stati = new List<Article>();
- public Magazine()
- {
- titlemag = "Цифровой мир";
- pereodichnost = Frequency.weekly;
- datavihoda = DateTime.Now;
- tiraj = 1;
- }
- public Magazine(string title, Frequency periodoch, DateTime date, int tir)
- {
- this.titlemag = title;
- this.pereodichnost = periodoch;
- this.datavihoda = date;
- this.tiraj = tir;
- }
- public string Title
- {
- set { titlemag = value; }
- get { return titlemag; }
- }
- public Frequency Period
- {
- set { pereodichnost = value; }
- get { return pereodichnost; }
- }
- public DateTime Date
- {
- set { datavihoda = value; }
- get { return datavihoda; }
- }
- public int Tiraj
- {
- set { tiraj = value; }
- get { return tiraj; }
- }
- public Article[] Stati
- {
- get { return stati.ToArray(); }
- }
- public double srreit
- {
- get
- {
- if (stati.Count == 0)
- return 0;
- else
- {
- double sumball = 0;
- foreach (Article a in stati)
- sumball += a.rait;
- return sumball / stati.Count;
- }
- }
- }
- public bool this[Frequency index]
- {
- get { return this.pereodichnost == index; }
- }
- public void AddArticles(params Article[] stati)
- {
- this.stati.AddRange(stati);
- }
- public override string ToString()
- {
- return String.Format("Название журнала: {0}\nПериодичность: {1}\nДата выхода: {2}\nТираж: {3}\nСтатьи: \n{4}", titlemag, pereodichnost, datavihoda.ToString("D"), tiraj, string.Join(",", stati));
- }
- public string ToShortString()
- {
- return String.Format("Название журнала: {0}\nПериодичность: {1}\nДата выхода: {2}\nТираж: {3}\nСредний рейтинг статей: {4}", titlemag, pereodichnost, datavihoda.ToString("D"), tiraj, srreit);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Magazine mag = new Magazine();
- mag.ToShortString();
- Console.WriteLine(mag[Frequency.monthly]);
- Console.WriteLine(mag[Frequency.weekly]);
- Console.WriteLine(mag[Frequency.yearly]);
- mag.AddArticles(new Article(new Person("Алексей", "Сергеев", new DateTime(1999, 2, 3)), "Новости робототехники", 5), new Article(new Person("Антон", "Доронин", new DateTime(1985, 5, 16)), "Новости C++", 4.3), new Article(new Person("Руслан", "Цветков", new DateTime(2001, 3, 9)), "Новости C#", 4.8));
- Console.WriteLine(mag.ToString());
- Console.WriteLine("Количество времени на операции в секундах");
- Article[] odnomer = new Article[10];
- Article[,] dvymer = new Article[2, 5];
- Article[][] stypench = new Article[4][];
- stypench[0] = new Article[1];
- stypench[1] = new Article[2];
- stypench[2] = new Article[3];
- stypench[3] = new Article[4];
- Console.WriteLine("Одномерный массив");
- long ms = DateTime.Now.Ticks;
- for (int i = 0; i < 10; i++)
- odnomer[i] = new Article();
- for (int i = 0; i < 10; i++)
- Console.WriteLine(odnomer[i]);
- Console.WriteLine("Затраченное время {0}с", (DateTime.Now.Ticks - ms)/1000.0);
- Console.WriteLine("Двумерный массив");
- ms = DateTime.Now.Ticks;
- for (int i = 0; i < 2; i++)
- for (int j = 0; j < 5; j++)
- dvymer[i, j] = new Article();
- for (int i = 0; i < 2; i++)
- for (int j = 0; j < 5; j++)
- Console.WriteLine(dvymer[i, j]);
- Console.WriteLine("Затраченное время {0}с", (DateTime.Now.Ticks - ms) / 1000.0);
- Console.WriteLine("Ступенчатый массив");
- ms = DateTime.Now.Ticks;
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < i+1; j++)
- stypench[i][j] = new Article();
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < i+1; j++)
- Console.WriteLine(stypench[i][j]);
- Console.WriteLine("Затраченное время {0}с", (DateTime.Now.Ticks - ms) / 1000.0);
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment