Friday, 22 June 2012

write c++ program consider the following class number

/*write c++ program consider the following class number
class number
{
int x,y,z;
public:\\methods
};
overload the operator unary - to negate the number.
*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class number
{
int x,y,z;
public:void getdata()
       {
       cout<<"enter three number";
       cin>>x>>y>>z;
       }
       void operator -()
       {
       x=-x;
       y=-y;
       z=-z;
       }
       void display()
       {
       cout<<"\nx="<<x
       <<"\ny="<<y
       <<"\nz="<<z;
       }
};
int main()
{
number n;
clrscr();
n.getdata();
-n;
n.display();
getch();
return 0;
}
/*enter three number5
6
9

x=-5
y=-6
z=-9
*/

No comments: