write a program for function overloading?

Answers were Sorted based on User's Feedback



write a program for function overloading?..

Answer / nekkanti rajesh

#include<iiostream.h>
class overload
{
public:
int max(int,int);
floatmax(float,float);
};
int overload::max(int num1,int num2)
{
if(num1>nmu2)
{
return num1;
}
else
{
return num2;
}
}
float overload::max(float num1,float num2)
{
if(num1>num2)
{
return num1;
}
else
{
return num2;
}
}
int main(90
{
overload o1;
cout<<"o1.max(5.4f,8.6f)<<endl;
cout<<"o1.max(19,34)<<endl;
}

Is This Answer Correct ?    143 Yes 57 No

write a program for function overloading?..

Answer / n. sakthi ganesh

8.6 for float
34 for int

Is This Answer Correct ?    64 Yes 23 No

write a program for function overloading?..

Answer / abhishek.karal

Program illustrating function overloading

# include<iostream.h>
# include<conio.h>
int area(int side)
{
return side*side;
}
int area(int l , int b)
{
return l*b;
}

void main()
{
clrscr();
int (*p1)(int);
int (*p2)(int,int);

p1=area;
p2=area;

cout<<"Address of area(int)="<<(unsigned int)p1<<endl;
cout<<"Address of area(int,int)="<<(unsigned int)p2<<endl;

cout<<"Invoking area(int) via p1 "<<p1(20)<<endl;
cout<<"Invoking area(int,int) via p2 "<<p2(10,20);
getch();
}

Is This Answer Correct ?    57 Yes 23 No

write a program for function overloading?..

Answer / krithika

#include<iostream.h>
#include<conio.h>
class a
{
public:
int area(int a)
{
cout<<"enter the side";
cin>>a;
return(a*a);
}
float area(float l,float b)
{
cout<<"enter the length and breadth":
cin>>l>>b;
return(l*b);
}
};
int main()
{
clrscr();
a e;
int a;
float l,b;
cout<<"the area of a square"<<e.area(a);
cout<<"the area of a rectangle"<<e.area(l,b);
getch();
return 0;
}

Is This Answer Correct ?    44 Yes 13 No

write a program for function overloading?..

Answer / sudesh kumar

#include<iostream.h>
#include<conio.h>
void add(int,int);
void add(int);
void main()
{
int a,b;
cout<<"enter two no";
cin>>a>>b;
add(a,b);
add(a);
getch();
}
void add(int x,int y)
{
int z;
z=x+y;
cout<<"the sum is "<<z;
}
void add(int x)
{
int z;
z=x*x;
cout<<"the sequre is A value"<<z;
}

Is This Answer Correct ?    37 Yes 11 No

write a program for function overloading?..

Answer / raja

#include<iiostream.h>
class overload
{
public:
int sum(int,int);
float sum(float,float);
};
int overload::sum(int num1,int num2)
{
return num1 + num2;
}
}
float overload::sum(float num1,float num2)
{
return num1+ num2
}
}
int main(90
{
overload o1;
cout<<"o1.sum(5.4f,8.6f)<<endl;
cout<<"o1.sum(19,34)<<endl;
}

Is This Answer Correct ?    28 Yes 8 No

write a program for function overloading?..

Answer / selvanayaki

#include<conio.h>
#include<iostream.h>

class arith {
public:
void calc(int num1)

{
cout<<"\n\nSquare of a given number: " <<num1*num1 <<endl;
}

void calc(int num1, int num2 )

{
cout<<"\n\nSquare of a given number: " <<num1*num2 <<endl;
}
};


void main() //begin of main function
{
clrscr();
arith a;
a.calc(5);
a.calc(6,7);
getch();
}

Is This Answer Correct ?    25 Yes 7 No

write a program for function overloading?..

Answer / riks

#include<iiostream.h>
class overload
{
public:
int sum(int,int);
float sum(float,float);
};
int overload::sum(int num1,int num2)
{
return num1 + num2;
}
}
float overload::sum(float num1,float num2)
{
return num1+ num2
}
}
int main(90
{
overload o1;
cout<<"o1.sum(5.4f,8.6f)<<endl;
cout<<"o1.sum(19,34)<<endl;

Is This Answer Correct ?    39 Yes 23 No

write a program for function overloading?..

Answer / abhinav kr

#include<iostream.h>
#include<conio.h>
void printline();
void printline(char ch);
void printline(char ch,int n);
void main()
{
printline();
printline('$');
printline('$',5);
}
void printline()
{
clrscr();
for(int i=1;i<=5;i++)
cout<<"*"<<endl;
}
void printline (char ch)
{
for(int i=1;i<=5;i++)
cout<<ch<<endl;}
void printline(char ch,int n)
{
for(int i=1;i<=n;i++)
cout<<ch<<endl;
getch();
}

Is This Answer Correct ?    12 Yes 2 No

write a program for function overloading?..

Answer / narmadha

same function name with multiple definitions

#include <iostream.h>
void print(int i)
{
cout << " int " << i << endl;
}
void print(double f)
{
cout << " float " << f << endl;
}
void print(char* c)
{
cout << " char " << c << endl;
}
int main()
{
print(10);
print(10.10);
print("a");
return 0;
}

Is This Answer Correct ?    6 Yes 2 No

Post New Answer

More OOPS Interview Questions

who is the founder of c++?

15 Answers   Hexaware, ONGC,


What is Object and Class? What are the differences between them?

5 Answers  


What is object in oop with example?

0 Answers  


What is the difference between Home and $Home?

2 Answers   TCS,


what is the difference between <stdio.h>and "stdio.h"?

5 Answers  






why to use template classes in c++?

1 Answers  


if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?

1 Answers  


Write 7 differences between "Public" function and "Private" function?

2 Answers   IBM, Wipro,


What is deep and shalow copy?

3 Answers   L&T, TCS,


what is function overloading..?

4 Answers  


What is a scope resolution operator?

5 Answers   HP, IBS,


What is the important feature of inheritance?

0 Answers   BPL,


Categories