IskandarIts

laba_1

Feb 24th, 2021 (edited)
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading;
  6.  
  7. namespace university
  8. {
  9. //class Money
  10. //{
  11. // public int first { get; set; }
  12. // public int second { get; set; }
  13.  
  14. // public Money(int f, int s)
  15. // {
  16. // first = f;
  17. // second = s;
  18. // }
  19.  
  20. // public int All_money()
  21. // {
  22. // return first * second;
  23. // }
  24.  
  25. // public bool Enough_Money(int n)
  26. // {
  27. // if (All_money() >= n)
  28. // return true;
  29. // return false;
  30. // }
  31.  
  32. // //Money m = new Money(500, 3);
  33. // //Console.WriteLine(String.Format("Номинал = {0} рублей, количество = {1}, общая сумма = {2} рублей", m.first, m.second, m.All_money()));
  34.  
  35. // //Console.WriteLine("Введите стоимость товара");
  36. // //int n = Convert.ToInt32(Console.ReadLine());
  37.  
  38. // //if (m.Enough_Money(n))
  39. // // Console.WriteLine(String.Format("Денег хватит на покупку товара стоимостью {0} рублей." +
  40. // // "\nУ вас останется {1} рублей", n, m.All_money() - n));
  41. // //else
  42. // // Console.WriteLine(String.Format("Вам не хватает {0}", n - m.All_money()));
  43.  
  44. //}
  45.  
  46. class Person
  47. {
  48. private string first_name;
  49. private string second_name;
  50. private DateTime DateOfBirth;
  51.  
  52. public string F_name
  53. {
  54. get
  55. {
  56. return first_name;
  57. }
  58. }
  59.  
  60. public string S_name
  61. {
  62. get
  63. {
  64. return second_name;
  65. }
  66. }
  67.  
  68. public DateTime Date
  69. {
  70. get
  71. {
  72. return DateOfBirth;
  73. }
  74. }
  75.  
  76. public int DateYear
  77. {
  78. get
  79. {
  80. return DateOfBirth.Year;
  81. }
  82.  
  83. set
  84. {
  85. DateOfBirth = new DateTime(value, DateOfBirth.Month, DateOfBirth.Day);
  86. }
  87. }
  88.  
  89. public Person(string f_n, string s_n, System.DateTime dob)
  90. {
  91. first_name = f_n;
  92. second_name = s_n;
  93. DateOfBirth = dob;
  94. }
  95.  
  96. public Person()
  97. {
  98. first_name = "Ivan";
  99. second_name = "Ivanov";
  100. DateOfBirth = System.DateTime.Now;
  101. }
  102.  
  103. public override string ToString()
  104. {
  105. return first_name.ToString() + ", " + second_name.ToString() + ", " + DateOfBirth.ToString();
  106. }
  107.  
  108. public virtual string ToShortString()
  109. {
  110. return first_name.ToString() + ", " + second_name.ToString();
  111. }
  112. }
  113.  
  114. enum Education
  115. {
  116. Specialist = 0,
  117. Вachelor = 1,
  118. SecondEducation = 2
  119. }
  120.  
  121. class Exam
  122. {
  123. public string name { get; set; }
  124. public int rating { get; set; }
  125. public DateTime exam_date { get; set; }
  126.  
  127. public Exam(string n, int r, DateTime d)
  128. {
  129. name = n;
  130. rating = r;
  131. exam_date = d;
  132. }
  133.  
  134. public Exam()
  135. {
  136. name = "Unknown";
  137. rating = 0;
  138. exam_date = DateTime.Now;
  139. }
  140.  
  141. public override string ToString()
  142. {
  143. return name.ToString() + ", " + rating.ToString() + ", " + exam_date.ToString();
  144. }
  145. }
  146.  
  147. class Student
  148. {
  149. public Person student_data { get; set; }
  150. public Education education_type { get; set; }
  151. public int group_number { get; set; }
  152. List<Exam> passed_exams { get; set; } = new List<Exam>();
  153.  
  154. public double average_score
  155. {
  156. get
  157. {
  158. int sum = 0;
  159. for (int i = 0; i< passed_exams.Count; i++)
  160. {
  161. sum += passed_exams[i].rating;
  162. }
  163. if (passed_exams.Count > 0)
  164. return sum * 1.0/ passed_exams.Count;
  165. return 0.0;
  166. }
  167. }
  168.  
  169. public Student(Person p, Education e, int g)
  170. {
  171. student_data = p;
  172. education_type = e;
  173. group_number = g;
  174. }
  175.  
  176. public Student()
  177. {
  178. student_data = new Person();
  179. education_type = Education.Вachelor;
  180. group_number = 0;
  181. }
  182.  
  183. public bool this [Education e]
  184. {
  185. get
  186. {
  187. if (education_type == e)
  188. return true;
  189. return false;
  190. }
  191. }
  192.  
  193. public void AddExam(Exam[] e)
  194. {
  195. for (int i =0; i< e.Length; i++)
  196. {
  197. passed_exams.Add(e[i]);
  198. }
  199. }
  200.  
  201. public override string ToString()
  202. {
  203. string t = "";
  204. for (int i = 0; i< passed_exams.Count; i++)
  205. {
  206. t += passed_exams[i].ToString() + '\n';
  207. }
  208. if (t == "")
  209. t = "not found exams";
  210.  
  211. return String.Format("about student: {0}\neducation_type: {1}\ngroup number: {2}\naverage score: {3}\nexams: {4}",
  212. student_data.ToString(), education_type.ToString(), group_number.ToString(), average_score.ToString(), t);
  213. }
  214.  
  215. public virtual string ToShortString()
  216. {
  217. return String.Format("about student: {0}\neducation_type: {1}\ngroup number: {2}\naverage score: {3}",
  218. student_data.ToString(), education_type.ToString(), group_number.ToString(), average_score.ToString());
  219. }
  220. }
  221.  
  222. class Program
  223. {
  224. static void Main(string[] args)
  225. {
  226. // одномерный массив
  227. Stopwatch sw = new Stopwatch();
  228. sw.Start();
  229.  
  230. Exam[] exams1 = new Exam[1000000];
  231.  
  232. for (int i = 0; i < 1000000; i++)
  233. {
  234. exams1[i] = new Exam();
  235. }
  236.  
  237. sw.Stop();
  238. Console.WriteLine("одномерный массив");
  239. Console.WriteLine((sw.ElapsedMilliseconds / 1000.0).ToString());
  240.  
  241. // прямоугольный
  242.  
  243. Stopwatch sw2 = new Stopwatch();
  244. sw2.Start();
  245.  
  246. Exam[,] exams2 = new Exam[200, 5000];
  247. int rows = exams2.GetUpperBound(0) + 1;
  248. int columns = exams2.Length / rows;
  249.  
  250. for (int i = 0; i < rows; i++)
  251. {
  252. for (int j = 0; j < columns; j++)
  253. {
  254. exams2[i, j] = new Exam();
  255. }
  256. }
  257.  
  258. sw2.Stop();
  259. Console.WriteLine("прямоугольный массив");
  260. Console.WriteLine((sw2.ElapsedMilliseconds / 1000.0).ToString());
  261.  
  262. // ступенчатый (зубчатым)
  263.  
  264. Stopwatch sw3 = new Stopwatch();
  265. sw3.Start();
  266.  
  267. Exam[][] exams3 = new Exam[5][];
  268.  
  269. exams3[0] = new Exam[300000];
  270. exams3[1] = new Exam[20000];
  271. exams3[2] = new Exam[30000];
  272. exams3[3] = new Exam[50000];
  273. exams3[4] = new Exam[600000];
  274.  
  275. for (int i = 0; i < exams3.Length; i++)
  276. {
  277. for (int j = 0; j < exams3[i].Length; j++)
  278. {
  279. exams3[i][j] = new Exam();
  280. }
  281. }
  282.  
  283. sw3.Stop();
  284. Console.WriteLine("ступенчатый массив");
  285. Console.WriteLine((sw3.ElapsedMilliseconds / 1000.0).ToString());
  286.  
  287. ////////////////////////////////////////////////////////////////////////////////////////
  288.  
  289. // первая часть задания
  290. Student student = new Student();
  291. Console.WriteLine(student.ToShortString());
  292. Console.WriteLine("----------------------------");
  293.  
  294. // вторая часть
  295. foreach (Education e in Enum.GetValues(typeof(Education)))
  296. {
  297. Console.WriteLine(student[e]);
  298.  
  299. }
  300. // получили True для Bachelor, так как по умолчанию задается Education.Bachelor
  301. Console.WriteLine("----------------------------");
  302.  
  303. //третья часть
  304.  
  305. Console.Write("Введите имя: ");
  306. string first_name = Console.ReadLine();
  307.  
  308. Console.Write("Введите фамилию: ");
  309. string second_name = Console.ReadLine();
  310.  
  311. Console.Write("Введите дату рождения и время (в формате: год месяц день час минута cекунда): ");
  312. int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
  313. DateTime dof = new DateTime(a[0], a[1], a[2], a[3], a[4], a[5]);
  314.  
  315.  
  316. //Console.Write("Введите год рождения: ");
  317. //int y = Convert.ToInt32(Console.ReadLine());
  318.  
  319. //Console.Write("Введите месяц рождения: ");
  320. //int m = Convert.ToInt32(Console.ReadLine());
  321.  
  322. //Console.Write("Введите день рождения: ");
  323. //int d = Convert.ToInt32(Console.ReadLine());
  324.  
  325. Console.Write("Введите номер группы: ");
  326. int g = Convert.ToInt32(Console.ReadLine());
  327.  
  328. Console.Write("Введите уровень образования: ");
  329. string l = Console.ReadLine();
  330.  
  331. if (l == " Second Education ")
  332. student.education_type = Education.SecondEducation;
  333. else if (l == "Specialist")
  334. student.education_type = Education.Specialist;
  335. else
  336. student.education_type = Education.Вachelor;
  337.  
  338. student.student_data = new Person(first_name, second_name, dof);
  339. student.group_number = g;
  340.  
  341. Console.WriteLine("----------------------------");
  342. Console.WriteLine(student.ToString());
  343.  
  344. // четвертая часть
  345. Console.WriteLine("----------------------------");
  346. Console.Write("Введите количество экзаменов: ");
  347. int k = Convert.ToInt32(Console.ReadLine());
  348. Exam[] exams = new Exam[k];
  349.  
  350. for (int i = 0;i<k;i++)
  351. {
  352. Console.Write("Введите название предмета: ");
  353. string p_name = Console.ReadLine();
  354.  
  355. Console.Write("Введите оценку за экзамен: ");
  356. int rate = Convert.ToInt32(Console.ReadLine());
  357.  
  358. Console.Write("Введите дату предмета и время (в формате: год месяц день час минута cекунда): ");
  359. int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
  360. DateTime dt = new DateTime(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]);
  361.  
  362. exams[i] = new Exam(p_name, rate, dt);
  363. Console.WriteLine("Информация об экзамене добавлена");
  364. }
  365.  
  366. student.AddExam(exams);
  367. Console.WriteLine("Экзамены добавлены");
  368. Console.WriteLine("----------------------------");
  369. Console.WriteLine(student.ToString());
  370. Console.WriteLine("----------------------------");
  371.  
  372. ////пятая часть
  373.  
  374. //// одномерный массив
  375. //Stopwatch sw = new Stopwatch();
  376. //sw.Start();
  377.  
  378. //Exam[] exams1 = new Exam[1000000];
  379.  
  380. //for (int i=0;i< 1000000; i++)
  381. //{
  382. // exams1[i] = new Exam();
  383. //}
  384.  
  385. //sw.Stop();
  386. //Console.WriteLine("одномерный массив");
  387. //Console.WriteLine((sw.ElapsedMilliseconds / 1000.0).ToString());
  388.  
  389. //// прямоугольный
  390.  
  391. //Stopwatch sw2 = new Stopwatch();
  392. //sw2.Start();
  393.  
  394. //Exam[,] exams2 = new Exam[200, 5000];
  395. //int rows = exams2.GetUpperBound(0) + 1;
  396. //int columns = exams2.Length / rows;
  397.  
  398. //for (int i = 0; i < rows; i++)
  399. //{
  400. // for (int j = 0; j < columns; j++)
  401. // {
  402. // exams2[i,j] = new Exam();
  403. // }
  404. //}
  405.  
  406. //sw2.Stop();
  407. //Console.WriteLine("прямоугольный массив");
  408. //Console.WriteLine((sw2.ElapsedMilliseconds / 1000.0).ToString());
  409.  
  410. //// ступенчатый (зубчатым)
  411.  
  412. //Stopwatch sw3 = new Stopwatch();
  413. //sw3.Start();
  414.  
  415. //Exam[][] exams3 = new Exam[5][];
  416.  
  417. //exams3[0] = new Exam[300000];
  418. //exams3[1] = new Exam[20000];
  419. //exams3[2] = new Exam[30000];
  420. //exams3[3] = new Exam[50000];
  421. //exams3[4] = new Exam[600000];
  422.  
  423. //for (int i = 0; i< exams3.Length; i++)
  424. //{
  425. // for (int j = 0; j < exams3[i].Length; j++)
  426. // {
  427. // exams3[i][j] = new Exam();
  428. // }
  429. //}
  430.  
  431. //sw3.Stop();
  432. //Console.WriteLine("ступенчатый массив");
  433. //Console.WriteLine((sw3.ElapsedMilliseconds / 1000.0).ToString());
  434. }
  435. }
  436. }
  437.  
Add Comment
Please, Sign In to add comment