Guest User

Технол прог лаб1

a guest
Feb 17th, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace TPhome
  7. {
  8. class Person
  9. {
  10. string name;
  11. string familia;
  12. DateTime birthday;
  13. public Person()
  14. {
  15. birthday = new DateTime(2000, 10, 10);
  16. name = "Иван";
  17. familia = "Иванов";
  18. }
  19. public Person(string name, string familia, DateTime date)
  20. {
  21. this.name = name;
  22. this.familia = familia;
  23. this.birthday = date;
  24. }
  25. public string Name
  26. {
  27. set { name = value; }
  28. get { return name; }
  29. }
  30. public string Familia
  31. {
  32. set { familia = value; }
  33. get { return familia; }
  34. }
  35. public DateTime Birthday
  36. {
  37. set { birthday = value; }
  38. get { return birthday; }
  39. }
  40. public int Year
  41. {
  42. set { birthday = birthday.AddYears(value - birthday.Year); }
  43. get { return birthday.Year; }
  44. }
  45. public override string ToString() { return "Имя " + this.name + "\nФамилия " + this.familia + "\nДата рождения " + birthday.ToString("D"); }
  46. public string ToShortString() { return "Имя " + this.name + "\nФамилия " + this.familia; }
  47. }
  48. enum Frequency
  49. {
  50. weekly,monthly,yearly
  51. }
  52. class Article
  53. {
  54. public Person avtor;
  55. public string title;
  56. public double rait;
  57. public Article()
  58. {
  59. avtor = new Person();
  60. title = "Статья по программированию";
  61. rait = 5;
  62. }
  63. public Article(Person avtor, string title, double raiting)
  64. {
  65. this.avtor = avtor;
  66. this.title = title;
  67. this.rait = raiting;
  68. }
  69. public double Raiting
  70. {
  71. set { rait = value; }
  72. get { return rait; }
  73. }
  74. public override string ToString() { return this.avtor.ToString() + "\nНазвание статьи " + this.title + "\nРейтинг статьи " + this.rait + "\n"; }
  75. }
  76. class Magazine
  77. {
  78. string titlemag;
  79. Frequency pereodichnost;
  80. DateTime datavihoda;
  81. int tiraj;
  82. private readonly List<Article> stati = new List<Article>();
  83. public Magazine()
  84. {
  85. titlemag = "Цифровой мир";
  86. pereodichnost = Frequency.weekly;
  87. datavihoda = DateTime.Now;
  88. tiraj = 1;
  89. }
  90. public Magazine(string title, Frequency periodoch, DateTime date, int tir)
  91. {
  92. this.titlemag = title;
  93. this.pereodichnost = periodoch;
  94. this.datavihoda = date;
  95. this.tiraj = tir;
  96. }
  97. public string Title
  98. {
  99. set { titlemag = value; }
  100. get { return titlemag; }
  101. }
  102. public Frequency Period
  103. {
  104. set { pereodichnost = value; }
  105. get { return pereodichnost; }
  106. }
  107. public DateTime Date
  108. {
  109. set { datavihoda = value; }
  110. get { return datavihoda; }
  111. }
  112. public int Tiraj
  113. {
  114. set { tiraj = value; }
  115. get { return tiraj; }
  116. }
  117. public Article[] Stati
  118. {
  119. get { return stati.ToArray(); }
  120. }
  121. public double srreit
  122. {
  123. get
  124. {
  125. if (stati.Count == 0)
  126. return 0;
  127. else
  128. {
  129. double sumball = 0;
  130. foreach (Article a in stati)
  131. sumball += a.rait;
  132. return sumball / stati.Count;
  133. }
  134. }
  135. }
  136. public bool this[Frequency index]
  137. {
  138. get { return this.pereodichnost == index; }
  139. }
  140. public void AddArticles(params Article[] stati)
  141. {
  142. this.stati.AddRange(stati);
  143. }
  144. public override string ToString()
  145. {
  146. return String.Format("Название журнала: {0}\nПериодичность: {1}\nДата выхода: {2}\nТираж: {3}\nСтатьи: \n{4}", titlemag, pereodichnost, datavihoda.ToString("D"), tiraj, string.Join(",", stati));
  147. }
  148. public string ToShortString()
  149. {
  150. return String.Format("Название журнала: {0}\nПериодичность: {1}\nДата выхода: {2}\nТираж: {3}\nСредний рейтинг статей: {4}", titlemag, pereodichnost, datavihoda.ToString("D"), tiraj, srreit);
  151. }
  152. }
  153. class Program
  154. {
  155. static void Main(string[] args)
  156. {
  157. Magazine mag = new Magazine();
  158. mag.ToShortString();
  159. Console.WriteLine(mag[Frequency.monthly]);
  160. Console.WriteLine(mag[Frequency.weekly]);
  161. Console.WriteLine(mag[Frequency.yearly]);
  162. 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));
  163. Console.WriteLine(mag.ToString());
  164. Console.WriteLine("Количество времени на операции в секундах");
  165. Article[] odnomer = new Article[10];
  166. Article[,] dvymer = new Article[2, 5];
  167. Article[][] stypench = new Article[4][];
  168. stypench[0] = new Article[1];
  169. stypench[1] = new Article[2];
  170. stypench[2] = new Article[3];
  171. stypench[3] = new Article[4];
  172. Console.WriteLine("Одномерный массив");
  173. long ms = DateTime.Now.Ticks;
  174. for (int i = 0; i < 10; i++)
  175. odnomer[i] = new Article();
  176. for (int i = 0; i < 10; i++)
  177. Console.WriteLine(odnomer[i]);
  178. Console.WriteLine("Затраченное время {0}с", (DateTime.Now.Ticks - ms)/1000.0);
  179. Console.WriteLine("Двумерный массив");
  180. ms = DateTime.Now.Ticks;
  181. for (int i = 0; i < 2; i++)
  182. for (int j = 0; j < 5; j++)
  183. dvymer[i, j] = new Article();
  184. for (int i = 0; i < 2; i++)
  185. for (int j = 0; j < 5; j++)
  186. Console.WriteLine(dvymer[i, j]);
  187. Console.WriteLine("Затраченное время {0}с", (DateTime.Now.Ticks - ms) / 1000.0);
  188. Console.WriteLine("Ступенчатый массив");
  189. ms = DateTime.Now.Ticks;
  190. for (int i = 0; i < 4; i++)
  191. for (int j = 0; j < i+1; j++)
  192. stypench[i][j] = new Article();
  193. for (int i = 0; i < 4; i++)
  194. for (int j = 0; j < i+1; j++)
  195. Console.WriteLine(stypench[i][j]);
  196. Console.WriteLine("Затраченное время {0}с", (DateTime.Now.Ticks - ms) / 1000.0);
  197. Console.ReadLine();
  198. }
  199. }
  200. }
Add Comment
Please, Sign In to add comment