Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*overloading special case(intger*object)*/
- #include<conio.h>
- #include<iostream>
- using namespace std;
- class Vector
- {
- int a,b,c;
- public :void read();
- void display();
- friend Vector operator*(int,Vector);
- };
- void Vector ::read()
- {
- cout<<"Enter coefficient of i,j,k: ";
- cin>>a>>b>>c;
- }
- void Vector ::display()
- {
- cout<<a<<"i + "<<b<<"j + "<<c<<"k"<<endl;
- }
- Vector operator*(int y, Vector x)
- {
- Vector z;
- z.a = y * x.a;
- z.b = y * x.b;
- z.c = y * x.c;
- return z;
- }
- int main()
- {
- Vector c1,c3;
- c1.read();
- cout<<"Before:"<<endl;
- c1.display();
- cout<<"After Multiplying(x5):"<<endl;
- c3=5*c1;
- c3.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment