Question
8.20 LAB**: Program: User-Defined Functions In this programming assignment, you will write a C program that uses input, output, function calls, and preprocessor directives for
8.20 LAB**: Program: User-Defined Functions
In this programming assignment, you will write a C program that uses input, output, function calls, and preprocessor directives for doing some basic mathematical computations. You will also organize your program into separate source and header files.
Create a header file named functions.h. In this file, you will do the following:
Include the header guards
Write a preprocessor directive to represent a constant value for an array size. Name it LENGTH and give the replacement value 5.
You will write two functions (see below functions.c). Declare their prototypes. Function names should be exactly as shown below.
Create a source file named functions.c. In this file, you will do the following:
Write a function named average() that takes in an array of integers. It returns the average of the array as a double value. Use "pass by value".
Write a function named quadraticFormula() that solves for the two x values. It takes in five parameters: the arguments for the equation a, b, and c plus two parameters "passed by pointer/reference" so that the both x values (x1 and x2) can be sent back to the caller. Assume all parameters are of type double. The function returns nothing. Here is the mathematical formula below (source: Wikipedia)
Assume that a > 0 and the value under the root is always greater than 0 i.e. b^2 > 4ac.
The first result x1 is when you add the square root expression and the second result x2 is when you subtract the square root expression.
No printf() statements can exist in these functions in this file. All printing will happen in main.
Write the main() that will do the following:
Declare an array with 5 integer values - use the LENGTH.
Using a for loop, ask the user to input a value for each of the array elements. Assume the user will always enter a valid value as input.
Next, ask the user for three values - a, b, and c arguments that will be passed to the quadraticFormula() function. It will pass two additional variables by pointer.
Call the average() function with the array as the argument.
Call the quadraticFormula() with the arguments - a, b, c and the result variables x1 and x2 passed by reference.
Print the results. First line should print the average of the array. Next, print the updated result values for x1 and x2, each in a separate line.
The output must look exactly like below in terms of formatting. There is only one space between the colon and the result. Results are shown with exactly two decimal places. The example shows the solutions for when the array contains [10, 20, 30, 40, 50] and when a = 2, b = 5, and c = -3.
8.20 LAB**: Program: User-Defined Functions In this programming assignment, you will write a C program that uses input, output, function calls, and preprocessor directives for doing some basic mathematical computations. You will also organize your program into separate source and header files. - Create a header file named functions.h. In this file, you will do the following: - Include the header guards - Write a preprocessor directive to represent a constant value for an array size. Name it LENGTH and give the replacement value 5 . - You will write two functions (see below functions.c). Declare their prototypes. Function names should be exactly as shown below. - Create a source file named functions. c. In this file, you will do the following: - Write a function named average ( ) that takes in an array of integers. It returns the average of the array as a double value. Use "pass by value". - Write a function named quadraticFormula ( ) that solves for the two x values. It takes in five parameters: the arguments for the equation a, b, and c plus two parameters "passed by pointer/reference" so that the both x values ( x1 and x2 ) can be sent back to the caller. Assume all parameters are of type double. The function returns nothing. Here is the mathematical formula below (source: Wikipedia) x=2abb24ac - Assume that a>0 and the value under the root is always greater than 0 i.e. b2 >4ac. - The first result x1 is when you add the square root expression and the second result x2 is when you subtract the square root expression. - No printf ( ) statements can exist in these functions in this file. All printing will happen in main. - Write the main ( ) that will do the following: - Declare an array with 5 integer values - use the LENGTH. - Using a for loop, ask the user to input a value for each of the array elements. Assume the user will always enter a valid value as input. - Next, ask the user for three values - a,b, and c arguments that will be passed to the quadraticformula ( ) function. It will pass two additional variables by pointer. - Call the average ( ) function with the array as the argument. - Call the quadraticformula ( ) with the arguments - a, b, c and the result variables x1 and x2 passed by reference. - Print the results. First line should print the average of the array. Next, print the updated result values for x1 and x2, each in a separate line. - The output must look exactly like below in terms of formatting. There is only one space between the colon and the result. Results are shown with exactly two decimal places. The example shows the solutions for when the array contains [10,20,30,40,50] and when a=2,b=5, and c=3. average:30.00x1:0.50x2:3.00 Save your files as main.c, functions.c, and functions.h and upload them below for grading. \begin{tabular}{l|l} LAB \\ ACTIVITY & 8.20.1: LAB \end{tabular} 0/20 Submission Instructions Compile command gcc main.c functions. c -Wall -o a.out - 1m We will use this command to compile your code Upload your files below by dragging and dropping into the area or choosing a file on your hard driveStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started