Question

I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate...

I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate and display the length of a right triangle hypotenuse,c, given the lengths of its adjacent sides: a and b.. (hint: a^2 + b^2 = c^2)

II. Design the C++ code for a program which will calculate and display the roots of a quadratic equation of the form ax^2 + bx + c = 0, given its coefficients, a, b, and c.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double a,b,c;
cout<<"Enter sides a and b";
cin>>a>>b;
c=(pow(a,2))+(pow(b,2));
c=sqrt(c);
cout<<"The hypoteneus is "<<c;
return c;
}

C:\Users) kunaltaneja\Documents hypo.exe Enter sides a and b3 The hypoteneus is 5 Process exited after 5.241 seconds with ret

Q2 -

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double a, b, c, d, r1,r2, realPart, imaginaryPart;

cout<<"Enter coefficients a, b and c: ";
cin>>a>>b>>c;

d = b*b-4*a*c;

  
if (d > 0)
{

r1 = (-b+sqrt(d))/(2*a);
r2 = (-b-sqrt(d))/(2*a);

cout<<"r1 = "<<r1 <<"and r2 = "<<r2;
}
else if (d == 0)
{
r1 = r2 = -b/(2*a);

cout<<"r1 = r2 = "<< r1;
}
else
{
realPart = -b/(2*a);
imaginaryPart = sqrt(-d)/(2*a);
cout<<"r1 = "<<realPart <<"+"<<imaginaryPart<<"i";
cout<<"r1 = "<<realPart <<"-"<<imaginaryPart<<"i";
}

return 0;
}   

CUsers kunaltaneja\ Documents hypo.exe Enter coefficients a b and c 2 1and 2 0.292893and r21.70711 Process exited after 3.763

Add a comment
Know the answer?
Add Answer to:
I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate...
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
  • Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c...

    Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c 0. The class contains: • The data fields a, b, and c that represent three coefficients. . An initializer for the arguments for a, b, and c. • Three getter methods for a, b, and c. • A method named get Discriminant() that returns the discriminant, which is b- 4ac The methods named getRoot 1() and getRoot 2() for returning the two roots of...

  • PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP...

    PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here    do { // program here             }while (true);    } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...

  • write a C programming code for the following prompt. please use stucture concept and test if...

    write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...

  • program in assembiy language x86 In assembly language using float point Quadratic Formula Prompt the user...

    program in assembiy language x86 In assembly language using float point Quadratic Formula Prompt the user for coefficients a, b, and c of a polynomial in the form ax²+bx +C =0. Calculate and display the real roots of the polynomial using the quadratic formula. If any root is imaginary, display an appropriate message. Your result must be calculated in floating point whenever it applies, otherwise you will NOT get any credit.

  • reword m the program into a design document diregard the m Write a C++ program that...

    reword m the program into a design document diregard the m Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula -b + b2 - 4ac 2a The value of the discriminant b2 - 4ac determines the nature of roots. If the value of the discriminant is zero, then the equation has a single...

  • use matlab and show all codes and work the question continues from this 4. Write a...

    use matlab and show all codes and work the question continues from this 4. Write a function with header (A, V - myCone (r, h), which outputs the total area A and volume of a cone with base radius r and height h. 5. Write a function - myMatrix (myvec, m, n) which creates an m-by-n matrix A, as in Problem 3, but for arbitrary values of mand n and any length of vector myvec. Hint: the function can use...

  • Using C++ For this program you are going to create a class that helps to solve...

    Using C++ For this program you are going to create a class that helps to solve the quadratic equation. The equation has the following form: ax2 + bx + c = 0 The roots of the equation are: x1 = -b + sqrt(b2 - 4 * a * c) and x2 = -b - sqrt(b2 - 4 * a * c) The phrase in the parenthesis is called the discriminant. If the value of the discriminant is positive, the equation...

  • 2. Write a program that prompts a user to enter the lengths of sides and angles...

    2. Write a program that prompts a user to enter the lengths of sides and angles for the two triangles described below. The program should calculate the length of the side of the triangle indicated below. Print the two answers to 3 decimal places onto the console screen Triangle 1 Read in the value of the angle, alpha, and the length, a, of the side indicated in the picture below. Calculate the length of the hypotenuse, c, of this right...

  • Write a C++ program to compute both roots of the quadratic equation when the user provides...

    Write a C++ program to compute both roots of the quadratic equation when the user provides the three coefficients A, B, and C. Specifically, A. Display “Your Name” B. Display “Project_2 Problem_1” C. Display “This program computes both roots of a quadratic equation” D. Display “given the coefficients A, B, and C” E. Real_1 = 0 F. Real_2 = 0 G. Imag = 0 H. D = 0 I. DD =0 J. Flag = ‘Y’ K. DO a. A =...

  • C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠...

    C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠ 0 are given by the following formula: In this formula, the term b² - 4ac is called the discriminant. If b² - 4ac = 0, then the equation has a single (repeated) root. If b² - 4ac > 0, the equation has two real roots. If b² - 4ac < 0, the equation has two complex roots. Instructions Write a program that prompts the...

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
ADVERTISEMENT