Skip to content

Instantly share code, notes, and snippets.

@susanta96
Created February 8, 2018 20:19
Show Gist options
  • Select an option

  • Save susanta96/76d87406389628e7ac752d666521297b to your computer and use it in GitHub Desktop.

Select an option

Save susanta96/76d87406389628e7ac752d666521297b to your computer and use it in GitHub Desktop.
Simple example of vector addition , subtraction and multiplication
#include<iostream>
#include<stdlib.h>
using namespace std;
class Vector
{
int a,b,c;
public:
Vector(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
Vector sum(Vector o4)
{
Vector o5(0,0,0);
o5.a=a+o4.a;
o5.b=b+o4.b;
o5.c=c+o4.c;
cout<<"Sum of two Vector:\t";
o5.display();
}
Vector sub(Vector o6)
{
Vector o7(0,0,0);
o7.a=a-o6.a;
o7.b=b-o6.b;
o7.c=c-o6.c;
cout<<"Subtraction of two Vector:\t";
o7.display();
}
Vector multi(Vector o8)
{
Vector o9(0,0,0);
o9.a=a*o8.a;
o9.b=b*o8.b;
o9.c=c*o8.c;
cout<<"Multiplication of two Vector:\t";
o9.display();
}
Vector scale_multi(int sc)
{
Vector o10(0,0,0);
o10.a=a*sc;
o10.b=b*sc;
o10.c=c*sc;
cout<<"Scaler Multiplication of two Vector:\t";
o10.display();
}
void display()
{
cout<<a<<"i"<<"\t"<<b<<"j"<<"\t"<<c<<"k";
}
};
int main()
{
int sc;
Vector o1(1,2,3),o2(2,3,1),o3(0,0,0);
o1.sum(o2);
cout<<"\n";
o1.sub(o2);
cout<<"\n";
o1.multi(o2);
cout<<"\n";
cout<<"Enter the scaler vector:";
cin>>sc;
o1.scale_multi(sc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment