--%>

Write programme to find value using Friend Function.

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

Ans. 

# include < iostream.h >

     # include < conio.h >

    Using name space std;

    Class maximum field

  {

Int data;

Public:

// 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;

Else

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 : Class and Object and explain diverse

    Q. Define class and object with example and explain diverse specifies.  

  • Q : Explain Functional programming

    Functional programming: It is a style of programming related with languages like Haskell. The functional programming languages are more strongly tied to a mathematical concept of `function' than imperative programming languages. This makes it simpler

  • Q : What is Universal Character Set or UTF

    UTF: Universal Character Set (abbreviated as UCS) Transformation Format. The format for symbolizing multibyte characters which is compatible with programs and file systems which were only made to handle single byte characters.

  • Q : Explain Declaration and initialization

    Declaration and initialization: It is a statement in which a variable is declared and instantly given its initial value. Three illustrations of declaration and initialization are as follows:     int

  • Q : Define Modem Modem : It is a

    Modem: It is a modulator-demodulator. A hardware device employed to connect a digital computer to an analogue telephone network by making analogue signals into digital signals, and vice-versa.

  • Q : Inventory management system in UML

    Mini-Case The Hatcher Company is in the process of developing a new inventory management system.  One of the event handling processes in that system is Receive Supplier Shipments.  The (inexperie

  • Q : Explain Window manager Window manager :

    Window manager: This is a window manager which provides a computer user with a virtual desktop having one or more windows and working regions in which individual programs might be run. Window managers permit the contents of a user's desktop to be arra

  • Q : ERD What is the meaning ofDerive the

    What is the meaning ofDerive the department and staff relations from the following ERD.

  • Q : Explain the good illustrations of

    Explain the good illustrations of closing XHTML elements.

  • Q : Define Container Abstractions Container

    Container Abstractions: Abstractions for containers (such as lists, stacks, sets, or queues) may represent just the state of a container—e.g., full or empty—and abstract away from the actual container content. The list operations also need