Homework 5 - File I/O and Arrays

Due: Wednesday, October 31, Friday November 2, 2012 at midnight

Name your files hw5_<problem>.cpp, such as hw5_1.cpp. Email all the cpp files to my account.

  1. (10 points) Write a program that reads a text file using character-by-character I/O and performs the following normalization tasks: You will have two file streams: an input file stream for the file to be normalized and an output file stream that contains the normalized file. You should issue an error message and exit the program if either file cannot be opened.

    Your program should prompt the user for the filename for the file to be normalized (the input file). The output filename should be the input filename with ".norm" added to it. For example, if the input file is "data.txt", the output file name will be "data.txt.norm".

    Sample input file: hw5_input1
    You MUST download this file with wget, copy and paste will not correctly copy over the tab characters.

    Hint: Do the normalization replacements by immediately sending the replacement string out to the output file when the desired character is found in the input file. If the input file character doesn't need to be replaced, just immediately send it to the output file.

    Your code must work correctly on the provided sample input file. You may also generate additional files with which to test your code, but it will only be graded against hw5_input1.

  2. (10 points) Write a menu program using do-while and switch statements to implement the following menu:
             Welcome to the CS221 Homework 5 Menu
      ======================================================
      1.  Read a list of integers from a file into an array.
      2.  Multiply all integers in the array.
      3.  Calculate the average and standard deviation for 
          all the integers in the array.
    
      0.  Exit
      ======================================================
      Enter selection:
    
    Options 2 and 3 cannot work if Option 1 has not been selected. Make sure to initialize your array variables to an "empty" condition and check this empty condition in the case statements for Options 2 and 3. If the array is empty when the user selects Option 2 or Option 3, print out an error message telling them to select Option 1 and continue to the next iteration of the menu loop.

    Required elements of your program (points will be deducted if these are not followed):

    Use the following files as input to Option 1: hw5_input2 hw5_input3