Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace newproject
- {
- class Program
- {
- static void Main(string[] args)
- {
- Human Katya = new Human();
- Katya.Hands = 10;
- Katya.Legs = 40;
- Katya.Head = 80;
- int SummKatya = Katya.SummOfParts();
- Console.WriteLine(SummKatya);
- Human Anna = new Human();
- Anna.Hands = 10;
- Anna.Legs = 40;
- Anna.Head = 80;
- int SummAnna = Anna.SummOfParts();
- Console.WriteLine(SummAnna);
- Human Victoria = new Human();
- Victoria.Hands = 100;
- Victoria.Legs = 100;
- Victoria.Head = 66;
- int SummVictoria = Victoria.SummOfParts();
- Console.WriteLine(SummVictoria);
- Console.ReadLine();
- }
- }
- public class Human
- {
- public int Hands;
- public int Legs;
- public int Head;
- public int SummOfParts()
- {
- int SummOfPart = Hands + Legs + Head;
- return SummOfPart;
- }
- }
- }
- public abstract class Human : ICloneable
- {
- public string Name { get; set; }
- public int Hands { get; set; }
- public int Legs { get; set; }
- public int Head { get; set; }
- public override string ToString()
- {
- return $"Девушка: {Name}-{Hands}-{Legs}-{Head}";
- }
- public int SummOfParts()
- {
- int SummOfPart = Hands + Legs + Head;
- return SummOfPart;
- }
- public abstract object Clone();
- }
- public class Woman : Human
- {
- public override object Clone()
- {
- //здесь так для упрощения, на самом деле
- //тут нужно делать копирование всех свойств
- return this.MemberwiseClone() as Human;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- //первая девушка (будет образцом)
- Woman Anna = new Woman()
- {
- Name = "Anna",
- Head = 66,
- Hands = 100,
- Legs = 100
- };
- Console.WriteLine(Anna.ToString());
- //клонируем девушку
- Woman Natasha = (Woman)Anna.Clone();
- //изменяем имя
- Natasha.Name = "Natasha";
- Console.WriteLine(Natasha.ToString());
- Console.ReadKey();
- //выводит
- //Девушка: Anna-100-100-66
- //Девушка: Natasha - 100 - 100 - 66
- }
- }
Add Comment
Please, Sign In to add comment