Trigonometry Calculations Assignment

May 3, 2013 at 9:34pm
Hello ya’ll! I need your help to help me with my assignment. Just like the previous assignment, I have an extremely difficult time completing all of my HW so far because, 1, the instructor is horrible, and 2, I’m actually in a high level Computer Science class since Computer Science l states’ specially it’s an introduction course to Computer Science. I was actually supposed to enroll in Exploring Computer Science first but I did not see that as an option until it was already too late. Anyways, I hoping if you can figure this out one for me and I’ll use the same formula for my codes and won’t use the one’s I have not learned yet in class. By the way, I have never taking Trigonometry so I have no idea where to start.

For this assignment, you will be calculating the hypotenuse and standard trigonometric values (sine, cosine, tangent), and cotangent for a right triangle of arbitrary size. Your program will start by asking the user for the lengths of the adjacent and opposite sides of a right triangle. Then your program will do the calculations for the items listed above, and display the results. The calculation to find the hypotenuse is:

hypotenuse 2 = opposite 2 + adjacent 2 , or hypotenuse = sqrt(opposite 2 + adjacent 2)

You can use the <cmath> library to get access to the pow() and sqrt() functions.

The calculation for sine, cosine, tangent, and cotangent are as follows:



http://postimg.org/image/vxw5ln2hh/



I want your program to ask if the user would like to do another calculation. If the user says “yes,” then ask them for the adjacent and opposite sides of a triangle again, and do the calculations again. You can put the relevant code inside of a while or do-while loop to do this.


Sample Output

Welcome to Rob's trigonometry calculator.
Please tell me the lengths of the adjacent and opposite sides of a right triangle.
Adjacent side length: 1.2
Opposite side length: 3.4
Based on an adjacent side of 1.2 and an opposite side of 3.4,
the hypotenuse has length 3.60555.
The sine of the angle is 0.94299.
The cosine of the angle is 0.33282.
The tangent of the angle is 2.83333.
The cotangent of the angle is 0.352941.

Would you like to do another calculation? (Y or N): Y
Adjacent side length: 2.5
Opposite side length: 1.7
Based on an adjacent side of 2.5 and an opposite side of 1.7,
the hypotenuse has length 3.02324.
The sine of the angle is 0.56231.
The cosine of the angle is 0.826927.
The tangent of the angle is 0.68.
The cotangent of the angle is 1.47059.

Would you like to do another calculation? (Y or N): N

Design Considerations
You will need the <cmath> library to have access to pow() and sqrt(). Please check for division by zero; don’t rely on the compiler to catch a divide by zero error. You will lose points on the assignment if your program allows division by zero, so check for zero before doing division. Follow the style guide for all of your relevant code items, including proper indentation, variable names, etc. Do not use literal values in your calculations; use constant globals instead. For example:
const double DEGREES_PER_RADIAN = 57.296;
Last edited on May 4, 2013 at 7:46pm
May 3, 2013 at 9:41pm
Your teacher does know that the cmath library includes arctan, correct? There's no need to use the Taylor series- it's given by default in cmath. As for your program itself, just have the name of the calculator be outside of the while() loop, and everything else inside. Most of the program comes from calculations, which you just write as you would any other mathematical calculations outside of a computer (though using sqrt() for square root, and pow() for power). At the end, it should have an if statement to ask for the yes or no. If yes, do nothing. If no, break. If neither, initiate another while loop.
May 3, 2013 at 9:43pm
What exactly is your problem ?
Do you not understand the assignment or do you not know how to do it in C/C++ ?
May 4, 2013 at 6:31pm
I don't really understand the assignment, but even if I do understand, I don't understand how to input anything in the Visual Studio; don't know where to start.
May 4, 2013 at 6:46pm
I may be missing the problem here, but it sounds like you need to start with the "Hello World" program, in order to just learn the basics of how to edit, compile and run a program.

http://www.cplusplus.com/doc/tutorial/program_structure/
I can't offer any help with Visual Studio as I don't use that myself.
May 4, 2013 at 6:52pm
I've done the Hello World assignment weeks ago. Sadly, it was the only assignment I actually done with no help. Every other one, I bugged and annoyed the instructor with questions.
May 5, 2013 at 11:28am
OK then, I misunderstood. I thought perhaps it was Visual Studio which was getting in the way.

Well then in this case I would start simple and gradually build up to a complete solution.
Begin by getting the two inputs from the user,

Output: Welcome to Rob's trigonometry calculator.
Output: Please tell me the lengths of the adjacent and opposite sides of a right triangle.
Output: Adjacent side length: Input: 1.2
Output: Opposite side length: Input: 3.4

Since you already completed the "Hello World" program, the output is something you already know how to do. That just leaves the two inputs.

One step at a time, each individual step here is not hard, approach it this way and work towards the next stage. Feel free to ask more questions as you go along, and post the code you've written so far.
Topic archived. No new replies allowed.