Advertisement
kadyr

Untitled

Sep 17th, 2022
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2.  
  3. class Man
  4. {
  5.   protected string name;
  6.   int age;
  7.   protected int money;
  8.   public Man () {}
  9.   public int health;
  10.   public Man (string name, int age, int money)
  11.   {
  12.     this.name = name;
  13.     this.age = age;
  14.     this.money = money;
  15.  
  16.   }
  17.   public string GetName(){return name;}
  18.   public void voice()
  19.   {
  20.     Console.WriteLine(name);
  21.   }
  22. public virtual void doing(Man x)
  23.   {
  24.     Console.WriteLine("Я ничего не делаю");
  25.   }
  26. }
  27.  
  28. class Grma : Man
  29. {
  30.  public Grma(string name, int age, int money) : base(name, age, money)
  31.  {
  32.     health = 50;
  33.  }
  34. public void say()
  35. {
  36.     Console.WriteLine(money);
  37. }
  38.   public override void doing(Man x)
  39.   {
  40.   Console.Write("Я пеку пирожки для ");
  41.   Console.WriteLine(x.GetName());
  42.   health -= 20;
  43.   x.health+=20;
  44.   }  
  45. }
  46.  
  47. class Doc : Man
  48. {
  49.  
  50. public Doc (string name, int age, int money): base(name, age, money)
  51.   {     health = 100;
  52.   }
  53.   public override void doing(Man x)
  54.   {
  55.     Console.Write("Я лечу ");
  56.     Console.WriteLine(x.GetName());
  57.     health -= 10;
  58.     x.health+=30;
  59.   }  
  60. }
  61.  
  62. class Mus : Man
  63. {
  64. public Mus (string name, int age, int money): base(name, age, money){    health = 80;}  
  65.  
  66. public override void doing(Man x)
  67.   {
  68.     Console.Write("Я играю музыку для ");
  69.     Console.WriteLine(x.GetName());
  70.     health -= 15;
  71.     x.health+=15;
  72.   }  
  73. }
  74.  
  75. // https://replit.com/@tvnukova/Grma#main.cs
  76.  
  77.  
  78. class Program {
  79.   public static void Main (string[] args) {
  80.  
  81.     Man [] array = new  Man[4];
  82. array[0] = new Man("Ivan", 15, 10);
  83. array[1] = new Grma("Alla", 80, 20000);
  84. array[2] = new Doc("Alex", 30, 30000);
  85. array[3] = new Mus("Igor", 20, 300);
  86.  
  87. for (int i = 0; i<4;i++)
  88. {
  89.   array[i].doing(array[0]);
  90. }
  91.   }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement