real life example of code using abstraction in c++

#include <iostream>

using namespace std;

// Abstract class
class Shape {
public:
// Pure virtual function
virtual float area() = 0;
};

// Concrete subclass
class Circle : public Shape {
private:
float radius;
public:
Circle(float r) : radius(r) {}

float area() {
return 3.14 * radius * radius;
}
};

// Concrete subclass
class Rectangle : public Shape {
private:
float length;
float width;
public:
Rectangle(float l, float w) : length(l), width(w) {}

float area() {
return length * width;
}
};

int main() {
Circle c(5);
Rectangle r(4, 6);

cout << "Area of circle: " << c.area() << endl;
cout << "Area of rectangle: " << r.area() << endl;

return 0;
}

//This code shows the use of abstraction in C++ by creating an abstract class Shape with a pure virtual function area(). Two concrete subclasses, Circle and Rectangle, inherit from the Shape class and provide their own implementation of the area() function. The main function creates objects of type Circle and Rectangle, calls the area() function on each object, and prints out the calculated area. This example demonstrates how abstraction allows different subclasses to provide different implementations for the same function.