File Processing - Integers


This assignment will give you more practice with:

  1. Handling arguments from the command line
  2. Opening and reading a text file
  3. Handling arrays
  4. Sorting an array
  5. Processing an array

Problem Description

Write a program that reads integers from a text file whose name is given as a command-line argument. Each line of the file may contain any number of integers (including none), separated by one or more spaces.

Your program should display (to stdout) the largest number in the file, the smallest number in the file, and the median. (Remember that the median is the number closest to the middle of a series of numbers. When there is an even number of numbers in the series, then the average of the two numbers in the middle is used. For this exercise, round down, if necessary.)

Assume that the file contains no more than 10,000 integers. As the book suggests, this would be a good use of an array of integers that is sorted. You can use insertion sort or any other sorting algorithm or function except for bubble sort.

If your program encounters


This assignment will be worth up to 12 points. If you use a bubble sort, you will automatically lose 5 points from your score.


This project comes from the King textbook, Chapter 22, Programming Project #18