Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im looking for a multi-file C program. These are the starter files: 1. array.c /*--------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ #include #include #include #include functions.h int main(void) { int

Im looking for a multi-file C program.

image text in transcribed

image text in transcribed

These are the starter files:

1. array.c

/*--------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ #include #include #include #include "functions.h" int main(void) { int npts = 0, ncount = 0, i = 0; double noise[ MAXIMUM ]; double left = 0, right = 0; npts = read_data(noise); printf(" \tArray Analysis "); printf("\t**************** "); if (npts > 0) { echo_data( noise, npts ); printf(" \tPercent positive: "); /* call function percent_pos and get the percentage of positive values */ printf(" \tNeighbor distances \t================ "); /* loop through the array call get_neighbor_distance for each element of the array once inside the loop and upon returning the values, print out the neighbor information for each element */ } else printf(" \tEmpty file, no statistics computed "); printf(" normal Termination "); return 0; }

2. functions.c

/*--------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ #include #include #include "functions.h" /*--------------------------------------------------- This function returns distance to each of the neighbors of the index. ---------------------------------------------------*/ int get_neighbor_distance( double x[], int n, double * left, double * right, int index) { int count = 0; return count; } /*---------------------------------------------------*/ /* This function returns the percent of positive values */ /* */ /*---------------------------------------------------*/ double percent_pos(double arr[], int max) { double pos = 0; return pos; } /**********************************************************************/ /* Code for echo_data has been written for you, don't modify anything */ void echo_data( double data[ ],int n ) { int i; printf( " \tInput data: %d data points ", n ); printf( "\t-------------------------- " ); for( i = 0; i  0) printf(" \tWARNING: There were %d extra input data items - these will not be used in the program ", m); return n; } 

3. functions.h

#define MAXIMUM 25 /*--------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ int read_data(double arr[]); double percent_pos(double arr[], int max); int get_neighbor_distance( double [], int , double *, double*, int ); void echo_data( double [ ],int );

If an input file contained these values: 1.5, 5.2, -2, 6.1, 2.0, 8.0, the output should look something like this

image text in transcribed

Problem The purpose of this assignment is to give your more practice with using arays, functions, functions with output arguuments and nmultiple file programs. The goal is to read data into an aray and print out some information on the aray, in particular. The percentage of positive values in the aray Given an aray index find the distance to the neighboring values . From this lab onwards you will be splitting up your program into different files. You have two source files: typically your main function is in one source file, all the functions that you write will be in a second source file. You also have a "header" file that contains any constants and proto-type declarations for functions that you will include in both your source files. Download, compile and run the starter files for this lab from the public folder. array.c, functions.c, To compile you need to specify all c files together: gcc array.c functions.c or gcc c will compile all the C files in your folder. DO NOT incude the header file for compiling, if you do you are likely to get several unexpected errors. Carefially study the structure of this program with the main function in one file, all other fiunctions in another and the forward declarations (proto-type declarations) in the third file. Test the program with the test files (inl, in2, etc). The fiunctions read data0 for reading the aray and echo_data0 for printing the aray are already written for you! But you will need to write code for the two functions percent pos0 and get _neighbor distance0 for which I have provided stubs that you can use to complete the code. Make sure you work on one function at a time and test it fully before you move on. Make sure that the program you submit compiles! A program that will not run or crashes will receive a zero even if pat of the program is correct. Solving it step by step 1. Complete the function double percent pos double xl, nt n) You should count the mumber of positive values (0) and calculate and retun the percent of the values in the aray that are positive. Test your function by writing code in your main) function to call percent_pos0 with the correct arguments and a variable to hold the result. 2. Complete the function int get _neighbor distance(double x, int n, double *left, double ight, int index) This function has two output arguments. The mut to this function is an array "x", the size of the aray "n" and an ray index "index. The function analyzes the element in the anay with the given index and returns the following values: The mumber of neighboring elements (this will be two unless the element is the first or the last element) The distance to each of the two neighbors, where the distances are the absolute values of the differences (for example ndex-x[index-11 and mdex_x[index-11) . . Problem The purpose of this assignment is to give your more practice with using arays, functions, functions with output arguuments and nmultiple file programs. The goal is to read data into an aray and print out some information on the aray, in particular. The percentage of positive values in the aray Given an aray index find the distance to the neighboring values . From this lab onwards you will be splitting up your program into different files. You have two source files: typically your main function is in one source file, all the functions that you write will be in a second source file. You also have a "header" file that contains any constants and proto-type declarations for functions that you will include in both your source files. Download, compile and run the starter files for this lab from the public folder. array.c, functions.c, To compile you need to specify all c files together: gcc array.c functions.c or gcc c will compile all the C files in your folder. DO NOT incude the header file for compiling, if you do you are likely to get several unexpected errors. Carefially study the structure of this program with the main function in one file, all other fiunctions in another and the forward declarations (proto-type declarations) in the third file. Test the program with the test files (inl, in2, etc). The fiunctions read data0 for reading the aray and echo_data0 for printing the aray are already written for you! But you will need to write code for the two functions percent pos0 and get _neighbor distance0 for which I have provided stubs that you can use to complete the code. Make sure you work on one function at a time and test it fully before you move on. Make sure that the program you submit compiles! A program that will not run or crashes will receive a zero even if pat of the program is correct. Solving it step by step 1. Complete the function double percent pos double xl, nt n) You should count the mumber of positive values (0) and calculate and retun the percent of the values in the aray that are positive. Test your function by writing code in your main) function to call percent_pos0 with the correct arguments and a variable to hold the result. 2. Complete the function int get _neighbor distance(double x, int n, double *left, double ight, int index) This function has two output arguments. The mut to this function is an array "x", the size of the aray "n" and an ray index "index. The function analyzes the element in the anay with the given index and returns the following values: The mumber of neighboring elements (this will be two unless the element is the first or the last element) The distance to each of the two neighbors, where the distances are the absolute values of the differences (for example ndex-x[index-11 and mdex_x[index-11)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions

Question

Identify the different methods employed in the selection process.

Answered: 1 week ago

Question

Demonstrate the difference between ability and personality tests.

Answered: 1 week ago