--%>

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 : Benefits of the event-delegation model

    Write down some of the benefits of the event-delegation model over event-inheritance model?

  • Q : Define the term Monitor Define the term

    Define the term Monitor: It is an object with one or more synchronized techniques.

  • Q : Explain why java is so important for

    The internet aided java to the forefront of programming. And java consequently has had a deep effect on the internet. The reason for this is highly simple: java uses the universe of objects that can travel freely in cyber space. In a network, two broad categories of

  • 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 : Criticizing CORBA technology Criticize

    Criticize the process by which the CORBA technology was designed and implemented.

  • Q : Explain the term XForms Explain the

    Explain the term XForms.

  • Q : Explain Increment operator Increment

    Increment operator: The operator (++) which adds one to its operand. It consists of two forms: pre-increment (++x) and post-increment (x++). In its pre-increment form, the outcome of the expression is the value of its argument subsequent to the increm

  • Q : Acknowledge inside a transaction Normal

    Normal 0 false false

  • Q : What is Namespace Namespace: It is the

    Namespace: It is the region of a program in which specific identifiers are visible. Java employs packages to give namespaces, and its visibility rules: package, private, protected, public-variously include identifiers within the namespaces.

  • Q : Explain String String: It is an

    String: It is an instance of the String class. A string comprises of zero or more Unicode characters, and they are not mutable or immutable, once formed. The literal string is written between a pair of string delimiters ("), as:

    Discover Q & A

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

    18,76,764

    1924178
    Asked

    3,689

    Active Tutors

    1456010

    Questions
    Answered

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

    Submit Assignment

    ©TutorsGlobe All rights reserved 2022-2023.