Menu

Custom Search

C++ lab Program

#include
#include
class vector
{
float i,j,k;
public: vector(float a=0,float b=0,float c=0):i(a),j(b),k(c){};
vector (vector &v):i(v.i),j(v.j),k(v.k){};
void getdata(){
cout<<"Enter value of i, j and k"<>i>>j>>k;
}
vector operator *(vector);
vector operator +(vector);
vector operator -(vector);
void display(){
cout<<"Vector(V)="< };
vector vector:: operator * (vector x)
{
vector y;
y.i=(j*x.k)-(x.j*k);
y.j=-((i*x.k)-(x.i*k));
y.k=(i*y.j)-(y.i*j);
return y;
}
vector vector:: operator + (vector x)
{
return vector(i+x.i,j+x.j,k+x.k);

}
vector vector:: operator - (vector x)
{
return vector(i-x.i,j-x.j,k-x.k);

}
void main()
{
clrscr();
vector v;
v.getdata();
vector v1(v),v2,v3,v4;
v2=v+v1;
v3=v*v1;
v4=v-v1;
v.display();
v1.display();
v2.display();
v3.display();
v4.display();
getch();
}

No comments:

Post a Comment