Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.  
  6. abstract class Figure
  7. {
  8. protected int posX,posY;
  9.  
  10. abstract public double Square();
  11.  
  12. }
  13.  
  14. class Triangle : Figure
  15. {
  16. int h, m;
  17. public Triangle(int h, int m)
  18. {
  19. this.h = h;
  20. this.m = m;
  21.  
  22. }
  23. override public double Square()
  24. {
  25. return (h * m)/2;
  26. }
  27. }
  28.  
  29. class Circle:Figure
  30. {
  31. int r;
  32. public Circle(int r)
  33. {
  34. this.r = r;
  35. }
  36. public override double Square()
  37. {
  38. return (Math.PI * r * r);
  39. }
  40. }
  41. class Program
  42. {
  43. static void Main(string[] args)
  44. {
  45. int r = 1;
  46. Figure circles = new Circle(r);
  47. Figure triangles = new Triangle(5, 10);
  48. Console.WriteLine("Площадь круга равна: " + circles.Square());
  49. Console.WriteLine("Площадь треугольника равна: " + triangles.Square());
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement