CODE TO FIND THE DIRECTION AND MAGNITUDE OF A VECTOR USING CLASS
category: OOP c++
IDe used : MS visual studio 2010
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
class vector
{
private:
int a,b,c,d;
public:
vector()
{
int a=0;
int b=0;
int c=0;
int d=0;
}
vector(int q,int w,int e,int r)
{
a=q;
b=w;
c=e;
d=r;
}
void setx(int q)
{
a=q;
}
void sety(int w)
{
b=w;
}
void setz(int e)
{
c=e;
}
void setp(int r)
{
d=r;
}
int getx()
{
return a;
}
int gety()
{
return b;
}
int getz()
{
return c;
}
int getp()
{
return d;
}
float magnitude()
{
float u,i;
u
=c-a;
i
=d-b;
u
=u*u;
i
=i*i;
return sqrt((u+i));
}
float direction()
{
float o,m;
o=(d-b);
m=(c-a);
float n=o/m;n=atan(n);
int
j=(180/3.1412)*n;
return j;
}
};
void main()
{
int q,w,e,r;
cout<<"enter the value of a""\n";
cin
>> q;
cout<<"enter the value of b""\n";
cin
>> w;
cout<<"enter the value of c""\n";
cin
>> e;
cout<<"enter the value of d""\n";
cin
>> r;
vector
v(q,w,e,r);
cout<<"your direction is""\n";
cout
<< v.direction()<<"\n";
cout<<"your magnitude is""\n";
cout
<< v.magnitude();
getch();
}
category DSA c++
No comments:
Post a Comment