Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*program to do vector addition*/
- #include<iostream.h>
- #include<conio.h>
- class VecAdd
- {
- private : int a,b,c; //coefficients of i,j,k
- public : void read();
- void display();
- VecAdd add(VecAdd);
- };
- void VecAdd :: read()
- {
- cout<<"Enter coefficient of i: ";
- cin>>a;
- cout<<"Enter coefficient of j: ";
- cin>>b;
- cout<<"Enter coefficient of k: ";
- cin>>c;
- cout<<"\n";
- }
- void VecAdd :: display()
- {
- cout<<a<<"i + "<<b<<"j + "<<c<<"k\n";
- }
- VecAdd VecAdd :: add(VecAdd x)
- {
- VecAdd z;
- z.a=a+x.a;
- z.b=b+x.b;
- z.c=c+x.c;
- return z;
- }
- int main()
- {
- VecAdd v1,v2,v3;
- clrscr();
- v1.read();
- v2.read();
- cout<<"Before Addition:\n";
- v1.display();
- v2.display();
- v3=v1.add(v2);
- cout<<"After Addition:\n";
- v3.display();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment