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 : Define the term RGB Color Model Define

    Define the term RGB Color Model: It is a color model based on representing a color as three components: green, red, and blue.

  • Q : Syntax to create AJAX objects Write the

    Write the syntax to create the AJAX objects?

  • Q : Define the Binding of Instructions and

    Define the Binding of Instructions and Data to Memory?

  • Q : Define the term Class constant Define

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

  • Q : Explain Structured programming

    Structured programming: It is a style of programming generally related with languages like FORTRAN, C, Pascal and so forth. Employing structured programming methods, a problem is frequently resolved employing a divide and conquer approach like stepwis

  • Q : What is the way to use XForms What is

    What is the way to use XForms?

  • Q : Explain Cast Cast : Where Java does not

    Cast: Where Java does not allow the utilization of a source value of one type, it is essential to use a cast to force the compiler to admit the use for the target type. The care must be taken with casting values of primitive types, as this frequently

  • Q : What are good examples of XHTML

    What are the good examples of XHTML elements along with contents?

  • Q : Explai phases of software development

    Define the difference between phases of software development or software life cycle?

  • Q : Reference variables Reference variable

    Discover Q & A

    Leading Solution Library
    Avail More Than 1451709 Solved problems, classrooms assignments, textbook's solutions, for quick Downloads
    No hassle, Instant Access
    Start Discovering




    Active Tutors



    Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!

    Submit Assignment

    ©TutorsGlobe All rights reserved 2022-2023.