For example, suppose innums.txt consists of the following lines:
4.0 5.0 -2.0 -3.0The program should compute and print the value 50, because the average of the four numbers in the file is 1.0, and (4.0 - 1.0)2 + (5.0 - 1.0)2 + (-2.0 - 1.0)2 + (-3.0 - 1.0)2 equals 50.
Your program should make no assumptions about how many numbers there are. (For those of you reading ahead, this means that the program cannot use an array to store the numbers.)
If input file innums.txt does not exist, the program should print a user-oriented error message saying so, rather than crashing or printing a semi-cryptic message about a failed assertion. See the temperature_records sample program for an example of checking that a file has been opened successfully and printing an error message if not.
Hint: Since the numbers are stored in a file (rather than being read in from standard input), your program can read through them more than once. To read the contents of a file a second time, close the file and open it again.
Now is the time for all good persons to come to the aid of their country. Testing, Testing, 1 2 3 4. Over and out!Then after executing the program, file lowercase.txt should consist of the following lines:
now is the time for all good persons to come to the aid of their country. testing, testing, 1 2 3 4. over and out!and file uppercase.txt should consist of the following lines:
NOW IS THE TIME FOR ALL GOOD PERSONS TO COME TO THE AID OF THEIR COUNTRY. TESTING, TESTING, 1 2 3 4. OVER AND OUT!
If input file intext.txt does not exist, the program should print a user-oriented error message saying so, rather than crashing or printing a semi-cryptic message about a failed assertion. See the temperature_records sample program for an example of checking that a file has been opened successfully and printing an error message if not.
Hint: You may find library functions tolower and toupper, described in Chapter 8, useful. Be advised, however, that these functions actually return ints, so the following lines of code produce a result that may surprise you (try them!):
cout << tolower('A') << endl; cout << toupper('a') << endl;To produce the expected result, you must convert the values returned by these functions to chars, as in the following:
cout << char(tolower('A')) << endl; cout << char(toupper('a')) << endl;