Abstraction in Header Files
Learn about implementing abstraction is creating header files. Find out more below!
We'll cover the following...
When our goal is to hide the unnecessary details from the users, we can divide the code into different files. This is where header files come into play.
Creating Header Files
Let’s take a look at the Circle
class below.
Press + to interact
#include <iostream>using namespace std;class Circle{double radius;double pi;public:Circle (){radius = 0;pi = 3.142;}Circle(double r){radius = r;pi = 3.142;}double area(){return pi * radius * radius;}double perimeter(){return 2 * pi * radius;}};int main() {Circle c(5);cout << "Area: " << c.area() << endl;cout << "Perimeter: " << c.perimeter() << endl;}
To hide our class, we will follow a few steps. The first step is to create a header file. This file will only contain the declaration of the ...