write a program for function overloading?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is inheritance write a program to show use of inheritance?

913


What is encapsulation process?

807


What is abstraction with example?

855


any one please tell me the purpose of operator overloading

2192


What is a class and object?

818


What does I oop mean?

860


can inline function declare in private part of class?

4024


Which language is not a true object oriented programming language?

904


What is interface in oop?

894


is there any choice in opting subjects like 4 out of 7

1965


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

1869


What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?

2328


How to use CMutex, CSemaphore in VC++ MFC

4559


How is polymorphism achieved?

794


Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

979