(Latest Revision: Wed Apr 29, 2015 )

SIXTH CS 1500 SOLO PROGRAM: Median Calculation Program


OBJECTIVE: The purpose of this programming assignment is to get practice using files, arrays, and loops.


ASSIGNMENT SYNOPSIS:

Write a program that reads a sorted set of numbers from an input file into an array, finds the median value in the array, and writes a report to both the screen and an output file.

The median is the item M that has this property: M is greater-than-or-equal to half the items in the list, and also M is less-than-or-equal to half the items in the list. (In other words, M is the middle value of the list.)


DETAILS:

To get a clear idea of what the program is supposed to do, have a look at the sample runs.

Notice that in the sample runs, when the program outputs the elements of the list, each is printed in a five-character-wide field, right justified. If you utilize output statements like this
      cout.width(5) ;
      cout << numberList[j] ;
you will be able to achieve the same kind of formatting with your program's output. The width function utilized above is discussed on page 328 of your text. Make sure to familiarize yourself with that material.


INPUT:

You must write the program with certain facts, assumptions, and preconditions in mind:
THE DESIGN OF THE PROGRAM:

The program must have at least two functions (in addition to the main() function).

At least two of the additional functions must have one or more parameters.

You are not allowed to use any global variables.

I expect you to employ good principles of top-down design when you develop the program.

I want you to have the experience of writing a program that reads from a file, writes to a file, and uses arrays appropriately. Therefore You should use this kind of declaration in your program:

char someFileName[256] ;

to give your program a variable needed for accepting a filename from the user. Obviously, you are not to use a declaration exactly like the one above, because you must think about what the actual names for such variables ought to be, and you must choose good mnemonic names.

The array of characters discussed above is nice and long - 256 slots - so it has more than enough capacity for most filenames. 256 slots is enough for 255 characters in a string, plus the null character ('\0') that is used to mark the end of the string. (As you know from class discussions, the extraction operator [ >> ] will automatically load a string into such an array for you, including the null character at the end.)

You can use a command like
ifstream fin(filename) ;
OR these commands
ifstream fin ;
fin.open(fileName);
to declare an ifstream named fin, and attach it to the file whose name is stored in the fileName string variable (array of char).

You can declare an ofstream variable and attach it to a file in a similar manner.

Note: Come to class to get more discussion of how to design the code.


FORM AND FORMATTING REQUIREMENTS:

At the beginning of your program file put a header comment like this:

  /* PROGRAM: Median Calculation */

  /*

  Name:          Gordon Goodguy
  User Name:     goodge
  Course:        CS 1500, Computer Programming I
  Instructor:    John Sarraille
  Date:          January 01, 1970

  */
Of course, in place of "Gordon Goodguy," you must put your own full name. In place of "goodge" put your user (login) name. In place of the Unix epoch, "January 01, 1970," put the date that you finished the program. Note that the comment delimiters /* and */ are important. They need to be placed correctly or you will get compiler errors.


TESTING:

When you make your test script, include the two tests that are in the sample runs. Be sure to perform the tests the same way as in the sample runs.

This is what you do for each individual test: first, cat the input file, then run the program, then cat the output file.

Also perform a test where the input file does not exist. (Of course, in the case of that test you do not cat the input or the output file as part of the test.) When the input file does not exist, the result of the test should be that the program writes a message saying there was a failure to open the file, and then the program stops immediately.

To make it easier for me to check the work in your script, order your tests so that When you do your testing, verify that all the output of the program is correct.


WHAT TO TURN IN:

You will be sending me two e-mail messages. Please follow these rules: Here is the list of things you have to turn in: Note that there are no spaces in the subject lines given. It is important that you do not insert any spaces. My e-mail address is:

john@ishi.csustan.edu



WHEN IS THIS ASSIGNMENT DUE?

Look for the due date in the class schedule. (It's at the top level of the class directory.)