Advertisement
bartigames

Untitled

Apr 15th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication2
  8. {
  9.     public class Figura
  10.     {
  11.         protected double a;
  12.         protected double b;
  13.  
  14.         public Figura(double a, double b)
  15.         {
  16.             this.a = a;
  17.             this.b = b;
  18.  
  19.  
  20.         }
  21.         public virtual double PoleFigury()
  22.         {
  23.             System.Console.WriteLine("Niezdefiniowana figura");
  24.             return 0;
  25.  
  26.  
  27.         }        
  28.     }
  29.     public class Prostokąt : Figura
  30.     {
  31.         public Prostokąt(double a, double b) : base (a,b)
  32.         { }
  33.         public override double PoleFigury()
  34.         {
  35.             double pole = a * b;
  36.             System.Console.WriteLine("Obliczamy pole prostokąta");
  37.             return pole;
  38.  
  39.         }
  40.     }
  41.     public class Trojkat : Figura
  42.     {
  43.  
  44.         public Trojkat(double a, double b) : base(a,b)
  45.         { }
  46.         public override double PoleFigury()
  47.         {
  48.             double pole = (a * b) / 2;
  49.             System.Console.WriteLine("Obliczamy pole trójkąta");
  50.             return pole;
  51.         }
  52.  
  53.     }
  54.     class glowna
  55.  
  56.     {
  57.         static void Main(string[] args)
  58.         {
  59.             Figura f = new Figura(5,6);
  60.             Prostokąt p = new Prostokąt(7, 8);
  61.             Trojkat t = new Trojkat(9, 10);
  62.  
  63.             System.Console.WriteLine("Pole wynosi {0}", f.PoleFigury());
  64.             System.Console.WriteLine("Pole wynosi {0}", p.PoleFigury());
  65.             System.Console.WriteLine("Pole wynosi {0}", t.PoleFigury());
  66.            
  67.  
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement