Tuesday, 21 April 2015

Write a program that will demonstrate destructor function

Write a program that will demonstrate destructor function. The program that uses the following properties – class names- test; two integer type private member variables- e,f; one constructor function test(); one destructor function ~test(); one public member function add_display(). Constructor function test() assigns the values for e, f; add_display() member function do the addition for e, f and displays the result as output.

#include<iostream>
using namespace std;
class test
{
    int e,f;
public:
    test();
    ~test();
    void add_display();
};
test::test()
        {
           cout<<"Constructor Function "<<endl;
            e=10;
            f=20;
        }
test::~test()
{
    cout<<"Destructor Function"<<endl;
}
void test::add_display()
            {
                cout<<"Addition value is : "<<e+f<<endl;
            }
 Int  main()
 {
     test  p;
     p.add_display();
     return 0;
}

No comments:

Post a Comment