Homework 4 - File I/O and Arrays

Due: Wednesday October 20, 2010 at 5:00pm

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

  1. (10 points) Write a program that reads a text file in character-by-character 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: hw4_input1

    Hint: Do the above 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 hw4_input1.

  2. (10 points) Write a program that reads integers in from the keyboard and stores them into an array. The program will prompt the user for the number of integers they wish to enter. It will use a validation loop to verifty that the user has given a number greater than 1 and less than or equal to the maximum capacity of the array. Once the desired number of integers has been validated, it will use a for() loop to read that many integers into the array. Once the integers have been obtained, it will use additional for() loops to compute the average and standard deviation and print those to the screen. If you do not recall how to compute the standard deviation, refer to Lab 4.