0% found this document useful (0 votes)
17 views

Sandhya Oops - CPP

Uploaded by

ahil12345678901
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Sandhya Oops - CPP

Uploaded by

ahil12345678901
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Sandhya BCA(B)2323380

29. Write a c++ program to compute area of right


angle triangle, equilateral triangle, isosceles triangle
using function overloading concept.
Input: -
#include <iostream>
#include <cmath>
using namespace std;
class Triangle {
public:
double area(double base, double height) {
return 0.5 * base * height; }
double area(double side) {
return (sqrt(3) / 4) * side * side;}
double area(double base, double side1, double
side2) {
double semi_perimeter = (base + side1 + side2) /
2;
return sqrt(semi_perimeter * (semi_perimeter -
base) * (semi_perimeter - side1) * (semi_perimeter -
side2));}};
int main() {
Sandhya BCA(B)2323380

Triangle triangle;
double base, height, side1, side2;
cout << "Enter base and height of the right-angle
triangle: ";
cin >> base >> height; cout << "Area of the right-
angle triangle: " << triangle.area(base, height) <<
endl;
cout << "Enter the side of the equilateral triangle: ";
cin >> side1; cout << "Area of the equilateral
triangle: " << triangle.area(side1) << endl;
cout << "Enter the base and two equal sides of the
isosceles triangle: ";
cin >> base >> side1 >> side2; cout << "Area of the
isosceles triangle: " <<
triangle.area(base, side1, side2) << endl;
return 0;
}
Sandhya BCA(B)2323380

Output: -
Enter base and height of the right-angle triangle:
56,66
Area of the right-angle triangle: 1848
Enter the side of the equilateral triangle: 45
Area of the equilateral triangle: 876.851
Enter the base and two equal sides of the
isosceles triangle: 56
77
90
Area of the isosceles triangle: 2142.46

You might also like