Write programme to find value using Friend Function.

Q. Write a programme to find maximum of two data or value using friend function.


# include < iostream.h >

     # include < conio.h >

    Using name space std;

    Class maximum field


Int data;


// member function declaration

Void get data ();

Void show ();

// member function declaration

Friend void max (Max friend, max friend);


// member function definition

Void max friend : : get data ()


Cout << "\n enter an integer = ";

Cin >> data;


Void max friend : : show ()


Cout << \n \n data :"


// friend function definition

Void max (max friend a, max friend b)


If (a. Data > b. Data)

Cout << " first data" << a. Data << "is greater than" << b. Data;


Cout << "second data" << b. Data << "is greater than" << a. Data;


Int main ()


Max friend num 1, num 2;

num 1. Get data ();

num 2. Get data ();

Max (num 1, num 2);

getch ();

   Related Questions in Programming Languages

  • Q : Explain Assignment operator Assignment

    Assignment operator: The operator (=) employed to store the value of an expression into the variable, for example: Variable = expression; The right-hand

  • Q : Block Started by Symbol What is the

    What is the Block Started by the Symbol?

  • Q : What is Hash function Hash function : A

    Hash function: A function employed to generate a hash code from the random contents of an object. The classes can override the hash Value method, inherited from the Object class, to state their own hash function.

  • Q : Define the term Garbage collector

    Garbage collector: It is a daemon thread which recycles objects to which there are no extant references in a program.

  • Q : Use of setjmp and longjmp Use of

    Use of setjmp() and longjmp(): In C/C++, setjmp() saves the contents of the registers at a particular state in the program and longjmp() will restore that state later. In this way, longjmp() “returns” to the state of the program when setjm

  • Q : Libraries involved in Windows

    Explain the important libraries involved in Windows programming?

  • Q : BAT files and shell scripts Using the

    Using the Web as a resource for your investigation, find out and explain what BAT files and shell scripts contain, and what they are used for. In the light of your findings, discuss why an operating system would provide both a graphical user interface

  • Q : Including CSS with the HEAD Tag

    Describe how to include the CSS within the HEAD Tag?

  • Q : Define Checked exception Checked

    Checked exception: An exception which should be caught locally in the try statement, or propagated through a throws clause stated in the method header.

  • Q : Explain Copy constructor Copy

    Copy constructor: It is a constructor which takes a single argument of similar class. For illustration:     public class Point {        

©TutorsGlobe All rights reserved 2022-2023.