**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.
TRIG: the trigonometric calculator
2. The program shall display a message prompting the user to enter input from the keyboard.
Please input request (h-help, q-quit):
3. The following help message shall be displayed whenever the user types the letter h at the input prompt.
The input format is a single line of letters and numbers comprising the
following fields:
These fields must be input in the order shown above, where
is a set of letters, and the others are single numbers defining
the range of computation.
The field consists of zero or more of the letters from the set
, which indicate respectively,
(1) The desired trig functions: sin, tan, cos.
(2) Whether to use degrees or radians for input parameters.
(3) Whether to quit the program.
Example input: scr 0 2.3 3
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:
Error: Illegal input!
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.
Degrees Radians Sin Cos Tan
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
TRIG: the trigonometric calculator
Please input request (h-help, q-quit): scr 0 2.3 3
Degrees Radians Sin Cos
0.000 0.000 0.000 1.000
32.945 0.575 0.544 0.839
65.890 1.150 0.913 0.408
98.835 1.725 0.988 -0.154
131.780 2.300 0.746 -0.666
Please input request (h-help, q-quit): q
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\n1. Right angle triangle" << endl;
cin >> menu;
switch(menu){
case 1:
cout << "If you do not know the value use 0.\n\n";
valuea = decision("Do you know side A?\n");
valueb = decision("Do you know side B?\n");
valuec = decision("Do you know side C?\n");
valueao = decision("Do you know angle A?\n");
valuebo = decision("Do you know angle B?\n");
sides(valuea, valueb, valuec, valueao, valuebo);
cout << "\n\nTriangle calculated:\n\n";
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;
}
}
**This is for the C Language. Trigonometric Calculator Specification You are required to write a program...
this is a C++ program!
You will write a program that performs the following tasks for a simple mathematical calculator: (1) Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file...
ENGR 40 PROGRAMMING ASSIGNMENT MENU-DRIVEN CALCULATOR PROGRAM Use a switch statement to build a menu-driven calculator. Your program should ask the user to choose from a list of ten possible functions (square root, square, natural log, common log, e'x yx, 1/x, sin(x), cos(x), and tan(x). Each choice will correspond to an integer -example: (1) square root, (2) square, etec. Once the person has input a function choice then a switch statement will control the flow of the program- ie. the program...
a.) Write a C++ program that calculates the value of the series
sin x and cos x, sin 2x or cos 2x where the user enters the value
of x (in degrees) and n the number of terms in the series. For
example, if n= 5, the program should calculate the sum of 5 terms
in the series for a given values of x. The program should use
switch statements to determine the choice sin x AND cos x, sin...
2) Write a C++ program that uses a class called “Degree” to obtain the trigonometric values for angles given in degrees. This is because the trigonometric functions defined in the library file <cmath> are applied to radian angles only. Use the constant DEG2RAD = 0.017453 for conversion from degrees to radians. This class must include a constructor, destructor, and the following functions: a. void set_value(double) b. double get_value() c. double get_sine() d. double get_cosine() e. double get_tangent() f. void read_value()...
Description Write C++ code that correctly input and output information. (Moving data to and from the screen and to and from text files. Also inputting predefined functions, etc., from included libraries.) Problem Description Consider a data file that has geometrical angle values in degrees. Angle values may be on one line, several lines, or any other white space separated format. Fig. 1 below shows one possible format, but other formats are possible. 12.9 100.8 270.5 300.6 120.8 There are no...
Consider the following C++ program. It prints a small table containing sin and cos values from 0 to 360 degrees. #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int step = 20; cout << setw(10) << "degrees" << setw(10) << "cos" << setw(10) << "sin" << endl; for (int degrees = 0; degrees <= 360; degrees += step) { cout << setw(10) << degrees << setw(10) << setprecision(5) << fixed << cos(degrees) << setw(10) << setprecision(5)...
C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...
I need a simple program in C language that
calculates the values of Sine, Cosine, and Tangent of values given
in degrees. It has to be a range of values between 0 and
360(integer values). The output should be a table of values showing
Sin, Cos and Tan values. The complete computation and printing of
the table must be done inside a function. The function also returns
to the main program with 3 output arguments: It also needs to show...
Program Description Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earth’s mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed: Program must have header comments stating the author of the Program, date, and Program Description. Include the math.h header file Initialize a...
In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...