Collaboration on this lab exercise is strongly ENCOURAGED. The exercise is intended for practice, not assessment -- most people who try should get all participation points. Feel free to ask for help from, and provide help to, others. You shouldn't blindly copy solutions from one another (or from anywhere else) nor simply write code for someone else (even if you explain it as you write), but you can certainly help each other debug, give plenty of suggestions and hints, **explain** why things work or don't work, etc. If you get done early, feel free to walk around and help others.
Write a program that takes input from a file of numbers of type double and outputs the average of those numbers to the screen. You may use the file avg.dat to test your program. The output to the screen when using this file should be:
Average = 15.2325
You may assume the file will always have exactly 12 values in it.
Don't forget to close your file before your program finishes. You use the member function close() to close the file. So if your input-file stream object is called fin you would close the file like this:
fin.close();
Write a program that takes 5 positive double values as input from the user and outputs all the values to an output file called out.dat followed by the average of those values. Each value should be on a separate line in the output file. Your output should look something like:
5.5 4.8 3.45 20.1 5.8 AVG = 7.93
Modify your program from Part 2 so that it allows the user to type as many positive values as they want. You can have the user type a negative number to let the program know they are done entering values.
You should have all the values print to the output file as before. For this part however, you should print the average to both the output file AND to the screen.
Write a program that reads in 2 numbers from an input file named in.txt and outputs the numbers in ascending order to an output file named out.txt. Use a function that passes the values in and returns the values in ascending order. You will create the file in.txt for this exercise. You can create this using Notepad in Windows or with Emacs in Linux. So, if the file in.txt looks like this:
10 9
after the program runs the file out.txt should look like this:
9 10
Write a program that takes 20 numbers from the user. The user may enter both positive and negative numbers. Your program should output all the positive numbers to an output file called positive.dat and all the negative numbers to an output file called negative.dat.
Please feel free to help your fellow labmates reach this point!!
The following exercises are for your own benefit. You are not required to do these. In fact, they may contain material not covered in class or lab yet. As such, the TAs will give priority to helping students on the previous sections.
Challenge 1: