Design Document

advertisement
Design Document
The purpose of this program is to perform basic mathematical and some advanced
mathematical math functions. When the program is first run a menu pops up allowing the
user to choose from a list of different mathematical functions he can perform. The menu
is divided into four different types of mathematical functions. The four subgroups are
basic math, trigonometric math, exponential math, and other section. The ‘other’ section
is provided since it allows the user to perform certain tasks that don’t fall in any of the
other three subgroups. This main menu and all the submenus in this program are done by
using a switch statement. One unique submenu is the basic mathematical function. This
submenu is done by using enum.
If the user decides that he wants to use the basic mathematical function subgroup,
another submenu pops up. This submenu allows the user to choose which basic
mathematical functions he wishes to use. The four different choices he has are to add,
subtract, divide, or to multiply. After he picks his choice, the program then asks for two
numbers and performs the operation specified by the user on the two numbers. This
section of the program was included since a calculator must always have the essentials.
If the user decides to pick the second subgroup, trigonometric math functions, he
is brought, once again, to another sub menu. The three choices that the user has in this
sub menu are to calculate the sine, cosine, or tangent of an angle specified by the user.
All the functions in this submenu are done by implementing the math functions in the
math.h standard library. Each choice that the user decides to use is done by using a
switch statement.
The next choice that the user can pick is to perform the exponential math
functions. Again a submenu appears that allows the user to choose which mathematical
function he wishes to perform. He has a choice of calculating ex, ln|x|, log10x, xy, square
a number, or the square root of x. For each one of these functions the program simply
asks for a number and the program will then plug the number into the function and return
the result. However, ln|x| is an exception. The absolute value function was performed on
x since natural log of a negative number cannot be taken. Calculating xy and squaring the
number is also a little different. A function is made containing the pow function and by
default, the power is set to two. If the square option is selected, the user is not asked to
enter a power and the default value 2 is assigned.
The last choice that the user can decide to use is the ‘Other’ function menu. This
menu composes of a subroutine that allows the user to find the greatest common
denominator between two numbers, round numbers up and down, or to calculate a
floating point remainder of two numbers. Each one of these functions uses the math
functions in the header file math.h. However, the function that calculates the greatest
common denominator is done by using a recursive function which finds the remainder of
the two numbers continuously until one reaches zero.
Download