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 to illustrate Array with Strings? main() { static char name[]="devdas"; int i; i=0; while(name[i]!='\0') { printf("%c",name[i]); i=i+1; } } In the

Explain Operator Overloading It is one type of Polymorphism, an significant feature of object-oriented programming .Polymorphism means one thing having many forms, i.e. here an

THIS PROGRAM IS TO DISPLAY A STOCK CONTAINING ITEM CODE,ITEM NAME,PRICE AND ANOTHER STOCK WITH CODE & QUANTITY AND DISPLAY COMPLETE INFORMATION #include #include #include

Within C we access external devices by means of a pointer i.e. address. The address could point to any memory mapped device i.e. Ram, Rom, Duart, Disk drives etc. Therefore there i

write a pseudocode algorithm for a program that accepts a number and prints out its reciprocal(1/n) is required.the program should prevent the user from entering zero by asking t

Write a program to compute the following equation for values of time.           y = 2x+3   The values of time are stored in the file program.dat and the solution should be display

em Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ''Content here, content here'', making it look like readable English. Many desktop publis

Explain each of the algorithms in a way that would be understandable to an intelligent person who is not familiar with programming. You should not use any code (or even pseudo code


convert lower case to uper case