fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace DashainBhandari_AreaofRectangle_1010
  7. {
  8. class Shape
  9. {
  10. protected double width;
  11. protected double height;
  12.  
  13. // Setter methods
  14. public void SetWidth(double w)
  15. {
  16. width = w;
  17. }
  18.  
  19. public void SetHeight(double h)
  20. {
  21. height = h;
  22. }
  23. }
  24.  
  25. // Derived class inheriting from base class
  26. class Rectangle : Shape
  27. {
  28. // Method to calculate area of rectangle
  29. public double GetArea()
  30. {
  31. return width * height;
  32. }
  33. }
  34.  
  35. class Program
  36. {
  37. static void Main(string[] args)
  38. {
  39. Rectangle rect = new Rectangle();
  40.  
  41. // Input width of rectangle
  42. Console.Write("Dashain Bhandari: ");
  43. Console.Write("Enter the width of the rectangle: ");
  44. double width = Convert.ToDouble(Console.ReadLine());
  45. rect.SetWidth(width);
  46.  
  47. // Input height of rectangle
  48. Console.Write("Enter the height of the rectangle: ");
  49. double height = Convert.ToDouble(Console.ReadLine());
  50. rect.SetHeight(height);
  51.  
  52. // Calculate and display area of rectangle
  53. Console.WriteLine("Area of Rectangle: " + rect.GetArea());
  54. }
  55. }
  56. }
  57.  
  58.  
Success #stdin #stdout 0.05s 32344KB
stdin
5
6
stdout
Dashain Bhandari: Enter the width of the rectangle: Enter the height of the rectangle: Area of Rectangle: 30