C++ Program to find Mean Value of number using Friend function

By | 10.10.2016

Mean Value of number using Friend function


Write a C++ Program to find Mean Value of number using Friend function. Here’s a Simple C++ Program to find Mean Value of number using Friend function in C++ Programming Language.


What is Class and Objects in C++?


  • Class is a user defined data type, which holds its own data members and member functions, which can be accessed and used by creating instance of that class.
  • The variables inside class definition are called as data members and the functions are called member functions.
  • Class is just a blue print, which declares and defines characteristics and behavior, namely data members and member functions respectively. And all objects of this class will share these characteristics and behavior.

  • Objects are instances of class, which holds the data variables declared in class and the member functions work on these class objects.
  • Each object has different data variables. Objects are initialized using special class functions called Constructors.

Below is the source code for C++ Program to find Mean Value of number using Friend function which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C++ Program to find Mean Value of number using Friend function  */

#include<iostream>
using namespace std;

class  base
{
    int val1,val2;

   public:
        void get()
        {
           cout<<"\nEnter 1st value :: ";
           cin>>val1;
           cout<<"\nEnter 2nd value :: ";
           cin>>val2;
        }

        friend float mean(base ob);
};

float mean(base ob)
{
   return float(ob.val1+ob.val2)/2;
}

int main()
{


    base obj;
    obj.get();
    cout<<"\nMean value is :: "<<mean(obj)<<"\n";

    return 0;
}

OUTPUT : :


/*  C++ Program to find Mean Value of number using Friend function  */

Enter 1st value :: 5

Enter 2nd value :: 8

Mean value is :: 6.5

Process returned 0

Above is the source code and output for C++ Program to find Mean Value of number using Friend function which is successfully compiled and run on Windows System to produce desired output.

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post….

3.3 4 votes
Article Rating
Category: C++ Programming

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments