The ability to write functions is one of the more powerful capabilities in C. Fu
ID: 3652016 • Letter: T
Question
The ability to write functions is one of the more powerful capabilities in C. Functions allow code to be reused, and provides a mechanism for introducing the concept of modularity to the programming process. In addition to the concept of functions, C allows complex programs to be organized using header files (.h files) that contain the prototypes of functions and implementation files that (.cpp files) that contain the implementation (definition) of the functions.In this programming assignment you will be asked to implement a number of useful functions using a header file and an implementation file. You will place the prototypes for your function in a .h file, and implement these functions in a .c file. You will need to write a driver (a program designed to test programs) to test your functions before you upload them.
Stay away from libraries such as conio.h and string.h. Try to complete using no more than stdio.h and/or math.h.
Deliverables:
MyFunctions.h
MyFunctions.c
Driver.c
Functions:
MAXIMUM
Precondition
-two double values exist
Postcondition
-The value of the larger double is returned.
-The original doubles are unchanged
-If the doubles have the same value then the value of either double is returned.
Return
-double
Description
-Function returns the value of the larger of two doubles.
Prototype: double maximum (double, double);
MINIMUM
Precondition
-two double values exist
Postcondition
-The value of the smaller double is returned.
-The original doubles are unchanged
-If the doubles have the same value then the value of either double is returned.
Return
-double
Description
-Function returns the value of the smaller of two doubles.
Prototype: double minimum (double, double);
ABSOLUTE
Precondition
-Some double value exists
Postcondition
-Double value is unchanged
Return
-Double
Description
-This function returns the absolute value of a double
Prototype: double absolute( double );
POWER
Precondition
-Double value X and integer value Y exist
Postcondition
-The value of X and Y are unchanged
Return
-The double X raised to the power of Y
Description
-This function will calculate XY
Prototype: double power ( double, int );
SQUAREROOT
Precondition
-Some integer radicand X exists
Postcondition
-The value of the radicand X is unchanged
Return
-The square root of X
-0 if an error is encountered
Description
-The function calculates the square root of a number using Newton
Explanation / Answer
The ability to write functions is one of the more powerful capabilities in C. Functions allow code to be reused, and provides a mechanism for introducing the concept of modularity to the programming process. In addition to the concept of functions, C allows complex programs to be organized using header files (.h files) that contain the prototypes of functions and implementation files that (.cpp files) that contain the implementation (definition) of the functions. In this programming assignment you will be asked to implement a number of useful functions using a header file and an implementation file. You will place the prototypes for your function in a .h file, and implement these functions in a .c file. You will need to write a driver (a program designed to test programs) to test your functions before you upload them. Stay away from libraries such as conio.h and string.h. Try to complete using no more than stdio.h and/or math.h. Deliverables: MyFunctions.h MyFunctions.c Driver.c Functions: MAXIMUM Precondition -two double values exist Postcondition -The value of the larger double is returned. -The original doubles are unchanged -If the doubles have the same value then the value of either double is returned. Return -double Description -Function returns the value of the larger of two doubles. Prototype: double maximum (double, double); MINIMUM Precondition -two double values exist Postcondition -The value of the smaller double is returned. -The original doubles are unchanged -If the doubles have the same value then the value of either double is returned. Return -double Description -Function returns the value of the smaller of two doubles. Prototype: double minimum (double, double); ABSOLUTE Precondition -Some double value exists Postcondition -Double value is unchanged Return -Double Description -This function returns the absolute value of a double Prototype: double absolute( double ); POWER Precondition -Double value X and integer value Y exist Postcondition -The value of X and Y are unchanged Return -The double X raised to the power of Y Description -This function will calculate XY Prototype: double power ( double, int ); SQUAREROOT Precondition -Some integer radicand X exists Postcondition -The value of the radicand X is unchanged Return -The square root of X -0 if an error is encountered Description -The function calculates the square root of a number using Newton’s method with 25 iterations. Prototype: double squareRoot( double ); FACTORIAL Precondition -Some integer value N exists. Postcondition -The value of the N unchanged Return -The number representing the factorial of N. Description -The function calculates factorial. Prototype: double factorial ( int ); HINT FOR SQUAREROOT FUNCTION: Newton's method for calculating the square root of N starts by making a (positive number) guess at the square root. It then uses the original guess to calculate a new guess, according to the following formula: guess = (( N / guess) + guess) / 2 ; No matter how wild the original guess is, if we repeat this calculation the algorithm will eventually find the square root of N.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.