I could not understand what is the purpose of a destructor in this program
Why destructor is created?
Destructor is a member function which destructs or deletes an object.
A destructor function is called automatically when the object goes out of scope
If we do not write our own destructor in class, compiler creates a default destructor for us.
The default destructor works fine unless we have dynamically allocated memory or pointer in class.
When a class contains a pointer to memory allocated in class, we should write a destructor to release memory before the class instance is destroyed. This must be done to avoid memory leak.
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course