Function Overloading In C++ in Hindi

C++

Function Overloading In C++ in Hindi – C++ Me Overloading Functions Ka Istemal Kiya Jata Hai Or Function Overloading Ki Help Se Ham Kisi Bhi Functions Ko Arguments Ke Anushar Call Kar Sakte Hai |

Function Overloading Ko Ham Niche Example Se Dekhne Wale Hai |

Function Overloading In C++ in Hindi

Function Overloading Ko Ham Jab Istemal Karte Hai, Jab Hame Ek hi Function Me Multiple Type Ke Arguments Pass Karane Hote Hai, And Function Overloading Me Hame Sabhi Functions Ka Name Ek Hi Rakhna Hota Hai |

Function Overloading Ko Or Acche Se Understand Karne ke Liye Ham Ek Program Create Karte Hai Jo Karega find the area and volume of respective figures using function overloading.

Is Program Me Ham Class Measures Or Function shape Rakhne Wale Hai, Or shape function Ko Ham Overloading Karke Unki Type Change Karenge |

Example:

#include<iostream>
using namespace std;

const double pi=3.142;

class Measures
{ 
    public:
        void shape(double r)
        { 
            cout<<endl<<"Area of circle:"<<pi*r*r;
            cout<<endl<<"Volume of a sphere:"<<(4/3)*pi*r*r*r;
        }
        void shape(int l,int b,int h)
        {
            cout<<endl<<"Area of rectangle:"<<l*b;
            cout<<endl<<"Volume of a rectangle:"<<l*b*h;
        }
        void shape(int s)
        { 
            cout<<endl<<"Area of square:"<<s*s;
            cout<<endl<<"Volume of a cube:"<<s*s*s;
        }
};

int main()
{ 
Measures m;
int side,breadth,height,length;
double radius;

cout<<endl<<"Enter radius of circle:";
cin>>radius;
m.shape(radius);

cout<<endl<<"Enter length, breadth, and height of rectangle:";
cin>>length>>breadth>>height;
m.shape(length,breadth,height);

cout<<endl<<"Enter a side of a square:";
cin>>side;
m.shape(side);

return 0;
}

Output:

Enter radius of circle:4
Area of circle:50.272
Volume of a sphere:201.088
  
Enter length,breadth and height of rectangle:4 2 3
Area ofrectangle:8
Volume of rectangle:24
  
Enter a side of a sqaure:4
Area of square:16
Volume of a cube:64

Friends Mujhe Umeed Hai, Aapko Ye Post + Program Ke Sath Me Samanjh Aa Gayi Hogi, Fir Agar Aapko Kuch Bhi Dikkat Hoti Hai, To Aap Niche Comments Box Me Likh Kar Aapni Problem Ka Solution Le Sakte Hai |

Leave a Reply

Your email address will not be published.