Implement the class of a function object that takes integer

Implement the class of a function object that takes integer m, n as inputs and returns m % n. Show various ways of using your function object. C++

Solution

#include<iostream.h>
#include<conio.h>

//class declaration

class calc
{
public:
//function declared inside the class
float find_mod(int x, int y)
{

return(x%y);
}

float find_mod2(int x, int y);


};

//function body outside the class

float calc:: find_mod2(int x, int y)
{
return(x%y);
}


main()
{
calc obj1;
int m,n;
float output;

cout <<\"Enter value 1:\";
cin>>m;
cout<<\"Enter value 2:\";
cin>>n;

//calling function 1

output=obj1.find_mod(m,n);
cout<<\"Answer:\"<<output;

//calling function 2

output=obj1.find_mod(m,n);
cout<<\"\ Answer=\"<<output;
getch();


}

Implement the class of a function object that takes integer m, n as inputs and returns m % n. Show various ways of using your function object. C++Solution#inclu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site