Advertisement
Temabowl

lab_5

Nov 25th, 2021
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace ConsoleApp1
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12.  
  13. List<Student> students_list = new List<Student>();
  14. Console.WriteLine("1. Создание студента\n2. Вывести всех студентов\n3. Сравнение студентов\n");
  15.  
  16.  
  17.  
  18.  
  19. while (true)
  20. {
  21. try
  22. {
  23. switch (Console.ReadLine())
  24. {
  25. case "1":
  26. Builder1 builder1 = new Builder1();
  27. Director director = new Director(builder1);
  28. director.MakeFullDefaultStudent();
  29. Student student = builder1.GetStudent();
  30. Console.WriteLine("Введите имя");
  31. student.Name = Console.ReadLine();
  32. Console.WriteLine("Введите пол \n1. М\n2. Ж");
  33. if(Console.ReadLine() == "2")
  34. {
  35. student.Gender = "Ж";
  36.  
  37. }
  38. Console.WriteLine("Введите форму обучения\n1. Очная\n2. Заочная");
  39. if (Console.ReadLine() == "2")
  40. {
  41. student.Education = "Заочная";
  42.  
  43. }
  44. Console.WriteLine("Семейное положение\n1. Не женат(не замужем)\n2. Женат(за мужем)");
  45. if (Console.ReadLine() == "2")
  46. {
  47. student.Married = "Женат(Замужем)";
  48.  
  49. }
  50. Console.WriteLine("1. Работает\n2. Не работает");
  51. if (Console.ReadLine() == "2")
  52. {
  53. student.Employment = "Не работает";
  54.  
  55. }
  56. Console.WriteLine("Есть дети?\n1. Нет детей\n2. Да");
  57. if(Console.ReadLine() == "2")
  58. {
  59. Console.WriteLine("Введите количество детей");
  60. int count = Convert.ToInt32(Console.ReadLine());
  61. for (int i = 0; i < count; i++)
  62. {
  63. Child child = new();
  64. Console.WriteLine("Введите имя ребенка");
  65. child.Name = Console.ReadLine();
  66. Console.WriteLine("Введите пол \n1. М\n2. Ж");
  67. if (Console.ReadLine() == "1")
  68. {
  69. child.Gender = "М";
  70. }
  71. else
  72. {
  73. child.Gender = "Ж";
  74. }
  75. Console.WriteLine("Введите дату рождения (прим. 01.01.2000)");
  76. child.Birthday = Console.ReadLine();
  77. Console.WriteLine("Введите увлечение");
  78. child.Hobbies = Console.ReadLine();
  79. student.children.Add(child);
  80. }
  81. }
  82. students_list.Add(student);
  83.  
  84. break;
  85. case "2":
  86. foreach (Student item in students_list)
  87. {
  88. Console.WriteLine("=======================");
  89. Console.WriteLine("Студент №" + students_list.IndexOf(item));
  90. item.GetInfo();
  91. }
  92. break;
  93. case "3":
  94. Console.WriteLine("Введите первого студента");
  95. Student st1 = students_list[Convert.ToInt32(Console.ReadLine())];
  96. Console.WriteLine("Введите второго студента");
  97. Student st2 = students_list[Convert.ToInt32(Console.ReadLine())];
  98. Compars(st1,st2);
  99. break;
  100. }
  101. }
  102. catch (Exception e)
  103. {
  104. Console.WriteLine("Ошибка!");
  105. Console.WriteLine(e.Message);
  106. }
  107.  
  108. }
  109. }
  110. static void Compars(Student student1, Student student2)
  111. {
  112. if (student1.Name == student2.Name && student1.Gender == student2.Gender && student1.Education == student2.Education && student1.Married == student2.Married && student1.Employment == student2.Employment && student1.children.Count == student2.children.Count)
  113. {
  114. if (student1.children.Count > 0)
  115. {
  116. for (int i = 0; i < student1.children.Count; i++)
  117. {
  118. if (student1.children[i].Name != student2.children[i].Name || student1.children[i].Gender != student2.children[i].Gender || student1.children[i].Birthday != student2.children[i].Birthday || student1.children[i].Hobbies != student2.children[i].Hobbies)
  119. {
  120. Console.WriteLine("Студенты не одинаковы");
  121. break;
  122. }
  123. else
  124. {
  125. Console.WriteLine("Студенты одинаковы");
  126. }
  127.  
  128. }
  129. }
  130. else
  131. {
  132. Console.WriteLine("Студенты одинаковы");
  133. }
  134. }
  135. else
  136. {
  137. Console.WriteLine("Студенты не одинаковы");
  138. }
  139. }
  140.  
  141. }
  142. }
  143.  
  144.  
  145.  
  146. class Child
  147. {
  148. // Имя
  149. private string name;
  150. public string Name { get { return name; } set { name = value; } }
  151. // Пол
  152. private string gender;
  153. public string Gender { get { return gender; } set { gender = value; } }
  154. // День рождения
  155. private string birthday;
  156. public string Birthday { get { return birthday; } set { birthday = value; } }
  157. // Увлечения
  158. private string hobbies;
  159. public string Hobbies { get { return hobbies; } set { hobbies = value; } }
  160. public void GetInfo()
  161. {
  162. Console.WriteLine(Name + "\n" + Gender + "\n" + Birthday + "\n" + Hobbies);
  163. }
  164.  
  165. }
  166.  
  167.  
  168.  
  169. class Student
  170. {
  171. // Имя
  172. private string name;
  173. public string Name { get { return name; } set { name = value; } }
  174. // Пол
  175. private string gender;
  176. public string Gender { get { return gender; } set { gender = value; } }
  177. // Форма обучения
  178. private string education;
  179. public string Education { get { return education; } set { education = value; } }
  180. // Семейное положение
  181. private string married;
  182. public string Married { get { return married; } set { married = value; } }
  183. // Работа
  184. private string employment;
  185. public string Employment { get { return employment; } set { employment = value; } }
  186.  
  187. public List<Child> children = new List<Child>();
  188.  
  189.  
  190. public void GetInfo()
  191. {
  192. Console.WriteLine("Имя: " + Name + "\n" + "Пол: " +Gender + "\n" + "Тип обучения: " + Education + "\n" + "Женат/За мужем?: " + Married + "\n" + "Работает?: " + Employment + "\nДети:\n");
  193. if (this.children.Count > 0 )
  194. {
  195. for (int i = 0; i < this.children.Count; i++)
  196. {
  197. int num_of_children = i + 1;
  198. Console.WriteLine("Ребенок №" + num_of_children);
  199. this.children[i].GetInfo();
  200. }
  201. }
  202. else
  203. {
  204. Console.WriteLine("Детей нет");
  205. }
  206.  
  207. }
  208. }
  209.  
  210.  
  211. abstract class StudentBuilder
  212. {
  213. public abstract void SetName();
  214. public abstract void SetGender();
  215. public abstract void SetEducation();
  216. public abstract void SetMarried();
  217. public abstract void SetEmployment();
  218. public abstract void SetChildren();
  219. }
  220.  
  221. class Builder1 : StudentBuilder
  222. {
  223. private Student _student = new Student();
  224.  
  225. public void Reset()
  226. {
  227. this._student = new Student();
  228. }
  229.  
  230. public override void SetName()
  231. {
  232. this._student.Name = "#Имя#";
  233. }
  234. public override void SetGender()
  235. {
  236. this._student.Gender = "М";
  237. }
  238. public override void SetEducation()
  239. {
  240. this._student.Education = "Очная";
  241. }
  242. public override void SetMarried()
  243. {
  244. this._student.Married = "Не женат / Не замужем";
  245. }
  246. public override void SetEmployment()
  247. {
  248. this._student.Employment = "Не работает";
  249. }
  250. public override void SetChildren()
  251. {
  252. this._student.children.Add(new Child());
  253. }
  254. public Student GetStudent()
  255. {
  256. Student result = this._student;
  257. return result;
  258. }
  259. }
  260.  
  261. class Director
  262. {
  263. public StudentBuilder builder;
  264.  
  265. public Director(StudentBuilder builder)
  266. {
  267. this.builder = builder;
  268. }
  269.  
  270. public void MakeFullDefaultStudent()
  271. {
  272. this.builder.SetName();
  273. this.builder.SetGender();
  274. this.builder.SetEducation();
  275. this.builder.SetMarried();
  276. this.builder.SetEmployment();
  277. }
  278.  
  279.  
  280. }
  281.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement