Write a program that will demonstrate private member function. The program that uses the following properties - class name- xyz, integer type private member variable- m, n. One private member function getvalue(), two public member function - int mul(), show(). mul() function will call private member function getvalue() for input number m, n and multiply the inputted value m, n like int s=m*n. show() function will display the multiplication value s as output.
#include <iostream>
#include <iostream>
using namespace std;
class xyz
{
private:
int
m,n;
void
getvalue(void);
public:
int
mul(void);
void
show(void);
};
void xyz :: getvalue(void)
{
cin
>> m >> n;
}
int xyz :: mul(void)
{
getvalue();
int
s=m*n;
return(s);
}
void xyz :: show(void)
{
cout
<< mul();
}
int main()
{
xyz m;
m.show();
return
0;
}
No comments:
Post a Comment