Programming Exercises

1. Write a C++ program that counts the numbers of newline characters, digits and letters in the input file ``in.txt''. The output should clearly show the number of occurrences of each type of character in the file. A sample output is:

linux2:~/PDS/C++$ ./ex2_1
You have 20 lines in your file
You have 26 digits in your file
You have 19 letters in your file
linux2:~/PDS/C++$
2. Write a function of prototype bool f(double x) to check if $x\in (-10,10)$ or not. Use this function to sort a list of real numbers in an input file to those in the interval $(-10,10)$ and those outside this interval. You can write output to console or to text files. The output of the program is something like this:

linux2:~/PDS/C++$ ./ex2_2
Enter input filename
myfile.txt
 Numbers in the interval (-10,10)
 --------------------------------
9.3
4
8.2
5
5
 Numbers outside this interval
 --------------------------------
12
23
11
34.7
32
18.1
19
29
26
20
22