Friday, 22 June 2012

write a c++ program to define a class for 3 dimensional points. write necessary member function for accepting and displaying the point object overload the following operator

/*
define a class for 3 dimensional points. write necessary member function
for accepting and displaying the point object overload the following
operator
operator        example          purpose
+(Binary)    p3=p1+p2        adds coordinate of point p1 with p2
-(unary)    -p1;        negates coordinates p1
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
int i=0;
class point
{
int p;
public:void accept()
       {
       i=i+1;
       cout<<"enter the dimentional point "<<i<<":-";
       cin>>p;
       }
       void operator +(point p2)
       {
       int ans;
       ans=p+p2.p;
       cout<<"\naddition of two cordinate point:-"<<ans;
       }
       void operator -()
       {
       p=-p;
       cout<<"\nnegation of point p1="<<p;
       }
       };
int main()
{
point p1,p2;
clrscr();
p1.accept();
p2.accept();
p1+p2;
-p1;
getch();
return 0;
}
/*
enter the dimentional point 1:-9
enter the dimentional point 2:-6

addition of two cordinate point:-15
negation of point p1=-9
*/

No comments: