Wednesday, 11 March 2015

Write a program that will demonstrate nested member function

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>
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;

}

1 comment: