Question

Asked Feb 6, 2019

3 views

write a program to enter two sides a and b of a right triangle from keyboard calculate its area and perimeter

Step 1

Given below is the C++ program to enter the two sides of a right triangle and then calculate its area and perimeter.

Step 2

#include <iostream>

#include <cmath>

using namespace std;

double Perimeter(double a, double b); //function declaration

double Area(double a, double b); //function declaration

int main()

{

double a,b;

cout<<"Enter a b:";

cin>>a>>b; // Enter values of a and b

cout<<"Perimeter:"<<Perimeter(a,b)<<endl; //function calling

cout<<"Area:"<<Area(a,b)<<endl; //function calling

}

double Perimeter(double a, double b) //function definition

{

double c,per;

c=sqrt(pow(a,2)+pow(b,2)); //finding value of c

per=a+b+c; //calculating perimeter

return per;

}

double Area(double a, double b) //function definition

{

double area=0.5*a*b; //calculating area

return area;

}

Step 3

In the above program, both area and perimeter are calculated by entering values of a and b. To enter the values of a and b, cin function is used. To calculate perimeter of right triangle,...

Tagged in

Q: Write a program that contains 2 methods, main and printLine 1) The printLine method will do the foll...

A: Program plan: Import necessary packages.Define a class named “PrintCheck”.Define a method called “pr...

Q: Write a function “gcDivisor” that takes two positive int “k” and “m” and returns the greatest common...

A: A call is made to a function called gcd with the numerator and denominator after receiving the user ...

Q: I need to be find the result of typing: len("Grand Hotel" [:6] . rstrip()) into Python. I constantly...

A: To find the result of the statement len("Grand Hotel" [:6] . rstrip()), you need to use print() func...

Q: Create a program that will input the 3 game scores of a player and then output the level of the play...

A: Since there are no messages given in the question for the condition where the weighted average falls...

Q: (Method Overloading) Given the following methods, write down the printed output of themethod calls: ...

A: Answer with Explanation:“doSomething(5)” contains an argument integer “5” and it is called to the “d...

Q: Write a program that contains 2 methods, main and printLine (10 points)1) The printLine method will ...

A: Declare required variables ‘first’, ‘second’ and ‘times’ which is used to store first character, sec...

Q: What language is accepted by the npda M = ({q0, q1, q2}, {a, b}, {a, b, z}} q0, z, {q2}). δ(q0,a,z)=...

A: The given npda is M = ({q0, q1, q2}, {a, b}, {a, b, z}} q0, z, {q2}) with transition functions asδ(q...

Q: Write two scnr.nextInt statements to get the input values into birthMonth and birthYear.Then write a...

A: Given below is the program to get input values for month and year and write the output value as a mo...

Q: Develop the ‘Shape’ application such that: Implement an array of objects of various types (all SIX ...

A: Program plan:Define a class called “ShapeTest”.Define a “main()” method.Create an array of six shape...