Skip to main content

Posts

Showing posts with the label Friend Class Sample Program

C++ Program On Friend Class-Find Mean Of Two Numbers.

This is a sample program On using Friend Classes. Using Friend class, here we try to find the mean of two numbers. #include <iostream.h> #include <conio.h> class num {     int a,b;     public:        void read()          {             cout<<" Enter Two Numbers: ";             cin>>a>>b;          }        friend void mean(num x)          {             int k;             k=(x.a+x.b)/2;             cout<<" Arithmetic Mean: "<<k;          } }; void main() {     clrscr();     num n;     n.read();     mean (n);     getch(); } OUTPUT: Enter Two Numbers: 18 ...

C++ Program Using Friend Class-Add Two Time Together.

This is a sample program using Friend Classes. Using Friend Classes, here we add two different time together & display the final time. #include <iostream.h> #include <conio.h> class time {     private:        int h, m, s;     public:        void read()          {              cout<<" Enter Time In Hours:Minutes:Seconds \n";              cin>>h>>m>>s;          }        friend void add(time t1, time t2, time t3)          {              t3.h=t1.h+t2.h;              t3.m=t1.m+t2.m;              t3.s=t1.s+t2.s;              if (t3.s>=60)       ...