AbdulFathaah

op over (obj=int*obj) w/ return

Mar 11th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. /*overloading special case(intger*object)*/
  2. #include<conio.h>
  3. #include<iostream>
  4. using namespace std;
  5. class Vector
  6. {
  7. int a,b,c;
  8. public :void read();
  9. void display();
  10. friend Vector operator*(int,Vector);
  11. };
  12. void Vector ::read()
  13. {
  14. cout<<"Enter coefficient of i,j,k: ";
  15. cin>>a>>b>>c;
  16. }
  17. void Vector ::display()
  18. {
  19. cout<<a<<"i + "<<b<<"j + "<<c<<"k"<<endl;
  20. }
  21. Vector operator*(int y, Vector x)
  22. {
  23. Vector z;
  24. z.a = y * x.a;
  25. z.b = y * x.b;
  26. z.c = y * x.c;
  27. return z;
  28. }
  29. int main()
  30. {
  31. Vector c1,c3;
  32. c1.read();
  33. cout<<"Before:"<<endl;
  34. c1.display();
  35. cout<<"After Multiplying(x5):"<<endl;
  36. c3=5*c1;
  37. c3.display();
  38. return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment