Write a program that will demonstrate nested member function. The program that uses the following properties - class name- addnumber, integer type private member variable- a, b; three member function inputnumber(), int add(), show(). add() function will add the inputted value a, b like int x=a+b. show() function will call the add() function as a nested function and will display the addition value y as output.
#include <iostream>
#include <iostream>
using namespace std;
class addnumber
{
private:
int
a,b;
public:
void
inputnumber(void);
int
add(void);
void
show(void);
};
void addnumber :: inputnumber(void)
{
cin
>> a >> b;
}
int addnumber :: add(void)
{
int
x=a+b;
return(x);
}
void addnumber :: show(void)
{
cout
<< add();
}
int main()
{
addnumber
result;
result.inputnumber();
result.show();
return
0;
}
This is really wonderful blog. If you want more on this topic, have a look here..Nesting of Member Functions – Object Oriented Programming (OOP)
ReplyDelete