Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Man
- {
- protected string name;
- int age;
- protected int money;
- public Man () {}
- public int health;
- public Man (string name, int age, int money)
- {
- this.name = name;
- this.age = age;
- this.money = money;
- }
- public string GetName(){return name;}
- public void voice()
- {
- Console.WriteLine(name);
- }
- public virtual void doing(Man x)
- {
- Console.WriteLine("Я ничего не делаю");
- }
- }
- class Grma : Man
- {
- public Grma(string name, int age, int money) : base(name, age, money)
- {
- health = 50;
- }
- public void say()
- {
- Console.WriteLine(money);
- }
- public override void doing(Man x)
- {
- Console.Write("Я пеку пирожки для ");
- Console.WriteLine(x.GetName());
- health -= 20;
- x.health+=20;
- }
- }
- class Doc : Man
- {
- public Doc (string name, int age, int money): base(name, age, money)
- { health = 100;
- }
- public override void doing(Man x)
- {
- Console.Write("Я лечу ");
- Console.WriteLine(x.GetName());
- health -= 10;
- x.health+=30;
- }
- }
- class Mus : Man
- {
- public Mus (string name, int age, int money): base(name, age, money){ health = 80;}
- public override void doing(Man x)
- {
- Console.Write("Я играю музыку для ");
- Console.WriteLine(x.GetName());
- health -= 15;
- x.health+=15;
- }
- }
- // https://replit.com/@tvnukova/Grma#main.cs
- class Program {
- public static void Main (string[] args) {
- Man [] array = new Man[4];
- array[0] = new Man("Ivan", 15, 10);
- array[1] = new Grma("Alla", 80, 20000);
- array[2] = new Doc("Alex", 30, 30000);
- array[3] = new Mus("Igor", 20, 300);
- for (int i = 0; i<4;i++)
- {
- array[i].doing(array[0]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement