Thursday, December 13, 2012

Nesting of member function in c++


#include<iostream.h>
#include<conio.h>
class Demo
{
 int a, b;
public:
  void getdata();
  int largest();
  void display();
};
void Demo :: getdata()
{
   cout<<"enter any two numbers:";
   cin>>a>>b;
}
int Demo :: largest()
{
 if(a>=b)
 {
  return a;
 }
 else
 {
  return b;
 }
}
void Demo :: display()
{
 cout<<"\n larest number is:"<<largest();
}
int main()
{
Demo A;
clrscr();
A.getdata();
A.display();
getch();
return 0;
}

Output