$25
• This assignment is about simple file read/write and array usage. You can use pointers and functions. You cannot use dynamical memory allocation. You cannot use recursion. You can use global variables.
This is a C Programming assignment. You will write a C program according to the following description.
• The program reads real numbers from a file. Determines the chunks according to a criteria. For each chunk, the average of the numbers is calculated and printed.
• Input file contains a sequence of real numbers which are separated by whitespace. The whole sequence consists of chunks which are going to be separated by the following criteria:
– n is the number to be added and a is the average of the chunk. If n is added to the current chunk the average becomes b.
– n is going to be added to the chunk if the following condition is satisfied:
– !(b > a*(1+p1) || b < a*(1-p1) || a > n*p2 || a < n/p2)
– Beware, there is a ! at the beginning of the condition.
– Here, p1 and p2 are pre-defined variables. Declare them as constants in your program.
• Each line of the output file lists the numbers in chunks.
• Code it so that it reads a text file named input.txt and writes to a text file named output.txt. (If you don’t follow this convention your grade will be 0.0).
Example
• Contents of the input file:
12.432 23.5 344.6 11.85 2.5 8.2313 19.27 70.001 23.64 13.62
• Given p1 = 0.5 and p2 = 20, there are 4 chunks:
• Find averages of numbers in each chunk. Create a text file with chunks as follows:
12.4320 23.5000 average: 17.9660
344.6000 average: 344.6000
11.8500 2.5000 8.2313 19.2700 average: 10.4628
70.0010 23.6400 13.6200 average: 35.7537
• Each line is a chunk. Be careful with the output format. There is single space between each token.
Remarks
• You cannot use variable length arrays and/or dynamic memory allocation.
• There is no limit on the length of the input sequence. Test your program with very large input sequences.(i.e. millions of numbers)
• Minimum length of a chunk is 1.
• The first number in the sequence belongs to the first chunk.
• There is at least one chunk in the sequence.
• Sequence starts with a chunk.
• You don’t have to do error checking on the input file. You can safely assume that you will be given a proper input file which doesn’t violate the described format.