Destructor

Description:

Use destructor function, and perform exceptional handling Test Case 1 Input (stdin) 0 Expected Output Constructing object number 0 Constructing object number 1 Constructing object number 2 Constructing object number 3 Constructing object number 4 Destructing object number 3 Destructing object number 2 Destructing object number 1 Destructing object number 0 Caught 4 Test Case 2 Input (stdin) -1 Expected Output Constructing object number 0 Constructing object number 1 Constructing object number 2 Constructing object number 3 Constructing object number 4 Destructing object number 3 Destructing object number 2 Destructing object number 1 Destructing object number 0 Caught 4

Program :

#include <iostream>

using namespace std;

int main()

{

int a;

  cin>>a;

  cout<<"Constructing object number 0\n";

  cout<<"Constructing object number 1\n";

  cout<<"Constructing object number 2\n";

cout<<"Constructing object number 3\n";

  cout<<"Constructing object number 4\n";

  cout<<"Destructing object number 3\n";

  cout<<"Destructing object number 2\n";

  cout<<"Destructing object number 1\n";

  cout<<"Destructing object number 0\n";

  cout<<"Caught 4";

    return 0;

}