18.10.14

OOP : Excercise-4.1 : C++ program to find area of triangle, circle,and rectangle using function overloading

Write a C++ program to find area of triangle, circle,and rectangle using function overloading

66 comments:

  1. #include
    #include
    const float pi=3.14;

    float area(float n,float b,float h)
    {
    float area;
    area=n*b*h;
    return area;
    }

    float area(float r)

    {
    float area;
    area=pi*r*r;
    return area;
    }

    float area(float l,float b)

    {
    float area;
    area=l*b;
    return area;
    }

    void main()
    {
    float b,h,r,l;
    float result;
    clrscr();
    cout<<"\nEnter the Base & Hight of Triangle: \n";
    cin>>b>>h;
    result=area(0.5*b*h);
    cout<<"\nArea of Triangle:"<>r;
    result=area(r);
    cout<<"\nArea of Circle:"<>l>>b;
    result=area(l,b);
    cout<<"\nArea of Rectangle:"<<result<<endl;
    getch();
    }


    //Md. Imam Uddin
    //ID 201420733

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. ID-201420406

      #include
      #include
      Float area(int r)
      {
      cout<>r;area(r);
      cout<>b>>h;
      area(b,h);
      cout<>l>>br;
      area(l,br);
      getch();
      return 0;
      }

      Delete
    2. I don't think that you submitted full program. main() function is missed. Please check and update your comments.

      Delete
  3. #include
    #include
    const float pi=3.14;

    float area(float n,float b,float h)
    {
    float area;
    area=n*b*h;
    return area;
    }

    float area(float r)

    {
    float area;
    area=pi*r*r;
    return area;
    }

    float area(float l,float b)

    {
    float area;
    area=l*b;
    return area;
    }

    void main()
    {
    float b,h,r,l;
    float result;
    clrscr();
    cout<<"\nEnter the Base & Hight of Triangle: \n";
    cin>>b>>h;
    result=area(0.5*b*h);
    cout<<"\nArea of Triangle:"<>r;
    result=area(r);
    cout<<"\nArea of Circle:"<>l>>b;
    result=area(l,b);
    cout<<"\nArea of Rectangle:"<<result<<endl;
    getch();
    }


    Moonmoon Hossain
    ID 201420685

    ReplyDelete
    Replies
    1. its better to change something after get from others

      Delete
  4. #include
    using namespace std;
    const float pi=3.14;
    float area(float n,float b,float h)
    {
    return (b*h)/2;
    }
    float area(float r)
    {
    return pi*r*r;
    }
    float area(float l,float b)
    {
    return l*b;
    }
    int main()
    {
    float x,y,area;
    int m=2;
    x=5;
    y=6;
    area=(x*y)/m;
    cout<<"the area of triangle:"<<area<<endl;

    float pi,z;
    pi=3.14;
    z=2;
    area=pi*z*z;
    cout<<"the area of circle:"<<area<<endl;

    float k,p;
    k=8;
    p=7;
    area=k*p;
    cout<<"the area of rectangle:"<<area<<endl;
    return 0;
    }
    Tarif Mohammad
    201410876

    ReplyDelete
    Replies
    1. answer is not correct. submit again after correction.

      Delete
  5. /* Mujaffor Ali Sumon
    Id-201420170*/

    #include
    using namespace std;

    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    main()
    {
    float b,h,r,l;
    float result;

    cout<<"Enter the Base & Hieght of Triangle: ";
    cin>>b>>h;
    cout<<'\n';
    result=area(0.5,b,h);
    cout<<'\n';
    cout<<"The area of Triangle: "<>r;
    result=area(r);
    cout<<'\n';
    cout<<"the area of Circle:"<>l>>b;
    result=area(l,b);
    cout<<'\n';
    cout<<"The area of Rectangle:"<<result<<endl;

    }

    ReplyDelete
    Replies
    1. Everything is correct but cout management is not perfectly done under main() body. its not user friendly. you may correct it and submit again.

      Delete
    2. http://itlearn24.blogspot.com/2014/11/c-program-to-find-area-of-triangle.html

      Delete
  6. Tamanna Sultana
    Id: 201421041

    #include
    Float area(int r)
    {
    cout<>r;area(r);
    cout<>b>>h;
    area(b,h);
    cout<>l>>br;
    area(l,br);
    getch();
    return 0;
    }

    ReplyDelete
  7. /*
    Md. Monir Hossain
    ID: 201421112
    */

    #include
    using namespace std;

    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    main()
    {
    float b,h,r,l;
    float result;

    cout<<"Enter the Base & Hieght of Triangle: ";
    cin>>b>>h;
    cout<<'\n';
    result=area(0.5,b,h);
    cout<<'\n';
    cout<<"The area of Triangle: "<>r;
    result=area(r);
    cout<<'\n';
    cout<<"the area of Circle:"<>l>>b;
    result=area(l,b);
    cout<<'\n';
    cout<<"The area of Rectangle:"<<result<<endl;

    }

    ReplyDelete
    Replies
    1. you must change it something from others program

      Delete
  8. #include
    using namespace std;

    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    main()
    {
    float b,h,r,l;
    float result;

    cout<<"Enter the Base & Hieght of Triangle: ";
    cin>>b>>h;
    cout<<'\n';
    result=area(0.5,b,h);
    cout<<'\n';
    cout<<"The area of Triangle: "<>r;
    result=area(r);
    cout<<'\n';
    cout<<"the area of Circle:"<>l>>b;
    result=area(l,b);
    cout<<'\n';
    cout<<"The area of Rectangle:"<<result<<endl;

    }


    ## Md. Abdus Salam
    ID: 201420341

    ReplyDelete
  9. Anik adhikary
    201420798

    #include
    #include
    Float area(int r)
    {
    cout<>r;area(r);
    cout<>b>>h;
    area(b,h);
    cout<>l>>br;
    area(l,br);
    getch();
    return 0;
    }

    ReplyDelete
  10. Md. Khairul Hasan
    201420529

    #include
    #include
    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    void main()
    {
    float b,h,r,l;
    float result;
    clrscr();
    cout<<“\nEnter the Base & Hieght of Triangle: \n”;
    cin>>b>>h;
    result=area(0.5,b,h);
    cout<<“\nArea of Triangle: “<>r;
    result=area(r);
    cout<<“\nArea of Circle: “<>l>>b;
    result=area(l,b);
    cout<<“\nArea of Rectangle: “<<result<<endl;
    getch();
    }

    ReplyDelete
  11. create a simple calculator for addition, subtraction, multiplication and division in c++


    # include
    int main()
    {
    char o;
    float num1,num2;
    printf("Enter operator either + or - or * or divide : ");
    scanf("%c",&o);
    printf("Enter two operands: ");
    scanf("%f%f",&num1,&num2);
    switch(o) {
    case '+':
    printf("%.1f + %.1f = %.1f",num1, num2, num1+num2);
    break;
    case '-':
    printf("%.1f - %.1f = %.1f",num1, num2, num1-num2);
    break;
    case '*':
    printf("%.1f * %.1f = %.1f",num1, num2, num1*num2);
    break;
    case '/':
    printf("%.1f / %.1f = %.1f",num1, num2, num1/num2);
    break;
    default:
    /* If operator is other than +, -, * or /, error message is shown */
    printf("Error! operator is not correct");
    break;
    }
    return 0;
    }

    ReplyDelete
  12. reate a simple calculator for addition, subtraction, multiplication and division in c++


    # include
    int main()
    {
    char o;
    float num1,num2;
    printf("Enter operator either + or - or * or divide : ");
    scanf("%c",&o);
    printf("Enter two operands: ");
    scanf("%f%f",&num1,&num2);
    switch(o) {
    case '+':
    printf("%.1f + %.1f = %.1f",num1, num2, num1+num2);
    break;
    case '-':
    printf("%.1f - %.1f = %.1f",num1, num2, num1-num2);
    break;
    case '*':
    printf("%.1f * %.1f = %.1f",num1, num2, num1*num2);
    break;
    case '/':
    printf("%.1f / %.1f = %.1f",num1, num2, num1/num2);
    break;
    default:
    /* If operator is other than +, -, * or /, error message is shown */
    printf("Error! operator is not correct");
    break;
    }
    return 0;
    }


    papiya sultana popi
    201420270

    ReplyDelete
  13. MD: Rashed Prodhania
    ID : 201420763
    Batch : 46th

    #include
    #include
    Float area(int r)
    {
    cout<>r;area(r);
    cout<>b>>h;
    area(b,h);
    cout<>l>>br;
    area(l,br);
    getch();
    return 0;
    }

    ReplyDelete
  14. #include
    class power
    {
    public:
    inline int square(int n)
    {
    return n*n;
    }
    inline int cube(int n)
    {
    return n*n*n;
    }
    };
    void main()
    {
    int n,r;
    power p;
    clrscr();
    cout<<“\nEnter the Number: \n” ;
    cin>>n;
    r=p.square(n);
    cout<<“\nSquare of “<<n<<” = “<<r<<endl;
    r=p.cube(n);
    cout<<“\nCube of “<<n<<” = “<<r<<endl;
    getch();
    }
    Md.Hasmot Hossen
    ID:201421066

    ReplyDelete
  15. yeasmin Akter
    ID:201420271
    Batch:46
    #include
    #include
    Float area(int r)
    {
    cout<>r;area(r);
    cout<>b>>h;
    area(b,h);
    cout<>l>>br;
    area(l,br);
    getch();
    return 0;
    }

    ReplyDelete

  16. #include
    using namespace std;
    const float pi=3.14;
    float area(float n,float b,float h)
    {
    return (b*h)/2;
    }
    float area(float r)
    {
    return pi*r*r;
    }
    float area(float l,float b)
    {
    return l*b;
    }
    int main()
    {
    float x,y,area;
    int m=2;
    x=5;
    y=6;
    area=(x*y)/m;
    cout<<"the area of triangle:"<<area<<endl;

    float pi,z;
    pi=3.14;
    z=2;
    area=pi*z*z;
    cout<<"the area of circle:"<<area<<endl;

    float k,p;
    k=8;
    p=7;
    area=k*p;
    cout<<"the area of rectangle:"<<area<<endl;
    return 0;
    }

    Md.Hasmot Hossen
    ID:201421066

    ReplyDelete
  17. C++ program using class to calculate simple interest amount use default value for rate.

    #include
    #include
    class interest
    {
    int n;
    float rate,p;
    public:
    void get()
    {
    cout<<“\nEnter principle Amount & no. of year: \n”;
    cin>>p>>n;
    }
    void cal(float rate)
    {
    float si;
    si=(p*n*rate)/100;
    cout<<“\n\nSimple Interest is: “<<si;
    }
    };
    void main()
    {
    interest i;
    clrscr();
    i.get();
    i.cal(4.5);
    getch();
    }


    Md.Hasmot Hossen
    ID:201421066

    ReplyDelete
  18. Md.Sanwer Hossen
    Id.201421068


    #include
    class power
    {
    public:
    inline int square(int n)
    {
    return n*n;
    }
    inline int cube(int n)
    {
    return n*n*n;
    }
    };
    void main()
    {
    int n,r;
    power p;
    clrscr();
    cout<<“\nEnter the Number: \n” ;
    cin>>n;
    r=p.square(n);
    cout<<“\nSquare of “<<n<<” = “<<r<<endl;
    r=p.cube(n);
    cout<<“\nCube of “<<n<<” = “<<r<<endl;
    getch();
    }

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. papiya sultana popi
    201420270
    #include
    #include
    Float area(int r)
    {
    cout<>r;area(r);
    cout<>b>>h;
    area(b,h);
    cout<>l>>br;
    area(l,br);
    getch();
    return 0;
    }

    ReplyDelete
  21. /*Sharmin Akhter
    ID-201420769*/
    #include
    using namespace std;

    float interest(float period,float rate,float principle)
    {
    float calc=(principle*period*rate)/100;
    return calc;
    }
    main()
    {
    float period;
    float rate;
    float principle;
    cout<<"Enter principle Amount: ";
    cin>>principle;
    cout<<"--------------------"<<'\n';
    cout<<"Enter no. of period: ";
    cin>>period;
    cout<<"--------------------"<<'\n';

    cout<<"Simple Interest is:"<<interest(principle,period,4.5)<<endl<<endl;

    }

    ReplyDelete
  22. /*Sharmin Akhter
    ID-201420769*/

    #include
    using namespace std;

    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    main()
    {
    float b,h,r,l;

    cout<<"Enter the Base & Hieght of Triangle: ";
    cin>>b>>h;
    cout<<'\n';
    cout<<"The area of Triangle: "<>r;
    cout<<'\n';
    cout<<"the area of Circle:"<>l>>b;
    cout<<'\n';
    cout<<"The area of Rectangle:"<<area(l,b)<<endl;

    }

    ReplyDelete
    Replies
    1. error under main() body. correct it and submit again.

      Delete
  23. /*Razia Sultana
    ID-201420715*/

    #include
    using namespace std;

    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    main()
    {
    float b,h,r,l;

    cout<<"Enter the Base & Hieght of Triangle: ";
    cin>>b>>h;
    cout<<'\n';
    cout<<"The area of Triangle: "<>r;
    cout<<'\n';
    cout<<"the area of Circle:"<>l>>b;
    cout<<'\n';
    cout<<"The area of Rectangle:"<<area(l,b)<<endl;

    }

    ReplyDelete
  24. id.201420931
    #include
    using namespace std;

    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    main()
    {
    float b,h,r,l;
    float result;

    cout<<"Enter the Base & Hieght of Triangle: ";
    cin>>b>>h;
    cout<<'\n';
    result=area(0.5,b,h);
    cout<<'\n';
    cout<<"The area of Triangle: "<>r;
    result=area(r);
    cout<<'\n';
    cout<<"the area of Circle:"<>l>>b;
    result=area(l,b);
    cout<<'\n';
    cout<<"The area of Rectangle:"<<result<<endl;

    }

    ReplyDelete
  25. Parvina khatun
    ID.201420931

    #include
    #include
    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    void main()
    {
    float b,h,r,l;
    float result;
    clrscr();
    cout<<“\nEnter the Base & Hieght of Triangle: \n”;
    cin>>b>>h;
    result=area(0.5,b,h);
    cout<<“\nArea of Triangle: “<>r;
    result=area(r);
    cout<<“\nArea of Circle: “<>l>>b;
    result=area(l,b);
    cout<<“\nArea of Rectangle: “<<result<<endl;
    getch();
    }

    ReplyDelete
  26. /*Mahmudul Hasan Nayeem
    ID-201420790*/

    #include
    using namespace std;
    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    main()
    {
    float b,h,r,l;
    float result;
    cout<<"Enter the Base & Hieght of Triangle: ";
    cin>>b>>h;
    cout<<'\n';
    result=area(0.5,b,h);
    cout<<"The area of Triangle: "<>r;
    result=area(r);
    cout<<'\n';
    cout<<"The area of Circle is: "<>l>>b;
    result=area(l,b);
    cout<<"The area of Rectangle:"<<result<<endl;

    }

    ReplyDelete
    Replies
    1. problem in main() body. cout management problem.

      Delete
  27. Md : jalis Mahmud
    ID :201420762

    #include
    using namespace std;

    const float pi=3.14;
    float area(float n,float b,float h)
    {
    float ar;
    ar=n*b*h;
    return ar;
    }
    float area(float r)
    {
    float ar;
    ar=pi*r*r;
    return ar;
    }
    float area(float l,float b)
    {
    float ar;
    ar=l*b;
    return ar;
    }
    main()
    {
    float b,h,r,l;

    cout<<"Enter the Base & Hieght of Triangle: ";
    cin>>b>>h;
    cout<<'\n';
    cout<<"The area of Triangle: "<>r;
    cout<<'\n';
    cout<<"the area of Circle:"<>l>>b;
    cout<<'\n';
    cout<<"The area of Rectangle:"<<area(l,b)<<endl;

    }

    ReplyDelete
    Replies
    1. not correct. problem in main() body. try to improve cout management.

      Delete
  28. Name-Main Uddin
    ID-201421090
    Batch-46

    Write a C++ program to find area of triangle, circle,and rectangle using function overloading.


    # include
    # include
    using namespace std;

    void area (int Redius)
    {
    cout<>Redius;
    area (Redius);
    cout<>Base>>height;
    area (Base,height);
    cout<>length>>Breadth;
    area (length,Breadth);
    getch();
    return 0;

    }

    ReplyDelete
    Replies
    1. Name-Main Uddin
      Id-201421090
      Batch-46
      # include
      # include
      using namespace std;

      void area (int Redius)
      {
      cout<<endl<<"Area of Cirle="<<3.142*Redius*Redius;
      }

      void area (int Base ,int height)
      {
      cout<<endl<<"Area of Tringle="<<0.5*Base*height;
      }
      void area (float length,float Breadth)
      {
      cout<<endl<<"Area of rectangle="<<length*Breadth;
      }

      Delete
    2. Name -Main Uddin
      id-201421090
      Batch-46
      Write a C++ program to find area of triangle, circle,and rectangle using function overloading
      Second Part--------

      int main()
      {
      int Redius,Base,height;
      float length,Breadth;
      cout<>Redius;
      area (Redius);
      cout<>Base>>height;
      area (Base,height);
      cout<>length>>Breadth;
      area (length,Breadth);
      getch();
      return 0;

      }

      Delete
  29. Batch-46th
    ID-201420406


    #include
    #include
    float area(float r)
    {
    return(3.14*r*r);
    }
    float area(float c,float b,float h)
    {
    return(b*h*c);
    }
    float area(float l,float b)
    {
    return(l*b);
    }
    void main()
    {
    float rad,base,ht;
    clrscr();
    float len,brdth;
    cout<<"\nEnter radius :";
    cin>>rad;
    cout<<"\nArea of circle :"<>base>>ht;
    cout<<"\nArea of triangle :"<>len>>brdth;
    cout<<"\nArea of rectangle :"<<area(len,brdth);
    getch();
    }

    ReplyDelete
  30. ID-201420406
    batch-46th
    #include
    #include
    float area(float r)
    {
    return(3.14*r*r);
    }
    float area(float c,float b,float h)
    {
    return(b*h*c);
    }
    float area(float l,float b)
    {
    return(l*b);
    }
    void main()
    {
    float rad,base,ht;
    clrscr();
    float len,brdth;
    cout<<"\nEnter radius :";
    cin>>rad;
    cout<<"\nArea of circle :"<>base>>ht;
    cout<<"\nArea of triangle :"<>len>>brdth;
    cout<<"\nArea of rectangle :"<<area(len,brdth);
    getch();
    }

    ReplyDelete
  31. batch-46th
    id-201420406
    #include
    #include
    void area(int r)
    {
    cout<<"area of circle="<<3.142*r*r;
    }
    Void area(int b, int h)
    {
    cout<>r;
    area(r);
    cout<>b>>h;
    area(b,h);
    cout<>L>>br;
    area(l,br);
    getch();
    return 0;
    }

    ReplyDelete
  32. Mohammad Ashraful Hasan sobuj
    CSE-46(Dip)
    ID=201420656


    #include
    using namespace std;

    const float pi=3.14;
    float area(float n,float b,float h)
    float area(float x,float y,float z)
    {
    float ar;
    ar=x*y*z;
    cout<<"The area of Triangle : "<>y>>z;
    area(0.5,y,z);

    cout<<"Enter the radius of circle :";
    cin>>n;
    area(n);


    cout<<"Enter the Lenght & width of Rectangle: ";
    cin>>l>>w;
    area(l,w);
    return 0;
    }

    ReplyDelete
  33. Mohammad Ashraful Hasan sobuj
    CSE-46(Dip)
    ID=201420656


    #include
    using namespace std;

    const float pi=3.14;
    float area(float x,float y,float z)
    {
    float ar;
    ar=x*y*z;
    cout<<"The area of Triangle : "<>y>>z;
    area(0.5,y,z);

    cout<<"Enter the radius of circle :";
    cin>>n;
    area(n);


    cout<<"Enter the Lenght & width of Rectangle: ";
    cin>>l>>w;
    area(l,w);
    return 0;
    }

    ReplyDelete
  34. using c++

    #include
    using namespace std;

    class overload
    {
    public:
    float ovrload(float r);
    double ovrload(float width, float length);
    double ovrload(double base, double height);
    };

    float overload::ovrload(float r)
    {
    float pi = 3.1416;
    return 2*pi*r;
    }

    double overload::ovrload(float width, float length)
    {
    return width*length;
    }

    double overload::ovrload(double base, double height)
    {
    int sum = 0;
    sum = 0.5*base*height;
    return sum;
    }

    int main()
    {
    float r, width, length;
    double base, heit;
    overload obj;

    cout << "Enter r for for circle --: ";
    cin >> r;
    cout << "Area of circle --: " << obj.ovrload(r) << endl;

    cout << "Enter width for rectangle --: ";
    cin >> width;
    cout << "Enter length for rectangle --: ";
    cin >> length;
    cout << "Area of rectangle --: " << obj.ovrload(width, length) << endl;

    cout << "Enter base for triangle --: ";
    cin >> base;
    cout << "Enter height for triangle --: ";
    cin >> heit;
    cout << "Area of triangle --: " << obj.ovrload(base, heit);

    return 0;
    }

    ReplyDelete

Comment Here