Monday, 25 January 2016

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

#include <iostream>

using namespace std;

class Shape{
    public:
    float findarea(float radii){
        return(3.14*(radii*radii));
    }
   
    int findarea(int side){
        return(side*side);
    }
   
    int findarea(int base, int height){
        return((base*height)/2);
    }
};

int main(){
int ch;
float r;
int b, h, s1;

cout << "Select and Find Area" << "\n1:CIRCLE 2:SQUARE 3:TRIANGLE " << endl;
cout << "Enter choice :";
cin >> ch;

Shape S;

if(ch==1){
    cout <<"Enter radius: ";
    cin >> r;
    cout << "Area of circle of raduis " << r << " is " << S.findarea(r) << endl;
}else if(ch==2){
    cout <<"Enter the value of Side ";
    cin >> s1;
    cout << "Area of square with side " << s1 << " is " << S.findarea(s1) << endl;
}else if(ch==3){
    cout <<"Enter base and height: ";
    cin >> b >> h;
    cout << "Area of triangle with base " << b << " and height " << h << " is " << S.findarea(b, h) << endl;
}else{
    cout << "Invalid input ";
}
   
return 0;
}


No comments:

Post a Comment