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
Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

#question. write a program number to alphabet in c++..

wap to calculatethe volume of cone,cylinderand sphere

For this program, you are going to modify your previous program (program 3) so that it will now have a menu to see if the user wants to read the input from a file or interactively.

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

convert string s into palindrome by doing character replacement

Classify computer system according to capacity. How they are different from computers according to the classification of technology. Provide comparative study also.