#include<iostream.h>
class Tpoint
{public:Tpoint(int x,int y){X=x,Y=y;}
Tpoint(Tpoint &p);
~Tpoint() {cout<<X<<"Destructor Called\n";}
int Xcoord(){return X;}
int Ycoord(){return Y;}
private:int X,Y;
};
Tpoint:: Tpoint(Tpoint &p)
{X=p.X; Y=p.Y; cout<<"Copy constructor Called\n";}
Tpoint f(Tpoint Q)
{cout<<"ok\n";
int x,y;
x=Q.Xcoord()+100;
y=Q.Ycoord()+200;
Tpoint R(x,y);
return R;
}
void main()
{Tpoint M(20,30),p(0,0);
Tpoint N(M);
p=f(N);
cout<<"p="<<p.Xcoord()<<" "<<p.Ycoord()<<endl;
}
#include<iostream.h>
void main()
{
int a=5,b=1,c=-1;
if(b+c) cout<<a+b<<endl;
else cout<<a-b<<endl;
}
4
#include<iostream.h>
void fun(int m,int &n)
{m=m+n;n=m-n;}
void main()
{
int a(10),b(20);
cout<<a<<" "<<b<<endl;
fun(a,b);
cout<<a<<" "<<b<<endl;
}
10 20
10 10
#include<iostream.h>
template<class T>
T fun(T m,T n)
{return m+n;}
void main()
{
int a(5),b(10);
cout<<fun(a,b)<<endl;
cout<<fun(1.5*a,0.5*b)<<endl;
}
15
12.5