class myclass{ int n,d; public: myclass(int i,int j){ n = i; d = j;} //declare a friend of myclass friend int isfactor(myclass ob); }; int isfactor(myclass ob) { if(!(ob.n % ob.d)) return 1; else return 0; } int main( ) { myclass ob1(10,2),ob2(13,3); if(isfactor(ob1)) cout<<"2 is a factor of 10\n"; else cout <<"2 is not a factor of 10\n"; if(isfactor(ob2) cout<<"3 is a factor of 13\n"; else cout<<"3 is not a factor of 13\n"; return 0; }
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
class myclass{int n,d;
public:
myclass(int i,int j){ n = i; d = j;}
//declare a friend of myclass
friend int isfactor(myclass ob);
};
int isfactor(myclass ob)
{
if(!(ob.n % ob.d)) return 1;
else return 0;
}
int main( )
{
myclass ob1(10,2),ob2(13,3);
if(isfactor(ob1)) cout<<"2 is a factor of 10\n";
else cout <<"2 is not a factor of 10\n";
if(isfactor(ob2) cout<<"3 is a factor of 13\n";
else cout<<"3 is not a factor of 13\n";
return 0;
}