Reference no: EM132586174
Program Assignment -
Part A - Write a program that asks the user for an input file name, reads from the file (it will contain an unknown number of floating-point numbers), and outputs:
1. the sum of all the numbers greater than or equal to zero,
2. the sum of all the numbers less than zero,
3. the sum of all the numbers, whether positive, negative or zero.
Use dynamic array.
Part B - Modify your program from project A so that it outputs:
1. the sum and average of all the numbers greater than or equal to zero,
2. the sum and average of all the numbers less than zero,
3. the sum and average of all the numbers, whether positive, negative or zero.
Bonus for using functions that involve a dynamic array parameter.
Requirements -
1. The program will loop again to ask if the user wants to process another file.
2. Use dynamic array to hold just the right number of floating-point numbers read from file.
3. Remember to comment well in your program and any functions you use.
Testing -
The program should be tested extensively to make sure it works as expected before you hand it in.
The program should accept a file like the followings:
-33.34 0 22.63 12.23 100.4 111 45.45
And outputs something like the following:
291.71 and 48.62 (setprecision to 2) are the sum and average of all the numbers greater than or equal to zero,
-33.34 and -33.34 are the sum and average of all the numbers less than zero,
258.37 and 36.91 are the sum and average of all the numbers, whether positive, negative or zero.
Please come up with more test cases.
Hints/Questions to Think Ahead - How to figure out how big of an array to allocate memory for?