Friend function in c++, C/C++ Programming

Friend function in c++:

class miles;

class km

 {

   float value;

   public :

  // void input();

    km convert(km  ,int a ) ;

   void output()

   {

   cout << value;

   }

  };

 

                                km km :: convert(km a,int b)

                                {

                                a.value = b * 1.61;

                                return a;

                                }

 

 

 

 

                class miles

                  {

                   int value;

                   public:

 

                   void input()

                   {

                   cout << "Enter the value\n";

                  cin >> value;

                   }

                   friend km & convert(km &,miles);

                   };

 

                km & convert(km & a,miles b)

                                {

                                a= b.value * 1.61;

                                return a;

                                }

 

 

   void main()

   {

     km a;

     miles b;

      clrscr();

     b.input();

 

     a= convert (a,b);

     a.output();

     getch();

    }

Posted Date: 10/18/2012 7:48:53 AM | Location : United States







Related Discussions:- Friend function in c++, Assignment Help, Ask Question on Friend function in c++, Get Answer, Expert's Help, Friend function in c++ Discussions

Write discussion on Friend function in c++
Your posts are moderated
Related Questions
Conversion Functions Conversion functions are member functions used for the following purposes: 1. Conversion of object to basic data type. 2. Conversion of basic data ty

5 questions. plus i will provide the "vector.h" for the questions that needs it

What if I wish a local to "die" before the close} of the scope wherein it was created? Can I call a destructor on a local if I want to?

Greatest Common Divisor (GCD) - The greatest common divisor (GCD) of two integers is the largest integer that will evenly divide both integers. The GCD algorithm involves intege

want to understand the working of structure and classes

The #define Directive The #define directive explains a macro which is a text string represented by a name. Whenever the pre-processor finds this name in the program, it is repl

Question: a) Give two uses of NFS. b) Give one advantage of using NFS. c) Explain the following lines as they would be interpreted in the /etc/exports file i. /usr/local

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Run the following C++ program with and without preprocessor variable POSTFIX defined. #include using namespace std; extern "C" int atoi( const char *str );

how would land elevation have changed if Coronado had traveled 150 miles due west from what is today Arizona instead of east toward New Mexico