Function overloading in C++ with example program: This simple CPP tutorial code is all about overloading of functions. If more than two functions have a same name with different parameters[Or Arguments] in a program means that is said to be the functions overloading or methods overloading. And especially this source code is used to find the Area values. Example program is also listed at the bottom of this page.
Function overloading C++ example:
Question: C++ Program for Area of Square, Rectangle, Circle & Triangle using methods overloading.
[Useful: C Program Tutorials] & [IT Companies Details]
// Header Files #include<iostream.h> #include<conio.h> // Overloading Functions Declaration int Acalcu(int); int Acalcu(int, int); float Acalcu(float, double=3.14); float Acalcu(float, float, float=0.5); void main() { int Square, Length, Breadth; // Variables Declaration float Rectangle,Base,Height; clrscr(); cout<<"\n C++ Program for Area of Square, Rectangle, Circle & Triangle"; cout<<"Input values for Square, Length & Breadth:"; cin>>Square>>Length>>Breadth; cout<<"\n Input values for Rectangle,Base & Height:"; cin>>Rectangle>>Base>>Height; int SquareCal=Acalcu(Square); cout<<"\n Area of a Square is ="<<SquareCal; int RectangleCal=Acalcu(Length,Breadth); cout<<"\n Area of Rectangle is = "<<RectangleCal; float CircleCal=Acalcu(Rectangle); cout<<"\n Area of Circle is = "<<CircleCal; float TriangleCal=Acalcu(Base,Height); cout<<"\n Area of Triangle value is="<<TriangleCal; getch(); } int Acalcu(int k) { return(k*k); } int Acalcu(int k,int s) { return(k*s); } float Acalcu(float k,double s) { return(s*k*k); } float Acalcu(float x,float y,float z) // Function Overloading { return(x*y*z); }