Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.76 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.  
  7. namespace ConsoleApp1
  8. {
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. public class Person /////Определить класс Person, который имеет
  18. {
  19. private string name1; ////////////· закрытое поле типа string, в котором хранится имя;
  20.  
  21.  
  22.  
  23.  
  24. ///////· конструктор без параметров, инициализирующий все поля класса некоторыми значениями по умолчанию.
  25. private string name2; /////////· закрытое поле типа string, в котором хранится фамилия;
  26. private System.DateTime birth; ///////////////· закрытое поле типа System.DateTime для даты рождения.
  27.  
  28. public Person()
  29. {
  30.  
  31.  
  32.  
  33.  
  34. name1 = "polya";
  35. name2 = "ivanova";
  36. birth = new DateTime(1999, 11, 22);
  37. }
  38.  
  39. public Person(string n1, string n2, DateTime b)
  40. {
  41. this.name1 = n1;
  42. this.name2 = n2;
  43. this.birth = b;
  44. }
  45. /////////////////
  46. public string Name
  47. {
  48. get
  49. {
  50. return name1;
  51. }
  52. set
  53. {
  54. name1 = value;
  55. }
  56.  
  57. }
  58. public string SecondName
  59. {
  60. get
  61. {
  62. return name2;
  63. }
  64. set
  65. {
  66. name2 = value;
  67. }
  68.  
  69. }
  70. ////////////
  71. public DateTime Birth
  72. {
  73. get
  74. {
  75. return birth;
  76. }
  77. set
  78. {
  79. birth = value;
  80. }
  81.  
  82. }
  83. public int Year
  84. {
  85. get
  86. {
  87. return birth.Year;
  88. }
  89. set
  90. {
  91.  
  92. birth = new DateTime(value, birth.Month, birth.Day);
  93. }
  94. }
  95.  
  96.  
  97. /////////////
  98. public override string ToString()
  99. {
  100.  
  101. return Name + " " + SecondName +" " + Birth.ToString();
  102. }
  103.  
  104.  
  105.  
  106. public virtual string ToShortString()
  107. {
  108.  
  109. return Name + " " + SecondName;
  110. }
  111. }
  112.  
  113.  
  114.  
  115. ////////////////////////////
  116. public enum Education { Specialist, Вachelor, SecondEducation }
  117.  
  118.  
  119.  
  120.  
  121. public class Exam
  122. {
  123. string subject;
  124. int rate;
  125. DateTime examday;
  126. ///////////////
  127. public string Subject
  128. {
  129. get
  130. {
  131. return subject;
  132. }
  133. set
  134. {
  135. subject = value;
  136. }
  137.  
  138. }
  139. public int Rate
  140. {
  141. get
  142. {
  143. return rate;
  144. }
  145. set
  146. {
  147. rate = value;
  148. }
  149.  
  150. }
  151. ////////////
  152. public DateTime Examday
  153. {
  154. get
  155. {
  156. return examday;
  157. }
  158. set
  159. {
  160. examday = value;
  161. }
  162. }
  163.  
  164. public Exam()
  165. {
  166. subject = "pract";
  167. rate = 5;
  168. examday = new DateTime(2017, 05, 30);
  169. }
  170.  
  171. public Exam(string sub, int r, DateTime ed)
  172. {
  173. this.subject = sub;
  174. this.rate = r;
  175. this.examday = ed;
  176. }
  177. public override string ToString()
  178. {
  179. return Subject + " " + Rate.ToString() + " " + Examday.ToString();
  180. }
  181.  
  182. }
  183. ///////////////
  184. //////////////
  185. public class Student
  186. {
  187. private Person pers;
  188. private Education fo;
  189. private int gruppa;
  190. private List<Exam> exams=new List<Exam>();
  191.  
  192.  
  193. /////
  194.  
  195.  
  196. public Person Pers
  197. {
  198. get
  199. {
  200. return pers;
  201. }
  202. set
  203. {
  204. pers = value;
  205. }
  206.  
  207. }
  208. public Education Fo
  209. {
  210. get
  211. {
  212. return fo;
  213. }
  214. set
  215. {
  216. fo = value;
  217. }
  218.  
  219. }
  220.  
  221.  
  222.  
  223.  
  224.  
  225. List<Exam> Exams
  226. {
  227. get
  228. {
  229. return exams;
  230. }
  231. set
  232. {
  233. exams = value;
  234.  
  235. }
  236. }
  237.  
  238.  
  239. ////////
  240.  
  241. private double sr = 0;
  242. public double Exsr()
  243. {
  244. int l = Exams.Count;
  245. for (int i = 1; i < l; i++)
  246. {
  247. sr += Exams[i].Rate ;
  248.  
  249. }
  250. sr /= l;
  251. return sr;
  252. }
  253. public double Sr
  254. {
  255. get
  256. {
  257.  
  258. return sr;
  259. }
  260. }
  261.  
  262. ///////////
  263.  
  264. public bool this[Education educ]
  265. {
  266. get
  267. {
  268.  
  269. return educ == fo;
  270. }
  271.  
  272. }
  273.  
  274.  
  275.  
  276.  
  277.  
  278. public void AddExams(params Exam[] exames)
  279. {
  280. this.exams.AddRange(exames);
  281. }
  282.  
  283.  
  284.  
  285.  
  286. public override string ToString()
  287. {
  288. string s = pers.ToString() + " " + fo.ToString() + " " + gruppa.ToString() + " ";
  289. for (int i = 0; i < Exams.Count; i++)
  290. s += Exams[i].Subject + " "+Exams[i].Rate.ToString()+Exams[i].Examday.ToString()+" ";
  291.  
  292. return s;
  293. }
  294.  
  295. public virtual string ToShortString()
  296. {
  297. return pers.ToShortString()+" " + fo.ToString() + " " + gruppa.ToString() + " " + Sr.ToString();
  298. }
  299.  
  300.  
  301. ////////////
  302. public int Gruppa
  303. {
  304. get
  305. {
  306. return gruppa;
  307. }
  308. set
  309. {
  310. gruppa = value;
  311. }
  312. }
  313.  
  314. public Student()
  315. {
  316.  
  317. pers = new Person("polya", "ivanova", new DateTime(1999, 11, 22));
  318. fo = Education.Вachelor;
  319. gruppa = 862;
  320. }
  321.  
  322.  
  323.  
  324.  
  325.  
  326. public Student(Person per, Education edu, int g)
  327. {
  328. this.pers = new Person(per.Name, per.SecondName, per.Birth);
  329. this.fo = edu;
  330. this.gruppa = g;
  331. }
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344. }
  345.  
  346. class Program
  347.  
  348. {
  349. static void Main(string[] args)
  350. {
  351.  
  352. Console.WriteLine("Создать один объект типа Student, преобразовать данные в текстовый вид с помощью метода ToShortString() и вывести данные.");
  353.  
  354. Console.WriteLine();
  355. Console.WriteLine();
  356. Console.WriteLine();
  357. Student stud = new Student();
  358. Console.WriteLine(stud.ToShortString());
  359. DateTime d = new DateTime(1999, 11, 22);
  360. Console.WriteLine();
  361. Console.WriteLine();
  362. Console.WriteLine();
  363. //List<Exam> ex=new List<Exam>();
  364. Console.WriteLine("Вывести значения индексатора для значений индекса Education.Specialist, Education.Bachelor и Education.SecondEducation.");
  365.  
  366. Console.WriteLine();
  367. Console.WriteLine();
  368. Console.WriteLine();
  369. Console.WriteLine(Education.Specialist + " " + stud[Education.Specialist]);
  370. Console.WriteLine(Education.Вachelor + " " + stud[Education.Вachelor]);
  371. Console.WriteLine(Education.SecondEducation + " " + stud[Education.SecondEducation]);
  372.  
  373.  
  374. Console.WriteLine();
  375. Console.WriteLine();
  376. Console.WriteLine();
  377. Console.WriteLine("Присвоить значения всем определенным в типе Student свойствам, преобразовать данные в текстовый вид с помощью метода ToString() и вывести данные.");
  378. Console.WriteLine();
  379. Console.WriteLine();
  380. Console.WriteLine();
  381. //stud.AddExams(new Exam("fdhhd", 5, d));
  382.  
  383. stud = new Student(new Person("polya", "ivanova", d), Education.Specialist, 862);
  384. Console.WriteLine(stud.ToString());
  385. Console.WriteLine();
  386. Console.WriteLine();
  387. Console.WriteLine();
  388.  
  389.  
  390.  
  391. Console.WriteLine("C помощью метода AddExams( params Exam*+ ) добавить элементы в список экзаменов и вывести данные объекта Student, используя метод ToString().");
  392.  
  393. stud.AddExams(new Exam( "fjgkkhkh", 5, new DateTime(2017, 05, 30)));
  394. Console.WriteLine(stud.ToString());
  395. Console.WriteLine();
  396. Console.WriteLine();
  397. Console.WriteLine();
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404. // Person per = new Person("polya", "ivanova", d);
  405. //per.Year = 2000;
  406. //Console.WriteLine(per.Year);
  407. // Console.WriteLine(per.ToString());
  408. // Console.WriteLine(per.ToShortString());
  409. // Education edu = Education.Вachelor;
  410. //Console.WriteLine(edu);
  411.  
  412. Console.ReadKey();
  413.  
  414. }
  415. }
  416.  
  417. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement