--%>

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 : Explain Mutator method Mutator method :

    Mutator method: It is a method specifically designed to permit controlled modification of a private attribute of a class. By convention, we name the mutators with a set prefix obeyed by the name of the attribute being transformed. For example, the mut

  • Q : Define the term Class constant Define

    Define the term Class constant: A variable which is defined as both final and static.

  • Q : Define Number of Interleavings Number

    Number of Interleavings: Besides the raw number of threads, the state space is affected by the number of potential interleavings of these threads. While there exist automated techniques (partial-order reduction) to reduce these interleavings, most mod

  • Q : Define Final variable Final variable :

    Final variable: A variable with final reserved word in its declaration. The final might not assigned to once it has been initialized. Initialization frequently occurs as a part of its declaration. Though, the initialization of an uninitialized final f

  • Q : State-space Reduction in Promela model

    State-space Reduction: Two language statements are used to reduce the number of states in a Promela model: atomic and d-step. 1553_state</span></p>
                                        </div>
                                        <!-- /comment-box -->
                                    </li>
   
   </td>
	</tr><tr>
		<td>
       
      <li>
                                        <div class=

    Q : Acknowledge inside a transaction Normal

    Normal 0 false false

  • Q : Explain Virtual memory Virtual memory :

    Virtual memory: It is computer will comprise a limited amount of real memory accessible to it. Programs frequently need more memory than the quantity of real memory. Moreover, in a multiprogramming system, various processes will be competing for simil

  • Q : Use of new operator What is the use of

    What is the use of new operator?

  • Q : Program for Linux operating system that

    Write a program for Linux operating system that uses Posix threads to sort a large array.  Specifically, you should write a program to generate random numbers. Then create at least two threads, each of which sorts a portion of the array. After the thr

  • Q : How much does Symbian Signed

    How much does Symbian Signed certification and testing cost? Answer: Test houses contain their own prices for Symbian Signed testing. So you can check that prices through searching over the internet.