
Trigonometry Calculator
As part of an assignment, I had to create a trigonometry calculator using C++ within Visual Studio.
The code starts out with a main menu, and the user is gradually split down paths until they get the answer to the question they want, an option I much rather preferred. I could have either given the user a large number of questions at the start, which would enable them to get to their choice quickly but with more difficulty, or ‘funnel’ them down a series of questions which would get them to the answer of their question far easier. The main menu presents the user with three options; they can either work out the angles and sides, get help, or exit the program. Selecting help will load up the “help” function, and give a basic explanation of how the user can utilise the program, and selecting exit will exit the program. Next, the user is shown a triangle which is represented by a basic triangle which I have ‘drawn’ onto the console via std::cout. This triangle displays the sides and angles, which are represented by letters, and some information is displayed to the user about what they can do next. The user can then either work out the angles or sides of the triangle. They are then asked as to what angle or side they would like to work out, and the relevant information they already know about their chosen angle or side. Depending on the information they know, and the option they select, a function will be loaded, where the user can input two pieces of information to work out the size of the angle or side. For example, say I wanted to work out Angle C, and I knew the opposite and hypotenuse (Sides a and b). In the main menu, I would select the option to ‘Work out Angles and Sides’. After the triangle has been displayed, I would then select the option “Angles”, which would then load up the next function. In this function, I am reminded that Angle B will always be 90, and I would select “C”, which will then load up another function which asks me what information I already know. I have four choices, but select the option “Opposite and hypotenuse”, as this is the information I know. This will load up the last function to work out the size of the angle. I then can input the sizes of the hypotenuse and opposite, and will be told the size of Angle C, before the program returns me to the main menu.
When I was making the calculator, the main problem I had was implementing the maths itself, as I had little experience of doing it previous to this assignment. I knew the code, and I knew the maths, I was just having a problem implementing it. However, after some research, I discovered how I can do it, and it turned out to be rather simple. My main error was that I was using ‘sin’, ‘cos’, and ‘tan’, when I should have been using ‘asin’, ‘acos’ and ‘atan’. After reworking the three functions which worked out the angles using these, I managed to get them functioning properly. Once they seemed to be functioning properly, I used a couple of Trigonometry Calculator websites to confirm that the results I was getting from my functions were correct, and they were. After proving my angle calculations were correct, I then moved on to test the functions that calculated the size of the sides, and I found that these were correct too. After the completion of the base program, I added a couple of extra features. This included the “Help” feature, and a few minor tweaks including the addition of the Sleep command after certain conditions such as when there was an invalid input, and when the user would exit the program.




