fork download
  1. #include <iostream>
  2. using namespace std;
  3. class Rectangle;
  4.  
  5. class Circle{
  6. float radius;
  7. float area;
  8.  
  9. public:
  10. Circle(float r)
  11. {
  12. radius = r;
  13. area =3.1416*radius*radius;
  14. }
  15. void display_Circle()
  16. {
  17. cout<<"Area of Circle : " <<area<<endl;
  18. }
  19. friend void compare(Circle c, Rectangle r);
  20.  
  21. };
  22. class Rectangle
  23. {
  24. float length;
  25. float width;
  26. float area;
  27.  
  28. public:
  29. Rectangle(float l, float w)
  30. {
  31. length = l;
  32. width = w;
  33. area = length * width;
  34. }
  35. void display_Rectangle()
  36. {
  37. cout<<"Area of Rectangle : " <<area<<endl;
  38. }
  39. friend void compare(Circle c, Rectangle r);
  40.  
  41. };
  42. void compare(Circle c, Rectangle r)
  43. {
  44. if (c.area == r.area)
  45. {
  46. cout<<"Area of Circle and Rectangla are Equal" <<endl;
  47. }
  48. else if(c.area>r.area)
  49. {
  50. cout<<"Area of Circle is Larger" <<endl;
  51. }
  52. else
  53. {
  54. cout<<"Area of Rectangle is Larger" <<endl;
  55. }
  56.  
  57. }
  58.  
  59.  
  60. int main()
  61. {
  62. Circle obj1(2.0);
  63. Rectangle obj2(2.0,2.6);
  64. obj1.display_Circle();
  65. obj2.display_Rectangle();
  66. compare(obj1, obj2);
  67.  
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Area of Circle : 12.5664
Area of Rectangle : 5.2
Area of Circle is Larger