14) Write a program to compute the area of a triangle and a circle by overloading the area( ) function.(function overloading)

Anonymous School

            (Minds of Hacker)

--------------------------------


Write a program to compute the area of a triangle and a circle by overloading the area( ) function.(function overloading)


C++ Practical



#include<iostream>
using namespace std;
void area(int hint b)
{
    float area;
    area=(h*b)/2;
    cout<<"Area of Triangle ="<<area;
}
void area(int r)
{
    float pi=3.141592653,area;
    area=pi*(r*r);
    cout<<"Area of Circle ="<<area;

}
int main()
{
    float r,h,b,choose;
    cout<<"Choose 1 for Area of Triangle\nChoose 2 for Area of circle\n";
    cin>>choose;
    if (choose==1)
    {
        cout<<"Enter the Height & base\n";
        cin>>h>>b;
        area(h,b);
    }
    else if (choose==2)
    {
        cout<<"Enter the Radius\n";
        cin>>r
        area(r);
    }
    else
    {
        cout<<"Invalid Option\n";
    }
    
    
}


Output:



Choose 1 for Area of Triangle Choose 2 for Area of circle 1 Enter the Height & base 20 3 Area of Triangle =30




 *******************Don't Make Learning Hard*****************



Follow us on :-

1) YouTube Channel :- Click Here

2) Blog                     :- Click Here


NextGen Digital... Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...