Question

In: Computer Science

(C++) Write a program that prompts the user for the length of one side of a...

(C++) 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:-

#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

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.
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 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...
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...
Write a program in C that prompts the user for a number of seconds and then...
Write a program in C that prompts the user for a number of seconds and then converts it to h:m:s format. Example: 5000 seconds should display as 1:23:20 (1 hour, 23 minutes, 20 seconds.) Test with several values between about 100 seconds and 10,000 seconds. use unint and remainders for this and keep it as simple as possible.
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
C++ Program: Write a program that prompts the user for two numbers and stores them in...
C++ Program: Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT