C++ Nesting of member functions


/ Published in: C++
Save to your folder(s)

basic usage of nesting


Copy this code and paste it in your HTML
  1. #include <iostream>
  2. //Vamsi
  3. // Nesting of member functions
  4. using namespace std;
  5. class comparing {
  6. int m,n;
  7. public:
  8. void input(void);
  9. void display(void);
  10. int larger(void);
  11. };
  12.  
  13. void comparing :: input(void) {
  14. cout << "Enter the two numbers to be compared \n";
  15. cin >> m >> n;
  16. }
  17.  
  18. void comparing :: display(void) {
  19. cout << "The larger number among the entered values is :" << larger() << endl;
  20. }
  21.  
  22. int comparing :: larger(void)
  23. {
  24. if (m >= n)
  25. {
  26. return (m);
  27. }
  28. else {
  29. return (n);
  30. }
  31. }
  32.  
  33. int main () {
  34. comparing x;
  35. x.input();
  36. x.display();
  37. return 0;
  38. }

URL: http://vamsii.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.