Question

In: Computer Science

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.

Solutions

Expert Solution

1. C++ program for calculating the length of the hypotenuse of a right angled triangle:-

Formula used: -   c = sqrt(a^2 + b^2)

#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main() {
    double a,b,c;
   printf("Enter the value of side A:-   \n");
   scanf("%lf",&a);
   printf("Enter the value of sideB:-   \n");
   scanf("%lf",&b);
   c = sqrt(a*a + b*b);
   printf("The length of the Hypotenuse of the right angled triangle is:- %lf",c);
   return 0;
}

Output:-

Enter the value of side A:-   3
Enter the value of sideB:-   4
The length of the Hypotenuse of the right angled triangle is:- 5

2. C++ program to calculate the roots of the quadratic equation :-

Formula Used :-    x = (-b + sqrt(b^2 - 4*a*c))/2*a       y = (-b - sqrt(b^2 - 4*a*c))/2*a

#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main() {
    double a,b,c;
    double x,y;
   printf("Enter the value of coefficient a:-   \n");
   scanf("%lf",&a);
   printf("Enter the value of coefficient b:-   \n");
   scanf("%lf",&b);
   printf("Enter the value of coefficient c:-   \n");
   scanf("%lf",&c);
   x = (-b + sqrt(b*b - 4*a*c))/(2*a);
   y = (-b - sqrt(b*b - 4*a*c))/(2*a);
   printf("The values of the roots x and y of the quadratic equation are:- %lf and    %lf",x,y);
   return 0;
}

Output:-

Enter the value of coefficient a:-   4
Enter the value of coefficient b:-   4
Enter the value of coefficient c:-   1
The values of the roots x and y of the quadratic equation are:- -0.500000 and    -0.500000


Related Solutions

(IN C) Program Question 2: Write a program that solves for c in the Pythagorean Theorem:...
(IN C) Program Question 2: Write a program that solves for c in the Pythagorean Theorem: a2 + b2 = c2 The user will enter values for a and b, and you will calculate c. All of this code will go in just one source file.
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
Need the correct line of code for c program to solve  this equation . i is a...
Need the correct line of code for c program to solve  this equation . i is a value that the program all ready calculates from user imput. t i = (x*1000)+(y*500)+(z*250
Please do not use vectors or any previously posted code Write a C++ program which reads...
Please do not use vectors or any previously posted code Write a C++ program which reads in a list of process names and integer times from stdin/cin and simulates round-robin CPU scheduling on the list. The input is a list of lines each consisting of a process name and an integer time, e.g. ProcessA 4 ProcessB 10 Read line by line until an end-of-transmission (^d) is encountered. You should read the list and represent it in a linked list data...
---------------------------------------------------------------------------------------------------------------- C++ //code a program for the following the given Instruction. Geometry Calculator 1. Calculate the...
---------------------------------------------------------------------------------------------------------------- C++ //code a program for the following the given Instruction. Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use 3.14159 for pi. #03   If the user enters 2, the program should ask for the length and width of...
IN C++ LANGUAGE PLEASE::: Design and implement a program (name it Rectangle) to calculate and display...
IN C++ LANGUAGE PLEASE::: Design and implement a program (name it Rectangle) to calculate and display the area and perimeter of a rectangle with width = 4 and height = 8.
Design and implement a C++ program with functions to calculate the pre-tax charge: If the customer...
Design and implement a C++ program with functions to calculate the pre-tax charge: If the customer subscribes to a phone plan called Plan200, then he is charged $5 for the first 200 minutes. For each additional minutes, the customer will be charged $0.10. If the customer subscribes to a phone plan called Max20, then he is charged $0.05 for each minute up to $20. (I.e., the customer never needs to pay more than $20.) If the customer is not subscribed...
In C++ Design a program to calculate the stock purchasing and selling transactions. 1. ask the...
In C++ Design a program to calculate the stock purchasing and selling transactions. 1. ask the user to enter the name of the stock purchased, the number of share purchased, and the price per share purchased 2. assume the buyer pays 2% of the amount he paid for the stock purchase as broker commission 3. assume that the buyer sold all stocks. Ask the user to enter the price per share sold. 4. assume the buyer will pay another 2%...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT