Sunday, 15 September 2013

PROGRAM TO USE CONSTRUCTORS

/*MADE BY KRISHNA AGARWAL*/
#include<iostream>
using namespace std;
class integer
{
    int m,n;
public:
    integer(int,int);   //constructor declared
    void display()
    {
        cout<<endl;
        cout<<"m = "<<m<<"\n";
        cout<<"n = "<<n<<"\n";
    }
};
integer::integer(int a,int b)       //constructor defined
{
    m=a;
    n=b;
}
int main()
{
    integer int1(0,100);    //constuctor called implicitly
    integer int2=integer(25,75);    //constructor called explicitly
    cout<<"\nobject1\n";
    int1.display();
    cout<<"\nobject2\n";
    int2.display();
    return 0;
}

No comments:

Post a Comment