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 : Programming with C# QUESTION 1      

    QUESTION 1       The following UML diagram describes an abstract class Customer. This class is to be used as part of a Company's inventory system. The inventory system will contain many different types of customers.  A separate s

  • Q : Maximum clock frequency of the circuit

    What do you mean by the term set up time and hold time constraints? Explain what do they mean? Which one is vital for estimating the maximum clock frequency of the circuit?

  • Q : What is validating parser What is

    What is validating parser? Answer: A parser makes sure that an XML document is valid additionally to being well formed.

  • Q : Features of WordPress Normal 0 false

    Normal 0 false false

  • Q : Explain Hot spot Hot spot : This is an

    Hot spot: This is an area in an image map with a specific significance. A program usually monitors movements of the mouse, and reacts according to the actions related with the hot spots over which it passes. This may comprise displaying various status

  • Q : Define Thread Thread : It is a

    Thread: It is a lightweight procedure which is managed by the Java Virtual Machine (abbreviated as JVM). Support for threads is given by the Thread class in java.lang package.

  • Q : Define Zip file Zip file : It is a file

    Zip file: It is a file employed to store compressed versions of the files. In connection with Java bytecode files, such have mostly been superseded by the Java Archive (abbreviated as JAR) files.

  • Q : Block Started by Symbol What is the

    What is the Block Started by the Symbol?

  • Q : What is Pattern Pattern : It is a

    Pattern: It is a recurring theme in class usage or design. Interfaces like Iterator encapsulate a pattern of admission to the items in a collection, whereas freeing the client from the requirement to know details of the way in which the collection is

  • Q : Define Number of Threads Number of

    Number of Threads: Threads can be a useful abstraction and implementation mechanism to partition independent program actions. However, when there is coordination (or interference) between these threads, the required synchronization mechanisms increase

©TutorsGlobe All rights reserved 2022-2023.