7. Define a class for 3 dimensional points necessary member functions for accepting and the point object Overload the following operators: Operator Example Purpose * (Binary) p3=p1*p2 multiplies coordinates of point p1 with p2. – (Binary) p3=p2-p1 subtracts coordinates of p1 from p2.


#include<iostream.h>
#include<conio.h>
class point
{
int x,y,z;
public:
void get()
{
cout<<“\nEnter the 3-Dimensional point’s: \n”;
cin>>x>>y>>z;
}
point operator*(point &t)
{
point temp;
temp.x=x*t.x;
temp.y=y*t.y;
temp.z=z*t.z;
return temp;
}
point operator-(point &t)
{
point temp;
temp.x=x-t.x;
temp.y=y-t.y;
temp.z=z-t.z;
return temp;
}
void display()
{
cout<<“Point’s: “<<x<<” “<<y<<” “<<z;
}
};
void main()
{
point p1,p2,p3;
clrscr();
p1.get();
p2.get();
cout<<“\n\nFirst “;
p1.display();
cout<<“\n\nSecond “;
p2.display();
p3=p1*p2;
cout<<“\n\nMultiplication of “;
p3.display();
p3=p2-p1;
cout<<“\n\nSubtraction of “;
p3.display();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s