Question

Heron's Formula for the area of a triangle with si Please help c++
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

/*method to calculate area of the triangle */
double area(double a,double b,double c){
double s=(a+b+c)/2; /*calculating s*/
/* calculating area */
double areaTriangle=s*(s-a)*(s-b)*(s-c);
return areaTriangle;/* returning area to main */
}
int main()
{double a,b,c;
/* Prompting user to enter 3 sides of the triangle */
cout << "Enter 1 side of the triangle : " << endl;
cin>>a;
cout << "Enter 2 side of the triangle : " << endl;
cin>>b;
cout << "Enter 3 side of the triangle : " << endl;
cin>>c;
/* calling area method and storing the returned result into variable areaTriangle */
double areaTriangle=area(a,b,c);
/* printing area */
cout<<"The area of a triangle with sides "<<a<<","<<b<<" and "<<c<<" is "<<areaTriangle<<endl;
return 0;
}

/*******OUTPUT**********
Enter 1 side of the triangle :
3   
Enter 2 side of the triangle :
4   
Enter 3 side of the triangle :
5   
The area of a triangle with sides 3,4 and 5 is 36   
*******OUTPUT************/

/* Note: Please ask in case of any doubt,thanks */

Add a comment
Know the answer?
Add Answer to:
Please help c++ Heron's Formula for the area of a triangle with sides a, b and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 10. Use Heron's formula to calculate the area of a triangle. In below formula, a, b,...

    10. Use Heron's formula to calculate the area of a triangle. In below formula, a, b, and c are the length of 3 sides of a triangle: s (a+b+c]/2 A Vs(s-a) (s-b) (s- e) Write a program to calculate area of triangle. Input a, b, e from console and display area.

  • c++ 17 please help!! A triangle can be of three types-one in which all the sides...

    c++ 17 please help!! A triangle can be of three types-one in which all the sides are equal, or one in which only two sides are equal, or one in which all the three sides are unequal. You are assigned to write a program that allows the user to enter the three sides of a triangle. The program should use three double variables to store the three sides of the triangle. The program should also be able to print the...

  • /4 Question An area of square, drea ofa rectangle and triangle can be calculated by using...

    /4 Question An area of square, drea ofa rectangle and triangle can be calculated by using the given formula: sqareaa (renww value from the functioi area is reciabgle-(retrn valwe from the function is area int) ceouatre -D-(return value fromtheneion e s double t and s s formula must be use when the values for the sides of the triangle are whether you want to calculate the area of square or a. b and c are the sides of the triangle...

  • Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths...

    Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths of its sides using Heron's Formula. Here is an outline: Get the three side lengths from the user (which might have decimal values): a, b, c. Check to ensure that the sides are valid for a triangle. Importantly, the sum of the lengths of any two sides must be larger than the length of the third side (you must check all three sides this...

  • In Java, write a class for a Triangle Object that contains, Private instance variables: - three...

    In Java, write a class for a Triangle Object that contains, Private instance variables: - three doubles: a,b,c, representing the three sides of the Triangle - constructor with three double as args, which are put into three instances variables Public Instance Methods: - getPerimeter: computes the perimeter of the triangle(the sum of the three sides), returns a double - getArea: computes the area of the triangle using Heron's formula: Area = (s*(s-a)*(s-b)*(s-c))^0.5, where s = 0.5*(the triangle's perimeter), returns a...

  • (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore,...

    (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore, your class will have THREE private member variables → side1, side2 and side3. Use the double data type to represent the triangle sides. In addition, please provide public methods that perform the following FIVE tasks: ▪ An input method that obtains the appropriate values for the three sides from the user. While entering the values of the three sides, please remember the triangle property that...

  • hello please i need help ASAP QUICKLY Write down a complete C++ program that will use...

    hello please i need help ASAP QUICKLY Write down a complete C++ program that will use the following functions related with a triangle; a) a function that will let the user to input the and to return the sizes of the three sides, let say a, b, c. b) a function that will calculate and return the area of the triangle; Area=(1/2)(a+b+c) c) a function that will print the sizes of the triangle and its area on the screen. Then...

  • ) 8. Suppose a triangle is constructed where two sides have fixed length a and b, but the third side has variable length x You can imagine there is a pivot point where the sides of fixed length a and...

    ) 8. Suppose a triangle is constructed where two sides have fixed length a and b, but the third side has variable length x You can imagine there is a pivot point where the sides of fixed length a and b meet, forming an angle of θ. By changing the angle θ, the opposite side will either stretch or contract (a) Let K(x)- Vs(s - a)(s -b)(s - x), where s is the semiperimeter of the triangle. Accord ing to...

  • MUST BE WRITTEN IN C++ All user input values will be entered by the user from...

    MUST BE WRITTEN IN C++ All user input values will be entered by the user from prompts in the main program. YOU MAY NOT USE GLOBAL VARIABLES in place of sending and returning data to and from the functions. Create a main program to call these 3 functions (5) first function will be a void function it will called from main and will display your name and the assignment, declare constants and use them inside the function; no variables will...

  • 1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the are...

    1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the area of a triangle and counts total number of areas program has computed Program should have two functions sfun(): sfun receives the values of a, b and c then computes and returns the value ofs as areafun 0: areafun receives the value of s and computes and return the area of a triangle to main program using below formulae...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT