Write a program to input two numbers and find the largest of them using nesting member function.
#include<iostream.h>
#include<conio.h>
class set
{
int a,b;
public:
void input(void);
void display(void);
int largest(void);
};
int set :: largest(void)
{
if(a>=b)
return (a);
else
return(b);
}
void set :: input(void)
{
cout<<"Input values of a and b:" << "\n";
cin >> a >>b;
}
void set :: display(void)
{
cout<<"Largest value ="<< largest( ) << "\n";
}
main( )
{
set A;
A.input( );
A.display( );
getch( );
return 0;
}
OUTPUT:
Input values of a and b:
3 4
Largest value= 4
#include<iostream.h>
#include<conio.h>
class set
{
int a,b;
public:
void input(void);
void display(void);
int largest(void);
};
int set :: largest(void)
{
if(a>=b)
return (a);
else
return(b);
}
void set :: input(void)
{
cout<<"Input values of a and b:" << "\n";
cin >> a >>b;
}
void set :: display(void)
{
cout<<"Largest value ="<< largest( ) << "\n";
}
main( )
{
set A;
A.input( );
A.display( );
getch( );
return 0;
}
OUTPUT:
Input values of a and b:
3 4
Largest value= 4
This is nice blog. The information you provide is remarkable. For more information on this topic, visit here Nesting of Member Functions – Object Oriented Programming (OOP)
ReplyDeletecan you please provide me answer of this question - using the concept of nesting of member function find the largest of any three numbers.
ReplyDeletenyc...i want more information and programs on nesting of member functon....
ReplyDelete