Write a program to overload the unary minus operator using friend function.
#include<iostream>
using
namespace std;
class
space{
int x;
int y;
int z;
public:
void getdata(int a,int b,int c);
void display(void);
friend void operator-(space &s);
};
void
space :: getdata(int a,int b,int c){
x=a;
y=b;
z=c;
}
void
space :: display(void){
cout<<x<<" ";
cout<<y<<" ";
cout<<z<<"\n";
}
void
operator-( space &s){
s.x=-s.x;
s.y=-s.y;
s.z=-s.z;
}
int
main(){
space s;
s.getdata(10,-20,30);
cout<<"S : ";
s.display();
-s;
cout<<"S :";
s.display();
return 0;
}
You might also like:
ty
ReplyDeleteTx
ReplyDeleteWhat is the output of this program?
ReplyDeleteadded.
DeleteWhat is the output of this program?
ReplyDeleteAlgorithm pls
ReplyDeleteOutput please
ReplyDeleteadded
Deletehttps://d2498fijg8ztfy3etotznbpl9t.hop.clickbank.net/?tid=MATBIN
ReplyDeleteIts showing a lot if errors 😶
ReplyDeleteplease specify the error..
Delete