Friend Function


Program using friend function to convert second into hours and minutes





#include<iostream.h>
#include<conio.h>
class Time
{
private:
  int secs,hrs,min;
public:
  void getdata()
  {
    cout<<"\nEnter time in seconds :: ";
    cin>>secs;
  }
  void putdata()
  {
    cout<<"\nConverted Time is "<<hrs<<":"<<min<<":"<<secs;
  }
  friend void convert(Time T)
  {
    T.min=T.secs/60;
    T.secs=T.secs%60;
    T.hrs=T.min/60;
    T.min=T.min%60;
    T.putdata();
  }
};
void main()
{
Time X;
clrscr();
X.getdata();
convert(X);
getch();
}


OUTPUT
Enter Time In seconds :: 500
Converted Time is 0:8:20


-----

Firoz Memon

Please view my other blogs:

          C++ Codes 4 Beginners

          Java Tips

          Java 4 Beginners

Previous Post Next Post