Subscribe Us

Responsive Advertisement

Advertisement

pointers to Objects add two nubmer

 

pointers to Objects add two nubmer





#include<bits/stdc++.h>

using namespace std;

class add

{

    int h,w;

public :

       void setval(int x,int y)

       {

           h=x;

           w=y;


       }

    int area()

    {

        return h*w;

    }


};

int main()

{

    add ad;

    add *p;

    ad.setval(3,4);

    p=&ad;

    cout<<ad.area()<<endl;

    p->setval(4,4);

    cout<<ad.area()<<endl;

    cout<<p->area()<<endl;


    return 0;

}


Post a Comment

0 Comments