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
There are ''n'' ants on a ''n+1'' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are moving eith

I want Skype Recorder Application + Setup + Sourcecode + NICE UI Project Description: i want an application built which will allow user to record skype audio or video calls


Write a C++ program that can be used to evaluate the credit worthiness of a client. The program reads the credit limit and the price and quantity of the item to be purchased by the

Call by Reference Passing variables(parameters) to a function in C can be done in two ways - pass by value, also called as call by value and pass by address or also known as ca

how to do 2, 4, 8 associativity

Semaphore is used to synchronize processes. whereas mutex is used to give synchronization among threads running in the similar process.

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Write a program that predicts users’ age (0-128 years old) with at most 7 questions. The game starts with asking the user whether he/she is younger or older than G (an initial gues

Write an algorithm to print all even numbers in descending order and draw the flowchart.