Question
My professor gave us this assignment for c++ and I am trying to figure out what I have to do to get the correct result.
My professor gave us this assignment for c++ and I am trying to figure out what I have to do to get the correct result. This is the description of the assignment our professor gave us:
Suppose that you have been hired as an Undergraduate Research Assistant to help Professor Cynthia Garcia. She will need to add the sine of an angle to the cosine of another angle in numerous occasions so she asks you to write a program that will get the two angles and calculate the addition of the sine of the first one with the cosine of the second one. The angles will be expressed in degrees. She needs the result of the addition with three decimal digits. In order to learn how to use the functions to solve this problem use www.cplusplus.com All the values that the program will need to work with must be double precision real numbers. Assume the value of PI to be 3.141592.
Test and compare your solution with mine for different values of alpha and beta. Use the following values for both alpha and beta to test your program and ensure it passes the tests:
1) 33.0
2) 66.45
3) 87.33
Inputting 33.0 to alpha and 66.75 to beta will give us a total of 0.945.
Below is what I have so far. The comments are tasks we are given, but I am having trouble figuring out how to do them.
#include
using namespace std;
// Ignore this; it's a little function used for making tests inline void _test(const char* expression, const char* file, int line) { cerr << "test(" << expression << ") failed in file " << file; cerr << ", line " << line << "." << endl << endl; } // This goes along with the above function...don't worry about it #define test(EXPRESSION) ((EXPRESSION) ? (void)0 : _test(#EXPRESSION, __FILE__, __LINE__))
int main( ) { const double PI = 3.141592; // Declares constant PI:3.141592
string name; // Declares variable name that holds text
double alpha, beta, sina, cosb, total; // Declares variables alpha,beta,sina,cosb, and total that hold double precision real numbers
cout << "Please enter your full name: " << endl; // Prompts the user to "Please enter your full name: "
getline(cin, name); // Reads the full name from keyboard and stores it in the corresponding variable
cout << "Please enter angle alpha: " << endl; // Prompts the user to "Please enter angle alpha: "
cin >> alpha; // Reads the value from the keyboard and stores it in the corresponding variable
cout << "Please enter angle beta: "; // Prompts the user to "Please enter angle beta: "
cin >> beta; // Reads the value from the keyboard and stores it in the corresponding variable
cout << "Thanks " << name << endl; // Displays "Thanks ", name
// Calculates the sine of alpha and the cosine of beta, and stores the results in the corresponding variables
// Rounds off the sine of alpha and the cosine of beta to the third decimal digit
// Calculates the total as the addition of the sine and the cosine and stores it in the corresponding variable
// Formats the output to display the values in fixed format with three decimal digits
// Prints a message like the one below: // Using 23 columns displays "sine of alpha: ", using 6 columns displays sina
// Using 23 columns displays "+ cosine of beta: " , using 6 columns displays cosb
// Using 30 columns displays "-------"
// Using 23 columns displays "total: ", using 6 columns displays total system("pause");
// Do NOT remove or modify the following statements cout << endl << "Testing your solution" << endl << endl; test(typeid(name) == typeid(string)); // Incorrect data type used for name test(typeid(alpha) == typeid(1.)); // Incorrect data type used for alpha test(typeid(beta) == typeid(1.)); // Incorrect data type used for beta test(typeid(sina) == typeid(1.)); // Incorrect data type used for sina test(typeid(cosb) == typeid(1.)); // Incorrect data type used for cosb test(typeid(total) == typeid(1.)); // Incorrect data type used for total if (alpha == 33. && beta == 33.) test(fabs(total - 1.384) < 0.0001); // Incorrect rounding if (alpha == 66.45 && beta == 66.45) test(fabs(total - 1.317) < 0.0001); // Incorrect rounding if (alpha == 87.33 && beta == 87.33) test(fabs(total - 1.046) < 0.0001); // Incorrect rounding system("pause"); return 0; // Successful completion }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started