Advertisement
Guest User

INTERFACE

a guest
Jul 2nd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     public interface MyInterface
  9.     {
  10.         int Sum();
  11.         int Otr();
  12.         int Prz();
  13.         int Del();
  14.     }
  15.  
  16.     public interface ISqrSqrt
  17.     {
  18.         int Sqr(int x);
  19.         int Sqrt(int x);
  20.         string this[int index]
  21.         {
  22.             get;
  23.             set;
  24.         }
  25.     }
  26.  
  27.     class First : MyInterface
  28.     {
  29.         string myName;
  30.  
  31.         int My_x, My_y;
  32.  
  33.         public int x
  34.         {
  35.             set { My_x = value; }
  36.             get { return My_x; }
  37.         }
  38.  
  39.         public int y
  40.         {
  41.             set { My_y = value; }
  42.             get { return My_y; }
  43.         }
  44.  
  45.         public First() { }
  46.         public First(int x, int y)
  47.         {
  48.             this.x = x;
  49.             this.y = y;
  50.         }
  51.  
  52.         public virtual int Sum()
  53.         {
  54.             return x + y;
  55.         }
  56.  
  57.         public int Otr()
  58.         {
  59.             return x - y;
  60.         }
  61.  
  62.         public int Prz()
  63.         {
  64.             return x * y;
  65.         }
  66.  
  67.         public int Del()
  68.         {
  69.             return x / y;
  70.         }
  71.  
  72.         public string this[int index]
  73.         {
  74.             set { myName = value; }
  75.             get { return myName; }
  76.         }
  77.  
  78.         public virtual void rewrite()
  79.         {
  80.             Console.WriteLine("Переменная x: {0}\nПеременная y: {1}", x, y);
  81.         }
  82.     }
  83.  
  84.  
  85.     class Second : First
  86.     {
  87.         public int z;
  88.  
  89.         public Second(int z, int x, int y)
  90.             : base(x, y)
  91.         {
  92.             this.z = z;
  93.         }
  94.  
  95.  
  96.         public override int Sum()
  97.         {
  98.             return base.x + base.y + z;
  99.         }
  100.  
  101.         public override void rewrite()
  102.         {
  103.             base.rewrite();
  104.             Console.WriteLine("Переменная z: " + z);
  105.         }
  106.     }
  107.  
  108.  
  109.     class Third : First, ISqrSqrt
  110.     {
  111.         public int Sqr(int x)
  112.         {
  113.             return x * x;
  114.         }
  115.  
  116.         public int Sqrt(int x)
  117.         {
  118.             return (int)Math.Sqrt((double)(x));
  119.         }
  120.     }
  121.  
  122.     class Program
  123.     {
  124.  
  125.  
  126.         static void Main()
  127.         {
  128.  
  129.             First obj1 = new First(x: 10, y: 12);
  130.             obj1[5] = "Hello";
  131.             Console.WriteLine("{0}", obj1[5]);
  132.             Console.WriteLine("obj1: ");
  133.             obj1.rewrite();
  134.             Console.WriteLine("{0} + {1} = {2}", obj1.x, obj1.y, obj1.Sum());
  135.             Console.WriteLine("{0} * {1} = {2}", obj1.x, obj1.y, obj1.Prz());
  136.             Second obj2 = new Second(z: -3, x: 10, y: 14);
  137.             Console.WriteLine("\nobj2: ");
  138.             obj2.rewrite();
  139.             Console.WriteLine("{0} + {1} + {3} = {2}", obj2.x, obj2.y, obj2.Sum(), obj2.z);
  140.  
  141.             Console.ReadLine();
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement