Menu

Custom Search

C++ lab Program

#include
#include
#include
class vector
{
int x,y,z;
public:
void getdata();
vector add(vector);
vector subtract(vector);
float magnitude();
void display();
};
void vector::getdata()
{
cout<<"Enter values for i,j,k:"; cin>>x>>y>>z;
}
vector vector::add(vector a)
{ cout<<"Addition of two vectors:"< vector v;
v.x=x+ a.x;
v.y=y+a.y;
v.z=z+a.z;
return v;
}
vector vector::subtract(vector p)
{ cout<<"Vector subtraction:"< vector v1;
v1.x=x-p.x;
v1.y=y-p.y;
v1.z=z-p.z;
return v1;
}
float vector::magnitude()
{
float m=sqrt(x*x+y*y+z*z);
return m;
}
void vector::display()
{
cout<<"The resul is:";
cout< }
void main()
{ clrscr();
vector v,v1,v2,v3;
v.getdata();
v1.getdata();
v2=v.add(v1);
v2.display();
v3=v.subtract(v1);
v3.display();
float y=v2.magnitude();
float z=v3.magnitude();

cout< getch();
}

No comments:

Post a Comment