Sunday, 7 April 2013

Example of Object as arguments in C++

#include<iostream.h>
#include<conio.h>
#include<dos.h>
class temp
{
  public:
      int a,b,sum;
      void getdata(int x,int y)
      {
       a=x;
       b=y;

      };

      int sum1()
      {
       sum=a+b;
       return(sum);
      };
      void sumobj(temp t1,temp t2);
};

void temp::sumobj(temp t1,temp t2)
{

     int ans1;
     ans1=t1.a+t2.b;
     cout<<"\nt\t\tANSWER FROM OBJECT::>"<<ans1;
};

void main()
{
 int ans;
 clrscr();
 temp t1,t2,t3;
 t1.getdata(10,20);
 t2.getdata(20,10);
 ans=t1.sum1();
 cout<<"\n\t\tYOUR ANSWER::>"<<ans;
 ans=t2.sum1();
 cout<<"\n\t\tYOUR ANSWER::>"<<ans;
 t3.sumobj(t1,t2);

 getch();
}

No comments:

Post a Comment

How to change Background color by selecting color from Listview

activitymain.xml file::> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xm...