Question: Write a C code that meets the following requirements: Below is the outline code from excerise A: /*------------------------------------------------------------------ File: analyseBinFile.c Author: Description: Reads the contents

Write a C code that meets the following requirements: Write a C code that meets the following requirements: Below is the Below is the outline code from excerise A:

/*------------------------------------------------------------------ File: analyseBinFile.c Author: Description: Reads the contents of a bin file and analyses the data. ---------------------------------------------------------------------*/ #include // Symbolic constants #define BIN_FILE "data.bin" #define NUM_VALUES 100 // number of values to read from binary file // For computed values #define NUM 3 // number of computed values // The following are indexes into the array // containing computed values #define MINIX 0 #define MAXIX 1 #define AVGIX 2 // function prototypes void analyseBinFile(FILE *, double *); /*--------------------------------------------------------------------- Function: main Description: Opens a binary file and calls analyzeFileBin to determine the minimum, the maximum and the average values of the contents of the file. ------------------------------------------------------------------------*/ void main(void) { // Variable declarations FILE *fp; // File pointer for binary file double outputVals[NUM]; // Open the file fp = fopen(BIN_FILE, "rb"); if(fp == NULL) printf("Cannot open binary file %s ", BIN_FILE); else { analyseBinFile(fp, outputVals); // Display the results printf("Analysis of file data gives: "); printf(" Minimum: %.3f ", outputVals[MINIX]); printf(" Maximum: %.3f ", outputVals[MAXIX]); printf(" Average: %.3f ", outputVals[AVGIX]); fclose(fp); } } /*----------------------------------------------------------------------- Function: analyseBinFile Parameters: fp - file pointer for input binary file outPt - pointer to array for storing compute values. Description: Reads all data values into an array and scans the data within the array to compute three output values: the minimum value, the maximum value and the average value of the data ------------------------------------------------------------------------*/ void analyseBinFile(FILE *fp, double *outPt) {

}

And below is the exact output required: outline code from excerise A: /*------------------------------------------------------------------ File: analyseBinFile.c Author: Description: Reads the and below is the data: contents of a bin file and analyses the data. ---------------------------------------------------------------------*/ #include //

B. Exercise: Reading data from a Binary File (20 marks) The project available in the zip file analyseBinFile.zip is practically a duplicate of the program in Exercise A. In this case the data is read from a binary file. Your task in this exercise is to complete the function analyseBinFile so that program produces the same output as in Exercise A, but in reading from the binary file. There are two approaches that can be taken to read the contents of the binary file It is possible to read each value one at a time as in Exercise A. The code from Exercise A can easily be modified it so that the program runs and produces the expected result. Only how values are read from the file (see the course notes on reading from binary files) need be changed. Complete this exercise at home. .The other approach is to read in all values at once into an array (examine the function saveInBinFile from Exercise A to see how a complete array was written into the file). This is thoe version you must produce. Thus modify your code to read in the complete contents of the file (you may use NUM_VALUES as the number of values to be read). This approach illustrates how large amounts of data can be written to and read from binary files without any translations. This is quite practical when storing a large array or a large structure variable, even an array of structure variables. Show and explain to your TA your code and running program to get your marks B. Exercise: Reading data from a Binary File (20 marks) The project available in the zip file analyseBinFile.zip is practically a duplicate of the program in Exercise A. In this case the data is read from a binary file. Your task in this exercise is to complete the function analyseBinFile so that program produces the same output as in Exercise A, but in reading from the binary file. There are two approaches that can be taken to read the contents of the binary file It is possible to read each value one at a time as in Exercise A. The code from Exercise A can easily be modified it so that the program runs and produces the expected result. Only how values are read from the file (see the course notes on reading from binary files) need be changed. Complete this exercise at home. .The other approach is to read in all values at once into an array (examine the function saveInBinFile from Exercise A to see how a complete array was written into the file). This is thoe version you must produce. Thus modify your code to read in the complete contents of the file (you may use NUM_VALUES as the number of values to be read). This approach illustrates how large amounts of data can be written to and read from binary files without any translations. This is quite practical when storing a large array or a large structure variable, even an array of structure variables. Show and explain to your TA your code and running program to get your marks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!