Monday, March 25, 2013

Simple Example of Function Overloading by Matee Gojra

By Unknown   Posted at  2:59 AM   C++ Programming No comments

/* Function Overloading is a Popular C++ Technique in Which a Functions of Same name works in a Different Methods, Functions can be Different in Following Aspects:

1- Number of Parameters

2-Types of Parameters

3-Difference in Return Type  */

#include<iostream>
using namespace std;
void max(int a,int b);
int max(int m,int n,int o);
void max(char a, char b, char c);
float max(float w,float x,float y);
int main()
{
    int j,k,l;
    char c,h,r; //Declaration of 3 Characters
    float f1,f2; // Floating Numbers
    cout<<"\n Enter Two Integers: ";
    cin>>j>>k;
    max(j,k);
    cout<<"\n Enter Three Integers: ";
    cin>>j>>k>>l;
    cout<<"\n Maximum is "<<max(j,k,l)<<endl;
    cout<<"\n Enter Three Characters: ";
    cin>>c>>h>>r;
    max(c,h,r);
    cout<<"\n Enter Two Decimal Values: ";
    cin>>f1>>f2;
    cout<<"\n Maximum is = "<<max(f1,f2)<<endl;
    cout<<"\n\t***************************\n";
    system("pause");
}
void max(int a,int b)
{
     if(a>b)
     cout<<"\n "<<a<<" is Maximum"<<endl;
     else
     cout<<"\n "<<b<<" is Maximum"<<endl;
}
int max(int m,int n,int o)
{
    int mx=0;
    if(m>mx)
    mx=m;
    if(n>mx)
    mx=n;
    if(o>mx)
    mx=o;
    return mx;
}
void max(char a, char b, char c)
{
     if(a>b && a>c)
     cout<<"\n "<<a<<" is Maximum"<<endl;
     else if(b>a && b>c)
     cout<<"\n "<<b<<" is Maximum"<<endl;
     else
     cout<<"\n "<<c<<" is Maximum"<<endl;
}
float max(float w,float x,float y)
{
      if(w>x && w>y)
      return w;
      else if(x>w && x>y)
      return x;
      else
      return y;
}
www.fb.com/MATEEGOJRA

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments:

Back to top ↑
Connect with Us

    What's Trending in Videoism

    Total Pageviews

    Copy of any Post is Not Allowed. All Rights Reserved with Matee ur Rehman (Author). Powered by Blogger.

    Advertisements

    Follow us on FaceBook

What they says

© 2013 GC Study Timez. WP Daily Quranand Hadith Converted by Matee Gojra
Blogger templates. Proudly Powered by Blogger.