Saturday 27 July 2013

Simple Example of Constructor (A)

#include<iostream.h>
#include<conio.h>
class mahi
{
    int m,n;
    public:
        mahi(int,int);
        void display()
        {
            cout<<"\n M= "<<m;
            cout<<"\n N= "<<n;
            cout<<"\n M+N= "<<m+n;
            cout<<"\n M-N= "<<m-n;
            cout<<"\n M*N= "<<m*n;
            cout<<"\n M/N= "<<m/n;
        }
};
mahi::mahi(int x,int y)
{
    m=x;
    n=y;
}
void main()
{
    clrscr();
    mahi m1(100,50);
    mahi m2(40,20);
    cout<<"\n\n OBJECT1\n";
    m1.display();
    cout<<"\n\n OBJECT2\n";
    m2.display();
    getch();
}


Here is the output :)


No comments:

Post a Comment