0% found this document useful (0 votes)
5 views3 pages

Experiment No 09

The document presents two programs demonstrating function overloading in C++. The first program shows overloading of the 'add' function with varying numbers of integer arguments, while the second program illustrates overloading the 'mul' function with different types of arguments (int and float). Both programs include examples of how to call these overloaded functions and display their outputs.

Uploaded by

utkarsha ghanwat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Experiment No 09

The document presents two programs demonstrating function overloading in C++. The first program shows overloading of the 'add' function with varying numbers of integer arguments, while the second program illustrates overloading the 'mul' function with different types of arguments (int and float). Both programs include examples of how to call these overloaded functions and display their outputs.

Uploaded by

utkarsha ghanwat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment No.

09
Function overloading

Program:

//program of function overloading with different no. of arguments.

#include <iostream>

using namespace std;

class Cal {

public:

static int add(int a,int b) {

return a+b;

static int add(int a,int b,int c) {

return a+b+c;

static int add(int a,int b,int c,int d) {

return a+b+c+d;

static int add(int a,int b,int c,int d,int e) {

return a+b+c+d+e;

};

int main(void) {

Cal C;

cout<<C.add(10,20)<< endl;

cout<<C.add(12,20,23)<<endl;

cout<<C.add(27,17,18,31)<<endl;

cout<<C.add(19,21,27,31,47)<<endl;

return 0;
}

Output:

Program:

//program of function overloading with different type of arguments.

#include <iostream>

using namespace std;

int mul(int,int);

float mul(float,int);

int mul(int a,int b) {

return a*b;

float mul(double x,int y) {

return x*y;

int main() {

int r1 = mul(6,7);

float r2 = mul(0.2,3);

cout<< "r1 is : "<< r1<<endl;

cout<< "r2 is : "<< r2<<endl;

return 0;
}

Output:

You might also like