Guest User

Untitled

a guest
Jul 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 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 newproject
  8. {
  9. class Program
  10.  
  11. {
  12.  
  13.  
  14. static void Main(string[] args)
  15. {
  16. Human Katya = new Human();
  17. Katya.Hands = 10;
  18. Katya.Legs = 40;
  19. Katya.Head = 80;
  20. int SummKatya = Katya.SummOfParts();
  21. Console.WriteLine(SummKatya);
  22.  
  23.  
  24. Human Anna = new Human();
  25. Anna.Hands = 10;
  26. Anna.Legs = 40;
  27. Anna.Head = 80;
  28. int SummAnna = Anna.SummOfParts();
  29. Console.WriteLine(SummAnna);
  30.  
  31. Human Victoria = new Human();
  32. Victoria.Hands = 100;
  33. Victoria.Legs = 100;
  34. Victoria.Head = 66;
  35. int SummVictoria = Victoria.SummOfParts();
  36. Console.WriteLine(SummVictoria);
  37. Console.ReadLine();
  38. }
  39. }
  40.  
  41. public class Human
  42. {
  43. public int Hands;
  44. public int Legs;
  45. public int Head;
  46.  
  47. public int SummOfParts()
  48. {
  49. int SummOfPart = Hands + Legs + Head;
  50. return SummOfPart;
  51. }
  52. }
  53. }
  54.  
  55. public abstract class Human : ICloneable
  56. {
  57. public string Name { get; set; }
  58. public int Hands { get; set; }
  59. public int Legs { get; set; }
  60. public int Head { get; set; }
  61.  
  62. public override string ToString()
  63. {
  64. return $"Девушка: {Name}-{Hands}-{Legs}-{Head}";
  65. }
  66.  
  67. public int SummOfParts()
  68. {
  69. int SummOfPart = Hands + Legs + Head;
  70. return SummOfPart;
  71. }
  72.  
  73. public abstract object Clone();
  74.  
  75. }
  76.  
  77. public class Woman : Human
  78. {
  79.  
  80. public override object Clone()
  81. {
  82. //здесь так для упрощения, на самом деле
  83. //тут нужно делать копирование всех свойств
  84. return this.MemberwiseClone() as Human;
  85. }
  86. }
  87.  
  88.  
  89. class Program
  90. {
  91. static void Main(string[] args)
  92. {
  93. //первая девушка (будет образцом)
  94. Woman Anna = new Woman()
  95. {
  96. Name = "Anna",
  97. Head = 66,
  98. Hands = 100,
  99. Legs = 100
  100. };
  101.  
  102. Console.WriteLine(Anna.ToString());
  103.  
  104. //клонируем девушку
  105. Woman Natasha = (Woman)Anna.Clone();
  106. //изменяем имя
  107. Natasha.Name = "Natasha";
  108.  
  109. Console.WriteLine(Natasha.ToString());
  110.  
  111. Console.ReadKey();
  112. //выводит
  113. //Девушка: Anna-100-100-66
  114. //Девушка: Natasha - 100 - 100 - 66
  115.  
  116.  
  117. }
  118. }
Add Comment
Please, Sign In to add comment