Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The ability to write functions is one of the more powerful capabilities in C. Fu

ID: 3652042 • 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. 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);

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 );

Explanation / Answer

/////////////////////////////////
//MyFunctions.h
/////////////////////////////////
#ifndef MyFunctions_H
#define MyFunctions_H

double maximum (double, double);
double absolute( double );
double power ( double, int );

#endif
/////////////////////////////////
//MyFunctions.c
/////////////////////////////////
#include"MyFunctions.h"

double maximum (double a, double b){
if (a>b)
return a;
else
return b;
}

double absolute( double a){
if(a<0){
return -a;
}
else
return a;
}

double power ( double X, int Y){
double Z=X;
int i;
for(i=1;i<Y;i++){
Z*=X;
}
return Z;
}

/////////////////////////////////
// testFunction.c
/////////////////////////////////
#include<stdio.h>
#include"MyFunctions.h"

int main(){
double num1,num2;
int num3;
printf("Enter two numbers of type double: ");
scanf("%lf",&num1);
scanf("%lf",&num2);
printf("Enter an integer: ");
scanf("%d",&num3);
printf(" The max number of the two is %1.3lf",maximum(num1,num2));
printf(" The absolute number of the two are %1.3lf and %1.3lf",absolute(num1),absolute(num2));
printf(" %1.4lf to the power of %d is %1.3lf ",num1,num3, power ( num1, num3 ));
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote