Write a Program to negate the values of data members using pass by reference

/*
 Program to negate the values of data members
 negate=reverse the sign
*/

#include<iostream>
using namespace std;

class Negate
{
   int a,b;
 
   public:
         void accept()
{
cout<<"\n\n Enter any two number: ";
cin>>a>>b;
}

void display(Negate s)
{
cout<<"\n A:"<<s.a;
cout<<"\n B:"<<s.b;
}

void negate(Negate &s)
{
s.a=-a;
s.b=-b;
display(s);
}
};

int main()
{
Negate n;
n.accept();

cout<<"\n\n Before Negate: ";
n.display(n);
cout<<"\n\n After Negate: ";
n.negate(n);
return 0;
}

Previous
Next Post »