Wednesday, March 2, 2011

que3

#include
using namespace std;

class testall
{
private:
int a;
public:
testall():a(0) {}
testall(int l):a(l) {}
bool operator == (testall t2)
{
if (a==t2.a)
return true;
else
return false;
}

bool operator != (testall t2)
{
if(a!=t2.a)
return true;
else return false;
}

bool operator > (testall t2)
{
if(a>t2.a)
return true;
else return false;
}


bool operator < (testall t2)
{
if(a return true;
else return false;
}
};
int main()
{
int i;

cout<<"Enter for 1st object: ";
cin>>i;
testall t1(i);
cout<<"Enter for 2nd object: ";
cin>>i;
testall t2(i);
if(t1==t2)
cout<<"Equal"< if(t1!=t2)
cout<<"Not equal"< if(t1 cout<<"Object 1 is less than Object 2"< if(t1>t2)
cout<<"Object 1 is greater than Object 2"<


return 0;
}

Que 2

#include
using namespace std;
class vect
{
private:
float x,y,z;
public:
vect():x(0),y(0),z(0) {}
void store(float xx, float yy,float zz)
{
x=xx;y=yy;z=zz;
}

friend vect operator + (vect,vect);
void showd()
{
cout< }
};

vect operator + (vect v1,vect v2)
{
vect t;
t.x=v1.x+v2.x;
t.y=v1.y+v2.y;
t.z=v1.z+v2.z;
return t;
}


int main()
{
vect v1,v2,v3;
int x,y,z;
cout<<"Enter x1 y1 and z1: "< cin>>x>>y>>z;
v1.store(x,y,z);
cout<<"Enter x2 y2 and z2: "< cin>>x>>y>>z;
v2.store(x,y,z);
v3=v1+v2;
v1.showd();
v2.showd();
v3.showd();
return 0;
}