if you want to remove an article from website contact us from top.

    write a c++ program to find area of square, rectangle, circle and triangle using operator overloading.

    Mohammed

    Guys, does anyone know the answer?

    get write a c++ program to find area of square, rectangle, circle and triangle using operator overloading. from screen.

    Calculate area using function overloading

    Calculate area using function overloading - C++

    Home > CPP Programs > CPP Functions Programs

    « Previous Next »

    Programs

    C++ Programs using Functions

    Area and Perimeter

    Area and circumference

    Fahrenheit to Centigrade

    Centigrade to Fahrenheit

    Fibonacci series

    Swap using call-by-value

    Swap with call-by-reference

    Bubble sort

    Area using function overloading

    Greater no. with Inline function

    Program on recursive function

    Highest paid employee

    No. with maximum digit sum

    Q. Write a C++ program to calculate the area of triangle, rectangle and circle using function overloading. The program should be menu driven.Answer:

    Function overloading allows to use the same function name for different functions. It is used to enhance the readability of the program. You can change the number of arguments or have different data types of arguments to overload a function.

    In the below menu driven program, area() function is overloaded to calculate the area of triangle, rectangle and circle using function overloading.

    #include#include

    using namespace std;

    float area(float r) {

    return(3.14 * r * r);

    }

    float area(float b,float h)

    {

    return(0.5 * b * h);

    }

    float area(float l,float b)

    { return (l * b); } int main() { float b,h,r,l; int ch; do {

    cout<<"\n\n *****Menu***** \n";

    cout<<"\n 1. Area of Circle";

    cout<<"\n 2. Area of Triangle";

    cout<<"\n 3. Area of Rectangle";

    cout<<"\n 4. Exit";

    cout<<"\n\n Enter Your Choice : ";

    cin>>ch; switch(ch) { case 1: {

    cout<<"\n Enter the Radius of Circle : ";

    cout<<"\n Area of Circle : "<

    cin>>r;

    break; } case 2: {

    cout<<"\n Enter the Base & Height of Triangle : ";

    cout<<"\n Area of Triangle : "<

    cin>>b>>h;

    break; } case 3: {

    cout<<"\n Enter the Length & Bredth of Rectangle : ";

    cout<<"\n Area of Rectangle : "<

    cin>>l>>b;

    break; } case 4: exit(0); default:

    cout<<"\n Invalid Choice... ";

    } }while(ch!=4); return 0; }

    Output:1. Area of Circle

    2. Area of Triangle

    3. Area of Rectangle

    « Previous Next »

    स्रोत : www.tutorialride.com

    C++ program to find area of square,rectangle,circle and triangle by using function overloading

    Help me

    0

    C++ program to find area of square,rectangle,circle and triangle by using function overloading

    Help me functions inline

    23rd December 2019, 11:33 AM

    Ghanshyam Dhruw 1 Answer NEW ANSWER 0

    Show your effort to get help, this is not a code writing service.

    Please try to do it yourself, the assignment is meant for improving your programming skills.

    23rd December 2019, 12:48 PM

    ~ swim ~ (Inactive Till Indefinite Time)

    Hot Today

    Could not find or load main class Java

    I have a math problem so this is the code and he didn't work so why?

    Where's the mistake?

    Why can't I complete more than 3 of my code repo project?

    Why is my code not working olzz tell me ? 😭😭😭

    What is the solution

    What is algorithms and data structures and where can iearn it?

    What's wrong in this code

    What are the uses of various symbols?

    Add binary as string

    स्रोत : www.sololearn.com

    C++ Program to find Area using Function Overloading

    Area using Function Overloading Write a C++ program to find Area of square,rectangle,circle and triangle using Function Overloading. Here’s a Simple C++ program…

    C++ Program to find Area using Function Overloading

    By admin | 01.01.2017

    Area using Function Overloading

    Write a C++ program to find Area of square,rectangle,circle and triangle using Function Overloading. Here’s a Simple C++ program to find Area using Function Overloading in C++ Programming Language.

    What is Overloading in C++ ?

    C++ allows you to specify more than one definition for a function name or an operator in the same scope, which is called function overloading and operator overloading respectively.

    Function overloading : :

    You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You can not overload function declarations that differ only by return type.

    Operators overloading : :

    You can redefine or overload most of the built-in operators available in C++. Thus a programmer can use operators with user-defined types as well.

    Overloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined. Like any other function, an overloaded operator has a return type and a parameter list.

    Below is the source code for C++ program to find Area using Function Overloading which is successfully compiled and run on Windows System to produce desired output as shown below :

    SOURCE CODE : :

    /* C++ program to find Area using Function Overloading */

    #include

    using namespace std;

    int area(int); int area(int,int); float area(float);

    float area(float,float);

    int main() { int s,l,b; float r,bs,ht;

    cout<<"Enter side of a square:";

    cin>>s;

    cout<<"Enter length and breadth of rectangle:";

    cin>>l>>b;

    cout<<"Enter radius of circle:";

    cin>>r;

    cout<<"Enter base and height of triangle:";

    cout<<"Area of square is"<

    cin>>bs>>ht;

    cout<<"\nArea of rectangle is "<cout<<"\nArea of circle is "<cout<<"\nArea of triangle is "<

    } int area(int s) { return(s*s); }

    int area(int l,int b)

    { return(l*b); } float area(float r) { return(3.14*r*r); }

    float area(float bs,float ht)

    { return((bs*ht)/2); }

    OUTPUT : :

    /* C++ program to find Area using Function Overloading */

    Enter side of a square:2

    Enter length and breadth of rectangle:3 6

    Enter radius of circle:3

    Enter base and height of triangle:4 4

    Area of square is4

    Area of rectangle is 18

    Area of circle is 28.26

    Area of triangle is 8

    Above is the source code and output for C++ program to find Area using Function Overloading which is successfully compiled and run on Windows System to produce desired output.

    If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.

    Thanks for reading the post….

    4.1 Article Rating

    Related posts:

    C++ Program to Find Area of Shapes using Function Overloading

    C++ Program to check Palindrome using function overloading

    C++ Program for Complex Operations using Operator Overloading

    स्रोत : www.codezclub.com

    Do you want to see answer or more ?
    Mohammed 2 month ago
    4

    Guys, does anyone know the answer?

    Click For Answer