Concept explainers
The area of an arbitrary triangle can be computed using the formula area=s(s–a)(s–b)(s–c)
where a, b, and c are the lengths of the sides, and s is the semiperimeter. s=(a+b+c)/2
Write a void function that computes the area and perimeter (not the semiperimeter) of a triangle based on the length of the sides. The function should use five parameters—three value parameters that provide the lengths of the edges and two reference parameters that store the computed area and perimeter. Make your function robust. Note that not all combinations of a, b, and c produce a triangle. Your function should produce correct results for legal data and reasonable results for illegal combinations.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Java How To Program (Early Objects)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Introduction To Programming Using Visual Basic (11th Edition)
Database Concepts (8th Edition)
Modern Database Management (12th Edition)
- (Numerical) Heron’s formula for the area, A, of a triangle with sides of length a, b, and c is A=s(sa)(sb)(sc) where s=(a+b+c)2 Write, test, and execute a function that accepts the values of a, b, and c as parameters from a calling function, and then calculates the values of sand[s(sa)(sb)(sc)]. If this quantity is positive, the function calculates A. If the quantity is negative, a, b, and c do not form a triangle, and the function should set A=1. The value of A should be returned by the function.arrow_forward(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forwardUSE C++programming languagearrow_forward
- The following formula can be used to determine the distance an object falls due togravity in a specific time period:d =112 gt2The variables in the formula are as follows:• d is the distance in meters,• g is 9.8,• and tis the time in seconds that the object has been falling.Write a function named fall i ngDi stance that accepts an object's falling time (in seconds)as an argument. The function should return the distance, in meters, that the object hasfallen during that time interval. Write a program that demonstrates the function by callingit in a loop that passes the values 1 through 10 as arguments and displays the return value.arrow_forwardCode in Pythonarrow_forwardThe area of an arbitrary triangle can be computed using the formulaarea = √(s(s–a)(s–b)(s–c))where the square root is applied to the entire product and where a, b, and c are the lengths of the sides, and s is thesemiperimeter of the triangle given by the formula:s = (a + b + c)/2 Write a void function named triangle that computes the area and perimeter (as well as the semiperimeter (which will be used to compute the area)of a triangle based on the length of the sides. The function should use five parameters and may call other functions.Make your function robust. Note that not all combinations of a, b, and c produce a triangle. Your function should produce correct resultsfor legal data and reasonable results for illegal combinations. Include in your submission a driver that repeatedly reads in 3 positive numbers thatare the sides of a triangle, and each time print out the sides and the area and perimeter calculated by the triangle function. Your program shouldterminate when the…arrow_forward
- Programming Language : R programming (R Studio) A twin prime is a prime that has a prime gap of two. Sometimes the term twin prime isused for a pair of twin primes. For example, the five twin prime pairs are (3, 5), (5, 7),(11, 13), (17, 19) and (29, 31). Write a function that returns the number of all twin primepairs between 1 and a given number n.arrow_forwardThe distance between two points pA (XA,YA) and pB (XRYB) is calculated as follows 2 Distance = (XA– XB) +(YA–YB) Write a function that accepts as parameters the four coordinates (float values) of two points pA(XA,YA) and pB (XB,YB) and returns as a result the distance between the two given points. In the function main: 1) Prompt the user to enter from the keyboard unknown number of quadruples (four float numbers), where the first two numbers represent the coordinates of the first point and the last two numbers represent the coordinates of the second point. 2) Calculate the distance between the two points by calling the above -developed function. 3) Print the coordinates of the two points and the distance between them separated by tab at the beginning of a new line. All values must be printed with 2 decimal places. 4) Repeat the previous steps until the user enters control+Z.arrow_forwardTrue or falsearrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning