Saved Bookmarks
| 1. |
A program is implemented to find the area of a circle and area of a rectangle with two functions having same name but with different signature.(a) Name the concept (b) Explain this concept by writing the above program. |
|
Answer» (a) Polymorphism (b) #include<iostream> #include<cmath> using namespace std; float area(float r) { return(3.14*pow(r,2)); } int area(int I, int b) { return(I*b); } { float r,Ac; int I,b,Ar; cout <<"Enter the radius of the circle"; cin>>r; AC = area(r); cout <<"Enter the length and breadth"; cin>>I>>b; Ar = area(I,b); cout<<"Area of circle is"<<Ac; cout<<"\n area of rectangle is"<<Ar; } Here the function names are same but the return type and number of parameters are different hence distinguish the functions. |
|