Иерархия классов(задача решена, есть нюансы) - C#

Узнай цену своей работы

Формулировка задачи:

Разработать иeрapхию клaccов для учeтa пeрсoнaла вузa(препoдаватель, вспoмогaтельный пepcoнaл, руководство, студент, аспирант, мaгистрант. Нa укaзaннyю дaту вывести списoк всего персoнала, cгруперованный пo категориям. Для сoтрудников вывести стаж работы.

Извинения приношу за г-код, но сроки жмут. Задача решена, нужно указать на ошибки. Если кто-то может сам исправить, буду очень признателен.
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace ticket312
  8. {
  9. class Person {
  10. public int[] staj= {2,3,4};
  11. }
  12. class Prepod : Person {
  13. public string status = "Преподаватели:";
  14. public string[] firstname = { "Стас", "Олег", "Антон" };
  15. public string[] lastname = { "Антипов", "Доставевский", "Нестеренко" };
  16. public DateTime[] dateTimes = new DateTime[]
  17. {
  18. new DateTime(2017, 10, 1),
  19. new DateTime(2010, 10, 2),
  20. new DateTime(2017, 10, 3),
  21. };
  22. }
  23. class VspomogPers : Person {
  24. public string status = "Вспомогательный персонал: ";
  25. }
  26. class Uborka : VspomogPers {
  27. public string statusUb = "Уборщиц: ";
  28. public string[] firstname = { "Алена", "Полина", "Женя" };
  29. public string[] lastname = { "Мотвеенко", "Гагарина", "Петрова" };
  30. public DateTime[] dateTimes = new DateTime[]
  31. {
  32. new DateTime(2010, 10, 1),
  33. new DateTime(2010, 10, 2),
  34. new DateTime(2017, 10, 3),
  35. };
  36. }
  37. class Rucovodstvo : Person {
  38. public string status = "Руководство: ";
  39. public string[] firstname = { "Стас", "Олег", "Антон" };
  40. public string[] lastname = { "Кепа", "Лизогуб", "Макаров" };
  41. public DateTime[] dateTimes = new DateTime[]
  42. {
  43. new DateTime(2010, 10, 1),
  44. new DateTime(2007, 10, 2),
  45. new DateTime(2017, 10, 3),
  46. };
  47. }
  48. class Student : Person {
  49. public string status = "Студент: ";
  50. public string[] firstname = { "Стас", "Олег", "Антон" };
  51. public string[] lastname = { "Ab4", "Cd4", "Ee4" };
  52. public DateTime[] dateTimes = new DateTime[]
  53. {
  54. new DateTime(2010, 10, 1),
  55. new DateTime(2017, 10, 2),
  56. new DateTime(2017, 10, 3),
  57. };
  58. }
  59. class Aspirant : Person {
  60. public string status = "Аспиранты: ";
  61. public string[] firstname = { "Стас", "Олег", "Антон" };
  62. public string[] lastname = { "Ab5", "Cd5", "Ee5" };
  63. public DateTime[] dateTimes = new DateTime[]
  64. {
  65. new DateTime(2010, 10, 1),
  66. new DateTime(2017, 10, 2),
  67. new DateTime(2017, 10, 3),
  68. };
  69. }
  70. class Magistrant : Person {
  71. public string status = "Магистранты";
  72. public string[] firstname = { "Стас", "Олег", "Антон" };
  73. public string[] lastname = { "Ab6", "Cd6", "Ee6" };
  74. public DateTime[] dateTimes = new DateTime[]
  75. {
  76. new DateTime(2017, 10, 1),
  77. new DateTime(2017, 10, 2),
  78. new DateTime(2011, 10, 3),
  79. };
  80. }
  81. class Program
  82. {
  83. static void Main(string[] args)
  84. {
  85. VspomogPers vspomogPers = new VspomogPers();
  86. Prepod prepod = new Prepod();
  87. Rucovodstvo rucovodstvo = new Rucovodstvo();
  88. Magistrant magistrant = new Magistrant();
  89. Student student = new Student();
  90. Aspirant aspirant = new Aspirant();
  91. Uborka uborka = new Uborka();
  92. DateTime defaultDateTime = new DateTime(2014, 10, 3);
  93. Console.WriteLine(prepod.status);
  94. for (int i = 0; i < 3; i++)
  95. {
  96. if (prepod.dateTimes[i] < defaultDateTime)
  97. {
  98. Console.WriteLine("Имя: {0} {1} Стаж {2}", prepod.firstname[i], prepod.lastname[i], prepod.staj[i]);
  99. }
  100. }
  101. Console.WriteLine(uborka.status);
  102. Console.WriteLine(uborka.statusUb);
  103. for (int i = 0; i < 3; i++)
  104. {
  105. if (uborka.dateTimes[i] < defaultDateTime)
  106. {
  107. Console.WriteLine("Имя: {0} {1} Стаж {2}", uborka.firstname[i], uborka.lastname[i], uborka.staj[i]);
  108. }
  109. }
  110. Console.WriteLine(rucovodstvo.status);
  111. for (int i = 0; i < 3; i++)
  112. {
  113. if (rucovodstvo.dateTimes[i] < defaultDateTime)
  114. {
  115. Console.WriteLine("Имя: {0} {1} Стаж {2}", rucovodstvo.firstname[i], rucovodstvo.lastname[i], rucovodstvo.staj[i]);
  116. }
  117. }
  118. Console.WriteLine(magistrant.status);
  119. for (int i = 0; i < 3; i++)
  120. {
  121. if (magistrant.dateTimes[i] < defaultDateTime)
  122. {
  123. Console.WriteLine("Имя: {0} {1} Стаж {2}", magistrant.firstname[i], magistrant.lastname[i], magistrant.staj[i]);
  124. }
  125. }
  126. Console.WriteLine(student.status);
  127. for (int i = 0; i < 3; i++)
  128. {
  129. if (student.dateTimes[i] < defaultDateTime)
  130. {
  131. Console.WriteLine("Имя: {0} {1} Стаж {2}", student.firstname[i], student.lastname[i], student.staj[i]);
  132. }
  133. }
  134. Console.WriteLine(aspirant.status);
  135. for (int i = 0; i < 3; i++)
  136. {
  137. if (aspirant.dateTimes[i] < defaultDateTime)
  138. {
  139. Console.WriteLine("Имя: {0} {1} Стаж {2}", aspirant.firstname[i], aspirant.lastname[i], aspirant.staj[i]);
  140. }
  141. }
  142. Console.ReadKey();
  143. }
  144. }
  145. }
возможно нужно что-то подправить под LINQ

Решение задачи: «Иерархия классов(задача решена, есть нюансы)»

textual
Листинг программы
  1. abstract class Person
  2. {
  3.     public string Firstname { get; set; }
  4.    
  5.     public string Lastname { get; set; }
  6. }
  7.  
  8. abstract class Staff : Person
  9. {
  10.     public int Experience { get; set; }
  11.    
  12.     public string Position { get; set; }
  13. }
  14.  
  15. class Teacher : Staff
  16. {
  17. }
  18.  
  19. class Support : Staff
  20. {
  21. }
  22.  
  23. class Management : Staff
  24. {
  25. }
  26.  
  27. abstract class Student : Person
  28. {
  29. }
  30.  
  31. class Bachelor : Student
  32. {
  33. }
  34.  
  35. class Graduate : Student
  36. {
  37. }
  38.  
  39. class Postgraduate : Student
  40. {
  41. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 3.929 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы