Write a C++ program to represent the function overriding using AVERAGE() function.

 #include <iostream>
 #include <string>
 using namespace std;
 int avrg( int , int );
 int avrg( int , int, int);
 float avrg( float, int);
 int avrg(char, char);
 int main()
 {
   int average;
   cin >> average;
   int averageI;
   cin >> averageI;
    float x;
    cin >>x;
   float y;
   cin >>y;
   float averageF = avrg(x,y);
   char averageC = avrg('x','y');
   //int &meal = food;
   cout << average << "\n";
   cout << averageI << "\n";
   cout << averageF << "\n";
   cout << averageC << "\n";
   //cout << &meal << "\n";
   return 0;
 }
 // Function Definitions
 int avrg(int x, int y)
 {
 return ((x + y)/2);
 }
 int avrg(int x, int y, int z)
 {
 return (( x + y + z )/3) ;
 }
 float avrg(float f, int i)
 {
 return (( f + i)/2) ;
 }
 int avrg(char c1, char c2)
 {
 return ((c1+c2)/2);
 } 

OUTPUT

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started