Constructor (C++)

A constructor is a special member function that runs automatically when an object is created. It has the same name as the class and is used to initialize the…