Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 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 HomeW
  8. {
  9.  
  10.     abstract class Figure
  11.     {
  12.       protected  double area = 0;
  13.  
  14.         public virtual void drawFigure()
  15.         {
  16.             Console.WriteLine("Figura nie moze byc narysowana");
  17.         }
  18.  
  19.         public abstract double getArea();
  20.  
  21.         public virtual void setArea(double area)
  22.         {
  23.             this.area = area;
  24.         }
  25.     }
  26.  
  27.     class Rectangle : Figure
  28.     {
  29.         int x = 0;
  30.         int y = 0;
  31.  
  32.         public Rectangle(int x, int y)
  33.         {
  34.             this.x = x;
  35.             this.y = y;
  36.         }
  37.         public override void drawFigure()
  38.         {
  39.             for (int a = 0; a < x; ++a)
  40.             {
  41.                 for (int b = 0; b < y; ++b)
  42.                 {
  43.                     Console.Write("#");
  44.                 }
  45.                 Console.WriteLine();
  46.             }
  47.         }
  48.  
  49.         public override double getArea()
  50.         {
  51.             base.setArea(x *y);
  52.             return area;
  53.         }
  54.     }
  55.  
  56.     class Triangle : Figure
  57.     {
  58.         int h;
  59.         int w;
  60.         public Triangle(int h, int w)
  61.         {
  62.             this.h = h;
  63.             this.w = w;
  64.         }
  65.         public override double getArea()
  66.         {
  67.             return 0.5*h*w;
  68.         }
  69.  
  70.         public override void drawFigure()
  71.         {
  72.              for(int a=1; a<= h; ++a)
  73.             {
  74.                 for(int b=0; b<a; ++b)
  75.                 {
  76.                     Console.Write("#");
  77.                 }
  78.                 Console.WriteLine();
  79.             }
  80.         }
  81.     }
  82.     class Program
  83.     {
  84.         static void Main(string[] args)
  85.         {
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement