OOP/CPP Vector class to create, add, display vector

/*Using class write a program that would be able to do the following task:
a) To create the vector.
b) To add the value of a two vector
c) To display the vector in the form (ai+bj+ck)
*/
#include <iostream>
using namespace std;
#include<stdlib.h>
class vector
{ float i,j,k;
  int n;
  public:
void create();
void show();
friend void add(vector,vector);
};
void vector::create()
{
    cout<<“Enter the value for i,j,k: “;
    cin>>i>>j>>k;
}
void vector::show()
{cout<<“The vector is: “<<i<<“i+”<<j<<“j+”<<k<<“k”<<endl;
}
void add(vector a,vector b)
{
    vector c;
    c.i=a.i+b.i;
    c.j=a.j+b.j;
    c.k=a.k+b.k;
    cout<<“After summation “;
    c.show();
}
int main()
{  vector p,q;
p.create();
p.show();
q.create();
q.show();
add(p,q);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>