StudyLover
  • Home
  • Study Zone
  • Profiles
  • Contact us
  • Sign in
StudyLover 20. Program to find the maximum of two numbers using a friend function.
Download
  1. C++ Programs list
19. Program to read the data of `n` employees and compute the net salary of each employee (DA = 52% of basic and IT = 30% of the gross salary). : 21. Program to implement function templates.
C++ Programs list

1.      Program to find the maximum of two numbers using a friend function.

  1. #include <iostream.h>

  2. #include<conio.h>

  3. class Num {

  4. private:

  5.     int num;

  6.  

  7. public:

  8.     Num(int n) {

  9.         num = n;

  10.     }

  11.  

  12.     friend int max(Num n1, Num n2);

  13. };

  14.  

  15. int max(Num n1, Num n2) {

  16.     return n1.num > n2.num ? n1.num : n2.num;

  17. }

  18.  

  19. int main() {

  20.     Num n1(10), n2(20);

  21.  

  22.     int maxNum = max(n1, n2);

  23.  

  24.     cout << "Maximum number: " << maxNum << endl;

  25.     getch();

  26.     return 0;

  27. }

19. Program to read the data of `n` employees and compute the net salary of each employee (DA = 52% of basic and IT = 30% of the gross salary). 21. Program to implement function templates.
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website