Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**This is for the C Language. Trigonometric Calculator Specification You are req

ID: 3885603 • Letter: #

Question

**This is for the C Language.

Trigonometric Calculator

Specification

You are required to write a program that calculates and displays values of the trigonometric functions sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the following specification.

1. When the program is run, it is to display a short welcome message.

2. The program shall display a message prompting the user to enter input from the keyboard.

3. The following help message shall be displayed whenever the user types the letter h at the input prompt.

4. The program shall exit if the user types the letter q at the input prompt.

5. The user may enter a single line of input composed of four fields separated by whitespace,

where the angle brackets < > indicate particular information fields as described below.

6. The field shall be zero or more of the letters stcdr, indicating sine (s), tangent (t), cosine (c), degrees (d), or radians (r) to indicate trigonometric function types and input units.

7. The field shall be followed by three numerical values that indicate, in order, the starting value for the calculations, the final value for the calculations and the number of intermediate rows in the table. The first two values are floating point, the third is an integer.

8. The following defaults shall be implemented when all or part of the field is missing:

(a) If no function type is specified, all 3 trigonometric functions shall be displayed.

(b) If no unit type is specified, units of entry shall default to degrees.

9. The program shall respond to all inputs in a case insensitive manner. i.e. any letters are valid in both upper and lower case.

10. The program shall validate user input, and recover gracefully from illegal input. Since a user might enter any arbitrary string of characters, many different errors are possible, including:

Specifying both d and r in the field.

Entering invalid letters in the field.

Entering letters or symbols instead of numbers in any of the last three fields.

Failing to enter exactly three numerical values after the field.

Entering a negative or non-integer value for the number of intermediate rows.

11. On detection of illegal input, the following error message shall be displayed:

12. The results shall be displayed in a tabular format, with the first column containing the angle values in degrees, the second column containing the angle values in radians and the next columns containing the values of the requested trigonometric functions. The values in each row shall be space delimited, with columns 10 characters wide and right justified.
Values in the table shall be displayed to 3 decimal places.
Undefined values shall be represented with the string "N/A".

13. The first row of the table shall display headings describing the contents of the columns.

The headings for degrees and radians shall always be shown, but those for sin, cos and tan are only displayed if the functions are selected. There shall be a blank line after the header row.

14. After displaying the tabular output or an error message, the program shall return to the input prompt (see Item 2 above).

Example Output

Explanation / Answer

Here is a code for above scenario:

#include <stdio.h>

#include <string>

#include <iostream>

#include <cmath>

#include <algorithm>

#include <fstream>

using namespace std;

void welcome();

float decision(string);

float sides(float &, float &, float &, float &, float &);

int main(int argc, char *argv[])

{

welcome();

  return 0;

}

void welcome(){

int menu;

float valuea;

float valueb;

float valuec;

float valueao;

float valuebo;

float valueco;

cout << "Trig Calculator" << endl << endl;

cout << "Select problem type 1. Right angle triangle" << endl;

cin >> menu;

switch(menu){

case 1:

cout << "If you do not know the value use 0. ";

valuea = decision("Do you know side A? ");

valueb = decision("Do you know side B? ");

valuec = decision("Do you know side C? ");

valueao = decision("Do you know angle A? ");

valuebo = decision("Do you know angle B? ");

sides(valuea, valueb, valuec, valueao, valuebo);

cout << " Triangle calculated: ";

cout << "Side A: " << valuea << endl;

cout << "Side B: " << valueb << endl;

cout << "Side C: " << valuec << endl;

cout << "Angle A: " << valueao << endl;

cout << "Angle B: " << valuebo << endl << endl;

welcome();

}

}

float decision(string question){

float value;

float radian = 3.1415/180;

cout << question;

cin >> value;

return value;

}

float sides(float &a, float &b, float &c, float &ao, float &bo){

float radian = 3.1415/180;

if(a !=0 && b!=0 && c==0){

c = sqrt(a * a + b * b);

}

if(a !=0 && c!=0 && b==0){

b = sqrt(c * c - a * a);

}

if(a ==0 && c!=0 && b!=0){

a = sqrt(c * c - b * b);

}

//TAN with side A

if(a!= 0 && b==0 && c==0){

if(ao !=0){

b = a/tan(ao*radian);

if(bo == 0){

bo = 90-ao;

}

}

if(bo !=0){

b = a*tan(bo*radian);

if(ao == 0){

ao = 90-bo;

}

}

c = sqrt((a*a)+(b*b));

}

//tan with sideB

if(a == 0 && b!=0 && c==0){

if(ao !=0){

a = b*tan(bo*radian);

if(bo == 0){

bo = 90-ao;

}

}

if(bo !=0){

a = b/tan(bo*radian);

if(ao == 0){

ao = 90-bo;

}

}

c = sqrt((a*a)+(b*b));

}

//sin with sideC

if(a == 0 && b==0 && c!=0){

if(ao !=0){

a = c*sin(ao*radian);

if(bo == 0){

bo = 90-ao;

}

}

if(bo !=0){

a = c*cos(bo*radian);

if(ao == 0){

ao = 90-bo;

}

}

b = sqrt((c*c)+(a*a));

}

if(ao == 0 && bo ==0){

ao = atan(a/b)*180/3.141592654;

bo = 90 - ao;

}

}