Advertisement
Seedx

bezkonstruktora

Mar 17th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _2._6
  4. {
  5.     class Figury
  6.     {
  7.         public virtual void Pole()
  8.         {
  9.             Console.Write("Pole wynosi: ");
  10.         }
  11.         public int a, b, r, h;
  12.     }
  13.     class Kwadrat : Figury
  14.     {
  15.         public override void Pole()
  16.         {
  17.            
  18.             Console.WriteLine("Pole kwadratu wynosi: {0}",Math.Pow(base.a, 2));
  19.         }
  20.            
  21.     }
  22.     class Prostokat : Figury
  23.     {
  24.         public override void Pole()
  25.         {
  26.  
  27.             Console.WriteLine("Pole prostokątu wynosi: {0}", base.a*base.b);
  28.         }
  29.  
  30.     }
  31.     class Kolo : Figury
  32.     {
  33.         public override void Pole()
  34.         {
  35.  
  36.             Console.WriteLine("Pole koła wynosi: {0}", Math.Pow(base.a, 2));
  37.         }
  38.     }
  39.     class Trojkat: Figury
  40.     {
  41.         public override void Pole()
  42.         {
  43.  
  44.             Console.WriteLine("Pole kwadratu wynosi: {0}", base.a*base.h/2);
  45.         }
  46.  
  47.     }
  48.     class Program
  49.     {
  50.         static void Main(string[] args)
  51.         {
  52.             Figury kw = new Kwadrat();
  53.             kw.a = 2;
  54.             kw.b = 3;
  55.             kw.Pole();
  56.             Figury pr = new Prostokat();
  57.             pr.a = 3;
  58.             pr.b = 3;
  59.             pr.Pole();
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement