fork download
  1. #include <iostream>
  2.  
  3. // Base class for shapes
  4. class Shape {
  5. public:
  6. virtual double calculateArea() const = 0;
  7. virtual ~Shape() = default;
  8. };
  9.  
  10. // Derived class for Circle
  11. class Circle : public Shape {
  12. private:
  13. double radius;
  14. public:
  15. Circle(double r) : radius(r) {}
  16. double calculateArea() const override {
  17. return 3.14159 * radius * radius; // Area of a circle: πr²
  18. }
  19. };
  20.  
  21. // Derived class for Rectangle
  22. class Rectangle : public Shape {
  23. private:
  24. double width, height;
  25. public:
  26. Rectangle(double w, double h) : width(w), height(h) {}
  27. double calculateArea() const override {
  28. return width * height; // Area of a rectangle: w × h
  29. }
  30. };
  31.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty