Guest User

Untitled

a guest
Dec 13th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. using System;
  2. namespace laba1
  3. {
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. // создание объекта класса HardDrive через конструктор по умолчанию
  9. // и установка полей c помощью set методов
  10. HardDrive seagate = new HardDrive();
  11. seagate.Manufacturer = "Seagate";
  12. seagate.Capacity = 50000;
  13. seagate.Iface ="SATA II";
  14. seagate.PrintInfo();
  15.  
  16. // создание объекта класса HardDrive с помощью перегруженного конструктора
  17. HardDrive toshiba = new OutsideHardDrive("Toshiba", 50000, "SATA", "Metal");
  18. toshiba.PrintInfo();
  19. Console.ReadLine();
  20. }
  21. }
  22. public class HardDrive
  23. {
  24. private string manufacturer;
  25. protected int capacity; // megabytes
  26. private string iface;
  27. public string Description = "HDD";
  28.  
  29. public HardDrive()
  30. {
  31. }
  32. public HardDrive(string manufacturer, int capacity, string iface)
  33. {
  34. this.manufacturer = manufacturer;
  35. this.capacity = capacity;
  36. this.iface = iface;
  37. }
  38. public string Manufacturer {
  39. get
  40. {
  41. return manufacturer;
  42. }
  43. set
  44. {
  45. if (value != null) manufacturer = value;
  46. }
  47. }
  48. public int Capacity {
  49. get
  50. {
  51. return capacity;
  52. }
  53. set
  54. {
  55. capacity = value;
  56. }
  57. }
  58.  
  59. public string Iface {
  60. get {
  61. return iface;
  62. }
  63. set
  64. {
  65. if (value != null) iface = value;
  66. }
  67.  
  68. }
  69.  
  70. public virtual string showInfo()
  71. {
  72. return "Manufactorer: " + manufacturer + ", " +
  73. "Capacity: " + capacity + ", " +
  74. "Interface: " + iface + ", " +
  75. "Type: " + Description;
  76. }
  77. // обращени родительского метода к методам наследника
  78. public void PrintInfo() { Console.WriteLine(showInfo()); }
  79. }
  80.  
  81. public class OutsideHardDrive : HardDrive
  82. {
  83. public new int capacity; // переопределение модификатора доступа поля capacity
  84. private string corpys; // новое поле - Корпус
  85. public string Corpys
  86. {
  87. get
  88. {
  89. return corpys;
  90. }
  91. set
  92. {
  93. if (value != null) corpys = value;
  94. }
  95. }
  96. public OutsideHardDrive(string manufacturer, int capacity, string iface, string corpys)
  97. : base(manufacturer, capacity, iface) {
  98. this.corpys = corpys;
  99. }
  100.  
  101. public override string showInfo()
  102. {
  103. return "Manufactorer: " + Manufacturer + ", " +
  104. "Capacity: " + Capacity + ", " +
  105. "Interface: " + Iface + ", " +
  106. "Corpys: " + Corpys + ", " +
  107. "Type: " + Description;
  108. }
  109. }
  110. }
Add Comment
Please, Sign In to add comment