write a program for function overloading?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
what is difference between objects and function
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
What does and I oop mean?
wht is major diff b/w c and c++?
What is function overloading and operator overloading?
Out of 4 concepts, which 3 C++ Follow?
Difference ways of Polymorphism?
Why do we use class?
Please tell me the oops concept with detailed answer
What is differance between Abstract and Interface
What is the difference between an object and a class?
What are the advantages of polymorphism?