--%>

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 : Define Well-known port Well-known port

    Well-known port: It is a port number at which a server provides a familiar service. For example, 80 is well-known port number for the servers employing the HyperText Transfer Protocol (abbreviated as HTTP).

  • Q : State Sub type Sub type: It is a type

    Sub type: It is a type with a parent super type. The sub-type or super-type relationship is more common than the sub-class or super-class relationship. A class which implements an interface is a sub type of interface. An interface which expands the ot

  • Q : Who Issues Certificates and how Who

    Who Issues Certificates and How?

  • Q : How you can develop your capability in

    How you can develop your capability in test?

  • Q : Examples in Threading in Java I need

    I need urgent help in Examples of Threading in Java

  • Q : Explain For loop For loop : This is one

    For loop: This is one of the Java's three control structures employed for looping. The other two are while loop and do loop. A for loop includes of a loop header and a loop body. The header comprises of three expressions separated by two semicolons an

  • Q : Define the term non-XML resource Define

    Define the term non-XML resource?

  • Q : Define Protocol Protocol : It is a set

    Protocol: It is a set of rules for interaction between two processes. The protocol is generally specified in a Uniform Resource Locator (abbreviated as URL) to point out how a specific resource must be transferred from a Web server to the requesting c

  • Q : Describe Overriding for restriction

    Overriding for restriction: It is a form of method overriding in which the sub-class version of a method calls the super-class version first of all and then employs or manipulates the outcome or consequences of that call in some manner.

  • Q : Explain a quality and metrics reporting

    What opinion would you provide to someone who asked you where to begin to introduce to their company a quality and metrics reporting program?