Question

In: Computer Science

Write a program that prompts the user for the length of one side of a triangle...

Write a program that prompts the user for the length of one side of a triangle and the sizes of the two adjacent angles in degrees and then displays the length of the two other sides and the size of the third angle.

Solutions

Expert Solution

CODE in C++:-

#include <iostream>
#include <cmath>//sine function is defined in this library.

using namespace std;

#define Pi 3.14159// it is required because angle to sin() function must be in radian

int main()
{
    //since , question doesn't mention the data types of length and degrees i'll use double type
    double length;
    double angle1, angle2;
   cout<<"Enter the length of a side of triangle: ";
    cin>>length;

    cout<<"Enter the first angle of two adjacent angles: ";
    cin>>angle1;


    cout<<"Enter the second angle of two adjacent angles: ";
    cin>>angle2;

    //third angle = 180 - (sum of first two angles
    double angle3 = (180.0 - (angle1+angle2));
    cout<<"\nThe size of third angle is "<<angle3;
    /*now to find the length of other two sides we'll use sine rule defined in trigonometry
    assume that angles provided as input are angles on side given.
    let unknown sides be a and b.
    applying sine rule
    sin(180-(angle1+angle2))/ length = sin(angle1)/a = sin(angle2)/b
    assuming a is side opposite to angle1 and b is opposite to angle2.
    */
    double a , b;//second and third side
    double multipliedToAngles = Pi/ 180.0;
    //the value inside sine() function must be in radians . so,angles are converted into radians from degrees
    angle1 = multipliedToAngles * angle1;
    angle2 = multipliedToAngles * angle2;
    angle3 = multipliedToAngles * angle3;
    a = (((sin(angle1))*length)/(sin(angle3)));
    b = (((sin(angle2))*length)/(sin(angle3)));
    //displaying other sides
    cout<<"\nThe second side length of triangle is "<<a;
    cout<<"\nThe third side length of triangle is "<<b;

    return 0;
}


output:-


Related Solutions

C++ Question: write a program that prompts the user for the length and width of a...
C++ Question: write a program that prompts the user for the length and width of a rectangle in inches.  The program then uses functions to compute the perimeter and area of the rectangle and to convert those to meters and square meters respectively. Sample output from one instance of the program is shown below: ```html Welcome to the Foot-To-Meter Rectangle Calculator ================================================= Enter the rectangle length in feet: 2 Enter the rectangle width in feet: 3 The rectangle dimensions are: 0.61...
Write a program that prompts for the lengths of the sides of a triangle and reports...
Write a program that prompts for the lengths of the sides of a triangle and reports the three angles. Make sure you have a good introduction stating what the program does when it is run, and a helpful prompt for the user when asking for input: i.e. Here is the generated output from a sample program: This program computes the angles of a triangle given the lengths of the sides. What is the length of side 1? <wait for user...
Write a program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
(PYTHON) Write aprogram that prompts user to enter three sides of a triangle....
(PYTHON) Write a program that prompts user to enter three sides of a triangle. The program should determine if the three sides can form a triangle. If the three sides can form a triangle, then determine the type of the triangle.There are three types of triangles: Equilateral triangle (all 3 sides are equal) Isosceles triangle (two sides are equal, the third side is of a different length) Scalene triangle (all 3 sides are of different lengths)   The program should...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT