CSCI-1320 Homework 16: File Reading and Writing II

Instructor: Todd Dole

Purpose Statement

This assignment gives practice reading and writing files.

Instructions

In this assignment, you will read the contents of a text file containing numbers, sort the numbers, and write the sorted numbers to a new text file.

Begin by prompting the user for the name of an input file and an output file.

For this assignment, you may assume that the user gives the name of a file that is filled with double values, one number per line.

Open the input file and read the contents into an array of doubles. (You can read it twice, once to discover how big you should make your array and then a second time to fill the array.)

Perform a sort algorithm on the array.

Then, open the output file for writing, and write the sorted array to the output file, one number per line.

Be sure to include basic error handling using try/catch.

Example input:

                Please enter the input file: numbers.txt
                Please enter the output file: sorted-numbers.txt

                sorted-numbers.txt created successfully!

            
This example would create a file called sorted-numbers.txt